<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Data Structures &#8211; Inga X</title>
	<atom:link href="https://ingax.com/category/data-structures/feed/" rel="self" type="application/rss+xml" />
	<link>https://ingax.com</link>
	<description>An education platform for people passionate about software engineering to learn problem solving techniques and useful algorithms and data structures</description>
	<lastBuildDate>Sat, 12 Nov 2022 17:41:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.18</generator>
	<item>
		<title>Simple Hash Table in Swift</title>
		<link>https://ingax.com/simple-hash-table-in-swift/</link>
					<comments>https://ingax.com/simple-hash-table-in-swift/#respond</comments>
		
		<dc:creator><![CDATA[David Inga]]></dc:creator>
		<pubDate>Mon, 26 Aug 2019 22:04:07 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[GIP]]></category>
		<category><![CDATA[Swift]]></category>
		<guid isPermaLink="false">https://ingax.com/?p=6667</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<p><script src="https://gist.github.com/davidinga/c27385cfd717f9b53082c5d252cc1277.js"></script></p>
]]></content:encoded>
					
					<wfw:commentRss>https://ingax.com/simple-hash-table-in-swift/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Graph with Adjacency List</title>
		<link>https://ingax.com/graph-with-adjacency-list/</link>
					<comments>https://ingax.com/graph-with-adjacency-list/#respond</comments>
		
		<dc:creator><![CDATA[David Inga]]></dc:creator>
		<pubDate>Mon, 26 Aug 2019 06:50:25 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[GIP]]></category>
		<category><![CDATA[Swift]]></category>
		<guid isPermaLink="false">https://ingax.com/?p=6640</guid>

					<description><![CDATA[Quick Facts Array of Linked Lists Array size equal to number of vertices. Each index in array corresponds to linked list with vertices connecting to...]]></description>
										<content:encoded><![CDATA[
<h3>Quick Facts</h3>



<ul><li>Array of Linked Lists</li><li>Array size equal to number of vertices.</li><li>Each index in array corresponds to linked list with vertices connecting to the vertex at this index.</li></ul>



<p>Pros:</p>



<ul><li>Saves space \(O( |V| + |E| )\), worst case \(O( V^2 )\)</li><li>Adding a vertex is easier.</li></ul>



<p>Cons:</p>



<ul><li>Checking whether an edge exists between two vertices takes \(O( V )\) time.</li></ul>


<p><script src="https://gist.github.com/davidinga/212c3b8c2244e7ae1c4ba2e0ecb49fc3.js"></script></p>


<h3>References</h3>



<ul><li><a rel="noreferrer noopener" aria-label="https://www.geeksforgeeks.org/graph-and-its-representations/ (opens in a new tab)" href="https://www.geeksforgeeks.org/graph-and-its-representations/" target="_blank">https://www.geeksforgeeks.org/graph-and-its-representations/</a></li><li><a rel="noreferrer noopener" aria-label="https://www.programiz.com/dsa/graph-adjacency-list (opens in a new tab)" href="https://www.programiz.com/dsa/graph-adjacency-list" target="_blank">https://www.programiz.com/dsa/graph-adjacency-list</a></li><li><a href="https://en.wikipedia.org/wiki/Adjacency_list" target="_blank" rel="noreferrer noopener" aria-label="https://en.wikipedia.org/wiki/Adjacency_list (opens in a new tab)">https://en.wikipedia.org/wiki/Adjacency_list</a></li></ul>
]]></content:encoded>
					
					<wfw:commentRss>https://ingax.com/graph-with-adjacency-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Graph with Adjacency Matrix</title>
		<link>https://ingax.com/graph-with-adjacency-matrix/</link>
					<comments>https://ingax.com/graph-with-adjacency-matrix/#respond</comments>
		
		<dc:creator><![CDATA[David Inga]]></dc:creator>
		<pubDate>Sun, 25 Aug 2019 22:02:08 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[GIP]]></category>
		<category><![CDATA[Swift]]></category>
		<guid isPermaLink="false">https://ingax.com/?p=6637</guid>

					<description><![CDATA[Quick Facts Represents graph with &#8220;V&#8221; nodes into a \(V x V\) binary matrix. A 1 means the two vertices are connected; and a 0...]]></description>
										<content:encoded><![CDATA[
<h3>Quick Facts</h3>



<ul><li>Represents graph with &#8220;V&#8221; nodes into a \(V x V\) binary matrix.</li><li>A 1 means the two vertices are connected; and a 0 means they are not connected.</li></ul>



<p>Pros:</p>



<ul><li>Easy to implement.</li><li>Adding and removing an edge, and checking whether there is an edge from one vertex to another is very efficient. Time complexity is \(O(1)\).</li><li>Good choice of implementation if the graph is dense and there are a large number of edges.</li><li>By performing operations on the adjacency matrix, we can get important insights into the nature of the graph and the relationship between its vertices. </li></ul>



<p>Cons:</p>



<ul><li>Takes up \(O(V^2)\) space. For large graphs, too much memory is consumed. Most real world applications for graphs do not have many connections. Therefore, in these situations, too much space is wasted.</li><li>Adding vertex takes \(O( V^2 )\) time.</li></ul>


<p><script src="https://gist.github.com/davidinga/5c02eb8dfbfbdf201677903de518eb4b.js"></script></p>


<h3>References</h3>



<ul><li><a rel="noreferrer noopener" aria-label="https://www.geeksforgeeks.org/graph-and-its-representations/ (opens in a new tab)" href="https://www.geeksforgeeks.org/graph-and-its-representations/" target="_blank">https://www.geeksforgeeks.org/graph-and-its-representations/</a></li><li><a rel="noreferrer noopener" aria-label="https://github.com/raywenderlich/swift-algorithm-club/blob/master/Graph/Graph/AdjacencyMatrixGraph.swift (opens in a new tab)" href="https://github.com/raywenderlich/swift-algorithm-club/blob/master/Graph/Graph/AdjacencyMatrixGraph.swift" target="_blank">https://github.com/raywenderlich/swift-algorithm-club/blob/master/Graph/Graph/AdjacencyMatrixGraph.swift</a></li><li><a href="https://www.programiz.com/dsa/graph-adjacency-matrix">https://www.programiz.com/dsa/graph-adjacency-matrix</a></li><li><a href="https://en.wikipedia.org/wiki/Adjacency_matrix" target="_blank" rel="noreferrer noopener" aria-label="https://en.wikipedia.org/wiki/Adjacency_matrix (opens in a new tab)">https://en.wikipedia.org/wiki/Adjacency_matrix</a></li></ul>
]]></content:encoded>
					
					<wfw:commentRss>https://ingax.com/graph-with-adjacency-matrix/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Graph with Objects and Pointers</title>
		<link>https://ingax.com/graph-with-objects-and-pointers/</link>
					<comments>https://ingax.com/graph-with-objects-and-pointers/#respond</comments>
		
		<dc:creator><![CDATA[David Inga]]></dc:creator>
		<pubDate>Sun, 25 Aug 2019 03:10:04 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[GIP]]></category>
		<category><![CDATA[Swift]]></category>
		<guid isPermaLink="false">https://ingax.com/?p=6631</guid>

					<description><![CDATA[Quick Facts Pros: Time complexity of edge and vertex insertion \(O(1)\). Consumes \(O(E + V)\) space. Searching for edge or vertex takes \(O(1)\) time. Dynamic...]]></description>
										<content:encoded><![CDATA[
<h3>Quick Facts</h3>



<p>Pros:</p>



<ul><li>Time complexity of edge and vertex insertion \(O(1)\).</li><li>Consumes \(O(E + V)\) space.</li><li>Searching for edge or vertex takes \(O(1)\) time.</li><li>Dynamic size.</li></ul>



<p>Cons:</p>



<ul><li>Deletion of vertices takes \(O(E)\) in the worst case, when an edge has a vertex to every edge.</li><li>Objects not stored in continuous space in memory. Not cache friendly.</li></ul>


<p><script src="https://gist.github.com/davidinga/56ead53a4a5045cdbad56945a8de30b4.js"></script></p>


<h3>References</h3>



<ul><li><a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://www.geeksforgeeks.org/graph-and-its-representations/" target="_blank">https://www.geeksforgeeks.org/graph-and-its-representations/</a></li><li><a rel="noreferrer noopener" aria-label="https://www.raywenderlich.com/773-swift-algorithm-club-graphs-with-adjacency-list (opens in a new tab)" href="https://www.raywenderlich.com/773-swift-algorithm-club-graphs-with-adjacency-list" target="_blank">https://www.raywenderlich.com/773-swift-algorithm-club-graphs-with-adjacency-list</a></li><li><a href="https://en.wikipedia.org/wiki/Graph_(abstract_data_type)" target="_blank" rel="noreferrer noopener" aria-label="https://en.wikipedia.org/wiki/Graph_(abstract_data_type) (opens in a new tab)">https://en.wikipedia.org/wiki/Graph_(abstract_data_type)</a></li></ul>
]]></content:encoded>
					
					<wfw:commentRss>https://ingax.com/graph-with-objects-and-pointers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Graphs</title>
		<link>https://ingax.com/graphs/</link>
					<comments>https://ingax.com/graphs/#respond</comments>
		
		<dc:creator><![CDATA[David Inga]]></dc:creator>
		<pubDate>Thu, 20 Jun 2019 03:24:54 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[GIP]]></category>
		<category><![CDATA[Swift]]></category>
		<guid isPermaLink="false">https://ingax.com/?p=6563</guid>

					<description><![CDATA[Quick Facts Constructed from edges (nodes) and vertices that connect them. Graph types include: Directed or Undirected Weighted or Unweighted Connected or Disconnected Represented in...]]></description>
										<content:encoded><![CDATA[
<h3>Quick Facts</h3>



<ul><li>Constructed from edges (nodes) and vertices that connect them.</li><li>Graph types include:<ul><li>Directed or Undirected</li><li>Weighted or Unweighted</li><li>Connected or Disconnected</li></ul></li><li>Represented in code as:<ul><li>Adjacency List</li><li>Adjacency Matrix</li><li>Objects and Pointers</li></ul></li><li>A tree is a graph, but a graph isn&#8217;t always a tree.</li></ul>



<h4>Graph Traversal</h4>



<ul><li>Depth First Search (DFS)</li><li>Breadth First Search (BFS)</li></ul>



<h4>Shortest Path</h4>



<ul><li>Dijkstra</li><li>A*</li></ul>



<h3>Graph Representation</h3>



<ul><li><a href="https://ingax.com/graph-with-adjacency-list/">Adjacency List</a></li><li><a href="https://ingax.com/graph-with-adjacency-matrix/">Adjacency Matrix</a></li><li><a href="https://ingax.com/graph-with-objects-and-pointers/">Objects and Pointers</a></li></ul>
]]></content:encoded>
					
					<wfw:commentRss>https://ingax.com/graphs/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Heaps</title>
		<link>https://ingax.com/heaps/</link>
					<comments>https://ingax.com/heaps/#respond</comments>
		
		<dc:creator><![CDATA[David Inga]]></dc:creator>
		<pubDate>Mon, 10 Jun 2019 05:57:40 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[GIP]]></category>
		<category><![CDATA[Swift]]></category>
		<guid isPermaLink="false">https://ingax.com/?p=6520</guid>

					<description><![CDATA[Quick Facts]]></description>
										<content:encoded><![CDATA[
<h3>Quick Facts</h3>


<div class="col span_6" data-animation="" data-delay="0">


<ul><li>Complete Binary Tree</li><li>Either a Min-Heap or Max-Heap</li><li>Self Balancing</li><li>Two most important operations are Insertion and the Extraction of highest priority element.</li><li>The node at the top of the Heap has the greatest priority, the same is true for every node recursively moving down the tree structure.</li><li>Moving down the tree, each level has twice as many nodes as the previous level.</li></ul>


</div><div class="col span_6 col_last" data-animation="" data-delay="0">


<ul><li>Min-Heap is synonymous with Priority Queue</li><li>HeapSort uses a Max-Heap</li><li>An Array is a great data structure for storing nodes in a Heap.</li><li>Building helper functions greatly assists in calculations of indices, swapping node positions, and more.</li></ul>


</div><div class="clear"></div>
<p><script src="https://gist.github.com/davidinga/925ea2878ae8581977fd1d55b1bcc038.js"></script></p>]]></content:encoded>
					
					<wfw:commentRss>https://ingax.com/heaps/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Binary Tree Descriptors</title>
		<link>https://ingax.com/binary-tree-descriptors/</link>
					<comments>https://ingax.com/binary-tree-descriptors/#comments</comments>
		
		<dc:creator><![CDATA[David Inga]]></dc:creator>
		<pubDate>Sun, 09 Jun 2019 06:14:57 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[GIP]]></category>
		<guid isPermaLink="false">https://ingax.com/?p=6522</guid>

					<description><![CDATA[Complete Binary Tree Every level of the tree is filled, except for perhaps the last level. The last level must be filled from left to...]]></description>
										<content:encoded><![CDATA[
<h3>Complete Binary Tree</h3>



<p>Every level of the tree is filled, except for perhaps the last level. The last level must be filled from left to right.</p>



<h3>Full Binary Tree</h3>



<p>Every node has zero or both children.</p>



<h3>Perfect Binary Tree</h3>



<p>Every node has a left and right child. It is both a Complete Binary Tree and a Full Binary Tree.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ingax.com/binary-tree-descriptors/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Binary Trees</title>
		<link>https://ingax.com/binary-trees/</link>
					<comments>https://ingax.com/binary-trees/#respond</comments>
		
		<dc:creator><![CDATA[David Inga]]></dc:creator>
		<pubDate>Thu, 06 Jun 2019 07:48:17 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[GIP]]></category>
		<category><![CDATA[Swift]]></category>
		<guid isPermaLink="false">https://ingax.com/?p=6475</guid>

					<description><![CDATA[Quick Facts A tree where each parent node has at most two child nodes. The first node is called the root node. Any nodes without...]]></description>
										<content:encoded><![CDATA[
<h3>Quick Facts</h3>



<ul><li>A tree where each parent node has at most two child nodes. </li><li>The first node is called the root node. </li><li>Any nodes without child nodes are called leaf or terminal nodes. </li><li>Each node stores a pointer to a left child, right child, and data. </li><li>Sometimes nodes will also store a pointer to the parent node.</li></ul>



<h3>Binary Tree Enumeration</h3>


<p><script src="https://gist.github.com/davidinga/505409f2a5f83988377bdab32cf7fd2d.js"></script></p>


<h3>References</h3>



<ul><li><a rel="noreferrer noopener" aria-label="https://www.geeksforgeeks.org/binary-tree-data-structure/ (opens in a new tab)" href="https://www.geeksforgeeks.org/binary-tree-data-structure/" target="_blank">https://www.geeksforgeeks.org/binary-tree-data-structure/</a></li><li><a rel="noreferrer noopener" aria-label="https://en.wikipedia.org/wiki/Binary_tree (opens in a new tab)" href="https://en.wikipedia.org/wiki/Binary_tree" target="_blank">https://en.wikipedia.org/wiki/Binary_tree</a></li><li><a href="https://www.raywenderlich.com/990-swift-algorithm-club-swift-binary-search-tree-data-structure" target="_blank" rel="noreferrer noopener" aria-label="https://www.raywenderlich.com/990-swift-algorithm-club-swift-binary-search-tree-data-structure (opens in a new tab)">https://www.raywenderlich.com/990-swift-algorithm-club-swift-binary-search-tree-data-structure</a></li></ul>
]]></content:encoded>
					
					<wfw:commentRss>https://ingax.com/binary-trees/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Hash Sets</title>
		<link>https://ingax.com/hash-sets/</link>
					<comments>https://ingax.com/hash-sets/#respond</comments>
		
		<dc:creator><![CDATA[David Inga]]></dc:creator>
		<pubDate>Wed, 05 Jun 2019 23:14:39 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[GIP]]></category>
		<category><![CDATA[Swift]]></category>
		<guid isPermaLink="false">https://ingax.com/?p=6325</guid>

					<description><![CDATA[A Hash Set is an unordered collection of unique elements, where elements are stored in a table using a hash function. In my implementation, elements...]]></description>
										<content:encoded><![CDATA[<p>A Hash Set is an unordered collection of unique elements, where elements are stored in a table using a hash function. In my implementation, elements are stored in an Array of Linked Lists.</p>
<div class="col span_6" data-animation="" data-delay="0"></p>
<h3>Quick Facts</h3>
<ul>
<li>An unordered collection of unique elements.</li>
<li>Elements in set must be hashable.</li>
<li>Swift&#8217;s Set implementation in Foundation is a Hash Set.</li>
</ul>
<h3>Use Cases</h3>
<ul>
<li>Test efficiency for membership.</li>
<li>When not concerned about order of elements.</li>
<li>When need to ensure elements in collection only appear once.</li>
</ul>
<p></div> <div class="col span_6 col_last" data-animation="" data-delay="0"></p>
<h3>Structure</h3>
<div class="code-toolbar">
<pre class=" language-swift"><code class=" language-swift"><span class="token keyword">var</span> <span class="token builtin">isEmpty</span><span class="token punctuation">:</span> <span class="token builtin">Bool</span></code></pre>
<div class="toolbar">
<div class="toolbar-item"><button>Copy</button></div>
</div>
</div>
<p>Returns true if the set is empty or false if it contains elements.</p>
<div class="code-toolbar">
<pre class=" language-swift"><code class=" language-swift"><span class="token keyword">var</span> <span class="token builtin">count</span><span class="token punctuation">:</span> <span class="token builtin">Int</span></code></pre>
<div class="toolbar">
<div class="toolbar-item"><button>Copy</button></div>
</div>
</div>
<p>Returns the number of elements in the set.</p>
<pre><code class="language-swift">func insert(_ element: Element) -&gt; Bool</code></pre>
<p>Inserts the element into the set the set does not already contain it. Returns true if the element was inserted and false if it was not.</p>
<pre><code class="language-swift">func remove(_ element: Element) -&gt; Element?</code></pre>
<p>Removes an element from the set. Returns the element if it is in the set.</p>
<pre><code class="language-swift">func removeAll()</code></pre>
<p>Removes all elements from the set.</p>
<pre><code class="language-swift">func contains(_ element: Element) -&gt; Element?</code></pre>
<p>Tests for membership. The element is returned if the set contains it.</p>
<pre><code class="language-swift">func union(_ hashSet: HashSet) -&gt; HashSet</code></pre>
<p>Returns a new set with the elements of both this set and the given set.</p>
<pre><code class="language-swift">func intersection(_ hashSet: HashSet) -&gt; HashSet</code></pre>
<p>Returns a new set with the elements that are common to both this set and the given set.</p>
<pre><code class="language-swift">func difference(_ hashSet: HashSet) -&gt; HashSet</code></pre>
<p>Removes the elements of the given set from this set.</p>
<p></div><div class="clear"></div> <div class="divider-wrap" data-alignment="default"><div  data-width="100%" data-animate="" data-animation-delay="" data-color="default" class="divider-border"></div></div>
<p><script src="https://gist.github.com/davidinga/6e6ed69c49fede21068d9c091b058e62.js"></script><br />
<div class="divider-wrap" data-alignment="default"><div  data-width="100%" data-animate="" data-animation-delay="" data-color="default" class="divider-border"></div></div>
<h3>References</h3>
<ol>
<li><a href="https://developer.apple.com/documentation/swift/set" target="_blank" rel="noopener noreferrer">https://developer.apple.com/documentation/swift/set</a></li>
<li><a href="https://github.com/raywenderlich/swift-algorithm-club/tree/master/Hash%20Set" target="_blank" rel="noopener noreferrer">https://github.com/raywenderlich/swift-algorithm-club/tree/master/Hash%20Set</a></li>
<li><a href="https://developer.apple.com/documentation/swift/hashable" target="_blank" rel="noopener noreferrer">https://developer.apple.com/documentation/swift/hashable</a></li>
</ol>
]]></content:encoded>
					
					<wfw:commentRss>https://ingax.com/hash-sets/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Hash Tables</title>
		<link>https://ingax.com/hash-tables/</link>
					<comments>https://ingax.com/hash-tables/#respond</comments>
		
		<dc:creator><![CDATA[David Inga]]></dc:creator>
		<pubDate>Mon, 03 Jun 2019 02:38:59 +0000</pubDate>
				<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[GIP]]></category>
		<category><![CDATA[Swift]]></category>
		<guid isPermaLink="false">https://ingax.com/?p=6342</guid>

					<description><![CDATA[A Hash Table is an important Data Structure which is designed to use a special function called the Hash function which is used to map...]]></description>
										<content:encoded><![CDATA[<p>A Hash Table is an important Data Structure which is designed to use a special function called the Hash function which is used to map a given value with a particular key for faster access of elements. The efficiency of mapping depends of the efficiency of the hash function used.</p>
<p>Let a hash function H(x) maps the value at the index x%10 in an Array. For example if the list of values is [11,12,13,14,15] it will be stored at positions {1,2,3,4,5} in the array or Hash table respectively.</p>
<p><img class="aligncenter size-large wp-image-251333" src="https://media.geeksforgeeks.org/wp-content/cdn-uploads/HashingDataStructure-min-1024x512.png" sizes="(max-width: 665px) 100vw, 665px" srcset="https://www.geeksforgeeks.org/wp-content/uploads/HashingDataStructure-min-1024x512.png 1024w, https://www.geeksforgeeks.org/wp-content/uploads/HashingDataStructure-min-300x150.png 300w, https://www.geeksforgeeks.org/wp-content/uploads/HashingDataStructure-min-768x384.png 768w, https://www.geeksforgeeks.org/wp-content/uploads/HashingDataStructure-min-660x330.png 660w, https://www.geeksforgeeks.org/wp-content/uploads/HashingDataStructure-min.png 1600w" alt="" width="665" height="333" /></p>
<div class="col span_6" data-animation="" data-delay="0"></p>
<h3>Characteristics</h3>
<ul>
<li>An array, storing pointers to elements</li>
<li>Maps key to table index with Hash Function</li>
<li>Efficiency depends on Hash Function and table size</li>
<li>Hash Function returns signed Int in Swift</li>
<li>Table Index = abs(key.hashValue%table.count)</li>
<li>Collisions
<ul>
<li>Multiple keys mapping to same index</li>
<li>Can handle collisions with Chaining</li>
</ul>
</li>
<li>Chaining
<ul>
<li>At every table index, point to array or linked list</li>
<li>After a collision, append element to array or linked list</li>
</ul>
</li>
<li>Table Size
<ul>
<li>Choose sufficiently large table for the number of elements</li>
<li>Choose next largest <a href="https://cs.stackexchange.com/a/64191" target="_blank" rel="noopener noreferrer">prime number to reduce chances of collisions</a></li>
</ul>
</li>
</ul>
<h3>Applications</h3>
<ul>
<li>Password Verification</li>
<li>Unordered_set &amp; unordered_map in C++, HashSet &amp; HashMap in java, dict in python etc.</li>
<li>Compiler Operation</li>
<li>Rabin-Karp Algorithm</li>
<li>Linking filename and path together.</li>
</ul>
<p></div> <div class="col span_6 col_last" data-animation="" data-delay="0"></p>
<h3>Structure</h3>
<pre><code class="language-swift">table.count</code></pre>
<p>Returns a Int with the number of elements in the hash table.</p>
<pre><code class="language-swift">table.isEmpty</code></pre>
<p>Returns a Bool. True if the hash table is empty. False if the hash table has elements.</p>
<pre><code class="language-swift">table.value(forKey key: Key) -&gt; Value?</code></pre>
<p>Given a key to the hash table, returns an associated value.</p>
<pre><code class="language-swift">table.updateValue(_ value: Value, forKey key: Key) -&gt; Value?</code></pre>
<p>Updates the value for the location of the given key. Returns a value.</p>
<pre><code class="language-swift">table.removeAll()</code></pre>
<p>Removes all the elements in the hash table.</p>
<pre><code class="language-swift">table.index(forKey key: Key) -&gt; Int</code></pre>
<p>Returns an Int with the Index of the element associated with the given key.</p>
<p></div><div class="clear"></div>
<div class="divider-wrap" data-alignment="default"><div  data-width="100%" data-animate="" data-animation-delay="" data-color="default" class="divider-border"></div></div>
<h2>Hash Table with Chaining</h2>
<p><script src="https://gist.github.com/davidinga/ee9d26b390e192e6d691d86299503bf8.js"></script></p>
<div class="divider-wrap" data-alignment="default"><div  data-width="100%" data-animate="" data-animation-delay="" data-color="default" class="divider-border"></div></div>
<h2>Hash Table with Only Keys</h2>
<p><script src="https://gist.github.com/davidinga/adc0a1c4f6432ff432387550e231f06c.js"></script></p>
<div class="divider-wrap" data-alignment="default"><div  data-width="100%" data-animate="" data-animation-delay="" data-color="default" class="divider-border"></div></div>
<h3>References</h3>
<ol>
<li><a href="https://developer.apple.com/documentation/swift/dictionary" target="_blank" rel="noopener noreferrer">https://developer.apple.com/documentation/swift/dictionary</a></li>
<li><a href="https://www.raywenderlich.com/206-swift-algorithm-club-hash-tables" target="_blank" rel="noopener noreferrer">https://www.raywenderlich.com/206-swift-algorithm-club-hash-tables</a></li>
<li><a href="https://en.wikipedia.org/wiki/Hash_function" target="_blank" rel="noopener noreferrer">https://en.wikipedia.org/wiki/Hash_function</a></li>
<li><a href="https://developer.apple.com/documentation/swift/hashable/1540917-hashvalue" target="_blank" rel="noopener noreferrer">https://developer.apple.com/documentation/swift/hashable/1540917-hashvalue</a></li>
<li><a href="https://developer.apple.com/documentation/swift/hashable/2995575-hash" target="_blank" rel="noopener noreferrer">https://developer.apple.com/documentation/swift/hashable/2995575-hash</a></li>
</ol>
]]></content:encoded>
					
					<wfw:commentRss>https://ingax.com/hash-tables/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Object Caching 32/110 objects using disk
Page Caching using disk: enhanced 
Database Caching using disk

Served from: ingax.com @ 2026-07-21 15:20:59 by W3 Total Cache
-->