 <?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.algo.informatik.tu-darmstadt.de/index.php?action=history&amp;feed=atom&amp;title=Heap_as_array%3A_insert</id>
	<title>Heap as array: insert - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.algo.informatik.tu-darmstadt.de/index.php?action=history&amp;feed=atom&amp;title=Heap_as_array%3A_insert"/>
	<link rel="alternate" type="text/html" href="https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Heap_as_array:_insert&amp;action=history"/>
	<updated>2026-05-12T17:04:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.4</generator>
	<entry>
		<id>https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Heap_as_array:_insert&amp;diff=3374&amp;oldid=prev</id>
		<title>Luedecke at 23:13, 19 June 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Heap_as_array:_insert&amp;diff=3374&amp;oldid=prev"/>
		<updated>2015-06-19T23:13:33Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 23:13, 19 June 2015&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;__NOTOC__&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Videos]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{#ev:youtube|https://www.youtube.com/watch?v=j-r4YOPFp7E|500|right||frame}}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Checkup]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Checkup]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Algorithm]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Algorithm]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Luedecke</name></author>
	</entry>
	<entry>
		<id>https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Heap_as_array:_insert&amp;diff=509&amp;oldid=prev</id>
		<title>Cuozzo at 09:06, 1 October 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Heap_as_array:_insert&amp;diff=509&amp;oldid=prev"/>
		<updated>2014-10-01T09:06:31Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 09:06, 1 October 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__NOTOC__&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__NOTOC__&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Checkup]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Algorithm]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Algorithm]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category: Method of an implementation of a data structure]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category: Method of an implementation of a data structure]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Cuozzo</name></author>
	</entry>
	<entry>
		<id>https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Heap_as_array:_insert&amp;diff=417&amp;oldid=prev</id>
		<title>Cuozzo: Created page with &quot;__NOTOC__ Category:Algorithm Category: Method of an implementation of a data structure '''Algorithmic problem:''' Bounded priority queue|Bounded priority queue: inse...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.algo.informatik.tu-darmstadt.de/index.php?title=Heap_as_array:_insert&amp;diff=417&amp;oldid=prev"/>
		<updated>2014-09-30T15:35:54Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ &lt;a href=&quot;/index.php?title=Category:Algorithm&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:Algorithm (page does not exist)&quot;&gt;Category:Algorithm&lt;/a&gt; &lt;a href=&quot;/index.php?title=Category:Method_of_an_implementation_of_a_data_structure&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:Method of an implementation of a data structure (page does not exist)&quot;&gt;Category: Method of an implementation of a data structure&lt;/a&gt; &amp;#039;&amp;#039;&amp;#039;Algorithmic problem:&amp;#039;&amp;#039;&amp;#039; Bounded priority queue|Bounded priority queue: inse...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
[[Category:Algorithm]]&lt;br /&gt;
[[Category: Method of an implementation of a data structure]]&lt;br /&gt;
'''Algorithmic problem:''' [[Bounded priority queue|Bounded priority queue: insert]]&lt;br /&gt;
&lt;br /&gt;
'''Prerequisites:'''&lt;br /&gt;
&lt;br /&gt;
'''Type of algorithm:''' loop&lt;br /&gt;
&lt;br /&gt;
'''Auxiliary data:'''&lt;br /&gt;
# A '''current index''' &amp;lt;math&amp;gt;k \in \mathbb{N}&amp;lt;/math&amp;gt;.&lt;br /&gt;
# An auxiliary index &amp;lt;math&amp;gt;k' \in \mathbb{N}&amp;lt;/math&amp;gt;.&lt;br /&gt;
# A number &amp;lt;math&amp;gt;ID&amp;lt;/math&amp;gt; storing the ID to be eventually returned for the new heap element.&lt;br /&gt;
&lt;br /&gt;
==Abstract view==&lt;br /&gt;
'''Invariant:''' Before and after each iteration:&lt;br /&gt;
# The value of &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; is one higher than immediately before the call to this method; one heap item has been inserted, and the key of this heap item is the input key.&lt;br /&gt;
# The heap property is fulfilled for all heap items except for the one at position &amp;lt;math&amp;gt;\lfloor k/2 \rfloor&amp;lt;/math&amp;gt; (for that one, the heap property may or may not be fulfilled).&lt;br /&gt;
&lt;br /&gt;
'''Variant:''' &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; is at least halved.&lt;br /&gt;
&lt;br /&gt;
'''Break condition:''' One of the following two conditions is fulfilled:&lt;br /&gt;
# either it is &amp;lt;math&amp;gt;k = 1&amp;lt;/math&amp;gt;;&lt;br /&gt;
# or, otherwise, the heap property is fulfilled by the heap item at position &amp;lt;math&amp;gt;\lfloor k/2 \rfloor&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Induction basis==&lt;br /&gt;
'''Abstract view:'''&lt;br /&gt;
# Attach the new heap item at position &amp;lt;math&amp;gt;N + 1&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Increase &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; by one.&lt;br /&gt;
# Take a position &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;Unused&amp;lt;/math&amp;gt; and associate &amp;lt;math&amp;gt;Positions[i]&amp;lt;/math&amp;gt; with the new heap item.&lt;br /&gt;
&lt;br /&gt;
'''Implementation:'''&lt;br /&gt;
# Set &amp;lt;math&amp;gt;N:=N+1&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Set &amp;lt;math&amp;gt;TheHeap[N].key:=K&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Extract some &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;Unused&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Set &amp;lt;math&amp;gt;Positions[i]:=N&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Set &amp;lt;math&amp;gt;TheHeap[N].ID:=i&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Set &amp;lt;math&amp;gt;ID:=i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Proof:''' Obvious.&lt;br /&gt;
&lt;br /&gt;
==Induction step==&lt;br /&gt;
'''Abstract view:'''&lt;br /&gt;
# If the current heap item has no parent or the parent fulfills the heap property, terminate the algorithm.&lt;br /&gt;
# Otherwise, exchange the current heap item with its parent. The index &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; follows the heap item.&lt;br /&gt;
&lt;br /&gt;
'''Implementation:'''&lt;br /&gt;
# If &amp;lt;math&amp;gt;k=1&amp;lt;/math&amp;gt;, terminate the algorithm and return &amp;lt;math&amp;gt;ID&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Set &amp;lt;math&amp;gt;k' := \lfloor k/2 \rfloor &amp;lt;/math&amp;gt;.&lt;br /&gt;
# If &amp;lt;math&amp;gt;TheHeap[k'].key \le TheHeap[k].key&amp;lt;/math&amp;gt;, terminate the algorithm and return &amp;lt;math&amp;gt;ID&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Swap &amp;lt;math&amp;gt;Positions[TheHeap[k].ID]&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Positions[TheHeap[k'].ID]&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Swap &amp;lt;math&amp;gt;TheHeap[k].key&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;TheHeap[k'].key&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Swap &amp;lt;math&amp;gt;TheHeap[k].ID&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;TheHeap[k'].ID&amp;lt;/math&amp;gt;.&lt;br /&gt;
# Set &amp;lt;math&amp;gt;k := k'&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Correctness:''' Obviously, the heap item at the old &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; now fulfills the heap property, and the new &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; is now the only index that does not necessarily fulfill it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Complexity==&lt;br /&gt;
'''Statement:''' The asymptotic complexity is logarithmic in the worst case.&lt;br /&gt;
&lt;br /&gt;
'''Proof:''' Obvious.&lt;br /&gt;
&lt;br /&gt;
==Further information==&lt;br /&gt;
Note that the loop is identical to the loop in [[Heap as array: decrease key]].&lt;/div&gt;</summary>
		<author><name>Cuozzo</name></author>
	</entry>
</feed>