Last active
December 30, 2015 07:59
-
-
Save dhammack/7799136 to your computer and use it in GitHub Desktop.
To study for the DSA final, I'm implementing all the algorithms we've covered since exam 2. This is an ipython notebook of them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "DSA Exam Study" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "# Implementations and explainations of different algorithms #\n\nTo study for the exam, I'm going to go through the powerpoints and implement the algorithms, along with explainations. \n\n### Implemented in this workbook: ###\n\n#### Graphs ####\n\n\n* Directed Graph\n* Undirected Graph\n* Breadth first search\n* Depth first search\n* Find all connected components (undirected only)\n* Best path (Dijkstra's algorithm)\n* Cycle detection\n* Kruskal's minimal cost spanning tree algoritm\n\n\n#### Divide and Conquer ####\n\n* minimum of unsorted list\n* tiling a defective chessboard (no code)\n* using queues instead of recursion (general principle)\n* merge sort\n* non recursive merge sort (uses queue idea)\n* natural merge sort\n* quick sort\n* in place quick sort (**hard**)\n* rank finding (find kth smallest element in unsorted list)\n* closest pair of points (**hard**)\n\n#### Greedy Methods ####\n\n* 0/1 Knapsack greedy profit density heuristic (**tricky**)\n\n#### Old material ####\n\n* LZW Compression\n* Hash Table\n\n\n#### In progress ####\n\n* AVL trees\n" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "from Queue import Queue\n%pylab inline\n\nclass WeightedDirectedGraph(object):\n \"\"\"\n Implementation of a graph, using an adjacency map instead of a matrix.\n \n \"\"\"\n def __init__(self):\n \"\"\"\n Creates a weighted directed graph. In other words, there is a collection of nodes\n and edges. Each edge goes from one node to another but not necessarily in reverse. \n Each node also has a weight associated with it.\n \"\"\"\n self.A = {}\n \n def AddNode(self, node_num):\n \"\"\"\n Adds a node to the graph.\n \"\"\"\n #check that the node isn't already here\n if node_num in self.A:\n print 'Node is already in graph'\n return\n \n self.A[node_num] = []\n return\n \n def AddEdge(self, start, end, weight):\n \"\"\"\n Add an edge to the graph, given the start, end and weight.\n \"\"\"\n #add an edge\n if start not in self.A:\n print 'Add a node before connecting it'\n return\n \n self.A[start].append((end, weight))\n return\n \n def ConnectedNodes(self, start):\n \"\"\"\n To find the connected nodes for a given node, we use the inner adjacency map (sparse matrix).\n The map takes the node id and returns the list of all outgoing connections and weights.\n \"\"\"\n #returns all connected nodes\n if start not in self.A: return []\n return [node for (node,weight) in self.A[start] if node != start]\n \n def BFS(self, start):\n \"\"\"\n Returns a list of nodes, in order as visited from a BFS starting at start\n \"\"\"\n found, visited, Q = [], set([start]), Queue()\n Q.put(start)\n while not Q.empty():\n current = Q.get()\n found.append(current)\n #explore around.\n for neighbor in self.ConnectedNodes(current):\n if neighbor not in visited:\n Q.put(neighbor)\n visited.add(neighbor)\n return found\n \n def DFS(self, start, visited=None):\n \"\"\"\n Traverses the graph with depth-first search, recursively.\n \"\"\"\n #don't visit this node again\n if visited is None: visited=set()\n visited.add(start)\n \n #recrusive step: concatenate DFS of each neighbor\n traversal = [start]\n for neighbor in self.ConnectedNodes(start):\n if neighbor in visited: continue\n traversal.extend(self.DFS(neighbor, visited))\n #if we hit the base case, then we'll skip the loop\n return traversal\n \n def CanReach(self, start, end):\n \"\"\"\n Returns true if you can reach the end from the start.\n \"\"\"\n return end in self.DFS(start) #that was easy\n \n def PathDijkstra(self, start, end):\n \"\"\"\n Uses Dijkstra's greedy algorithm to find a path from start to end.\n Returns the path, but it finds paths to all nodes. It could be modified\n to quit once 'end' is visited, if desired.\n Returns a tuple (path, dist).\n \"\"\"\n #Breadth-first-search with a greedy heuristic\n prev = {start:start} #given a node, it finds the previous one in the path\n dist = {node:sys.maxint for node in self.A.iterkeys()} #holds distance from start to each node in path\n dist[start] = 0 #start->start is zero\n visited = set()\n current = start\n while len(visited) < len(self.A):\n #find the node with the smallest dist not yet visited\n current = min((node for node in dist.iterkeys() if node not in visited),\n key = lambda x: dist[x])\n #mark this node as visited\n visited.add(current)\n #check neighbors\n for neighbor in self.ConnectedNodes(current):\n dist_to_neighbor = next(dist for node,dist in self.A[current] if node == neighbor)\n if dist[current]+dist_to_neighbor < dist[neighbor]:\n #this path is better, so take it\n dist[neighbor] = dist[current]+dist_to_neighbor\n prev[neighbor] = current\n \n #now just backtrace to get the path\n path = []\n current = end\n while prev[current] != current:\n path.append(current)\n current = prev[current]\n \n return ([start] + path[::-1], dist[end])\n ", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "Populating the interactive namespace from numpy and matplotlib\n" | |
} | |
], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "So now let's build up a graph and test it out." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "G = WeightedDirectedGraph()\nG.AddNode('a')\nG.AddNode('b')\nG.AddEdge('a','b',10)\nG.AddNode('c')\nG.AddEdge('b','c',10)\nG.AddNode('d')\nG.AddEdge('b','d',10)\nG.AddNode('e')\nG.AddEdge('a','e',10)\nprint 'breadth first search from a', G.BFS('a')\nprint 'breadth first search from b', G.BFS('b')\nprint 'breadth first search from e', G.BFS('e')", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "breadth first search from a ['a', 'b', 'e', 'c', 'd']\nbreadth first search from b ['b', 'c', 'd']\nbreadth first search from e ['e']\n" | |
} | |
], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "It's hard to tell if the results are correct, so I'm going to use a neat library for graphs: networkx" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "import networkx as nx\n%pylab inline\nG2 = nx.DiGraph()\nG2.add_edge('a','b')\nG2.add_edge('b','c')\nG2.add_edge('b','d')\nG2.add_edge('a','e')\n#draw\nnx.draw_spectral(G2)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "Populating the interactive namespace from numpy and matplotlib\n" | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "display_data", | |
"png": "iVBORw0KGgoAAAANSUhEUgAAAd8AAAFBCAYAAAA2bKVrAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAG6BJREFUeJzt3XmUFPXd7/F3D8PsA8ruY4KsBsEVURJwu0YwCCREI1GD\n9zFRSJ4R3JCAUVEjnsDFEO5VUUNQ475hjKKICxrzGAKIWxR0CBiiUVZRZpNlpu8fLTyAjSyZruqu\ner/OmXPoqurJ90x6/My3flX1TSSTySSSJCkweWEXIElS3Bi+kiQFzPCVJClghq8kSQEzfCVJCpjh\nK0lSwAxfSZICZvhKkhQww1eSpIAZvpIkBczwlSQpYIavJEkBM3wlSQqY4StJUsAMX0mSAmb4SpIU\nMMNXkqSAGb6SJAXM8JUkKWCGryRJATN8JUkKmOErSVLADF9JkgJm+EqSFDDDV5KkgBm+kiQFzPCV\nJClghq8kSQEzfCVJCpjhK0lSwAxfSZICZvhKkhQww1eSpIAZvpIkBczwlSQpYIavJEkBM3wlSQqY\n4StJUsAMX0mSAmb4SpIUMMNXkqSAGb6SJAUsP+wCJEnZIZlM8uGHH7Ju3ToAWrZsyde+9jUSiUTI\nlUWP4StJMVdVVcW999zDtMmTWb1qFe2aNgVg5ebNtG3XjooxY/jRsGGUl5eHXGl0JJLJZDLsIiRJ\n4Zh+222Mvewy/ldeHhU1NZwMbO1zG4C5wLTSUl5KJpk8dSrnDx8eXrERYvhKUkxdf/XV3D1lCrNq\na/nGbo59FxhUUsKPx4zhymuvDaC6aPOCK0mKoRnTp/P7KVN4ZTfBex5wNdANeKW2ljsmT+auO+4I\npMYos/OVpJipq6vj661b83JNDd13c+yPga8Dv/zi9dvAyWVl/HPNGoqKijJaZ5T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XkqSA\nGb6SJAXM8JUkKWCGryRJATN8JUkKmOErSVLADF9JkgJm+EqSFDDDV5KkgBm+kiQFzPCVJClghq8k\nSQEzfCVJCpjhK0lSwAxfSZIC9v8BqHWbrK8LsE8AAAAASUVORK5CYII=\n", | |
"text": "<matplotlib.figure.Figure at 0x6377240>" | |
} | |
], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Now it's easy to see the connections. We can also see that the BFS was correct." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "print [i for i in nx.bfs_edges(G2, 'a')]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "[('a', 'b'), ('a', 'e'), ('b', 'c'), ('b', 'd')]\n" | |
} | |
], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Lets try to build the graph specified by the homework assignment, and then check our Dijkstra's algorithm." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "G = WeightedDirectedGraph()\n#add nodes\nfor i in range(1,7):\n G.AddNode(i)\n#add edges\nG.AddEdge(1,2,10)\nG.AddEdge(1,4,30)\nG.AddEdge(1,5,100)\nG.AddEdge(2,3,50)\nG.AddEdge(3,6,5)\nG.AddEdge(3,5,10)\nG.AddEdge(4,3,20)\nG.AddEdge(4,6,15)\nG.AddEdge(5,4,60)\n\n#test dijkstra\nprint G.PathDijkstra(1, 6)\nprint G.DFS(1)\nprint G.BFS(1)\nprint G.CanReach(1,6)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "([1, 4, 6], 45)\n[1, 2, 3, 6, 5, 4]\n[1, 2, 4, 5, 3, 6]\nTrue\n" | |
} | |
], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "We can also draw this graph to confirm that it's correct.\n" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "G2 = nx.DiGraph()\nG2.add_weighted_edges_from([(1,2,10), (1,4,30),(1,5,100)])\nG2.add_weighted_edges_from([(2,3,50), (3,6,5), (3,5,10)])\nG2.add_weighted_edges_from([(4,3,20), (4,6,15), (5,4,60)])\n#draw\nnx.draw_circular(G2)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "display_data", | |
"png": "iVBORw0KGgoAAAANSUhEUgAAAd8AAAFBCAYAAAA2bKVrAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3Xd8U9X/x/FXOqBA2VNAtorsUiizDBmCDAGBMsqWvUqj\novIVB4ID0zIKlL2FFpG9oexNyxARlCl7lFFaunN+fyD9UQqlhSQ3ST/PxyMPH5zc3PuOhHxyzj33\nXJ1SSiGEEEIIi3HQOoAQQgiR0UjxFUIIISxMiq8QQghhYVJ8hRBCCAuT4iuEEEJYmBRfIYQQwsKk\n+AohhBAWJsVXCCGEsDApvkIIIYSFSfEVQgghLEyKrxBCCGFhUnyFEEIIC5PiK4QQQliYFF8hhBDC\nwqT4CiGEEBYmxVcIIYSwMCm+QgghhIVJ8RVCCCEsTIqvEEIIYWFSfIUQQggLk+IrhBBCWJgUXyGE\nEMLCpPgKIYQQFibFVwghhLAwKb5CCCGEhUnxFUIIISxMiq8QQghhYVJ8hRBCCAuT4iuEEEJYmBRf\nIYQQwsKk+AohhBAWJsVXCCGEsDApvkIIIYSFOWkdQIi0uH//Pjdu3CA6OppcuXJRpEgRMmXKpHUs\nYWdiYmK4evUqDx48wNXVlTfeeIPs2bNrHUvYISm+wmoZjUa2bdvG1J9/ZtuuXbyROTNZdDruJSYS\n6+hIn/796Td4MMWLF9c6qrBxp0+fJnDiRBYuWEBOBwdyODgQZTRyKz6eVh98wKBPPqFWrVrodDqt\nowo7oVNKKa1DCPGs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sm3ebcAAAAASUVORK5CYII=\n", | |
"text": "<matplotlib.figure.Figure at 0x8686b00>" | |
} | |
], | |
"prompt_number": 7 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "And the shortest path..." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "print nx.shortest_path(G2, source=1, target=6)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "[1, 4, 6]\n" | |
} | |
], | |
"prompt_number": 8 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Let's implement a weighted undirected graph. I'll do this by just duplicating connections!" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "class WeightedUndirectedGraph(object):\n \"\"\"\n Implementation of a weighted, undirected graph. Uses an adjacency map (sparse matrix).\n \n \"\"\"\n def __init__(self):\n \"\"\"\n Creates a weighted undirected graph. In other words, there is a collection of nodes\n and edges. Each edge is symmetric.\n \"\"\"\n self.A = {}\n \n def AddNode(self, node_num):\n \"\"\"\n Adds a node to the graph.\n \"\"\"\n #check that the node isn't already here\n if node_num in self.A:\n print 'Node is already in graph'\n return\n \n self.A[node_num] = []\n return\n \n def AddEdge(self, start, end, weight):\n \"\"\"\n Add an edge to the graph connecting the two specified nodes\n \"\"\"\n #add an edge\n if start not in self.A:\n print 'Add a node before connecting it'\n return\n \n #in an undirected graph, we need connections going both ways!\n self.A[start].append((end, weight))\n self.A[end].append((start, weight))\n return\n \n def RemoveEdge(self, start, end):\n \"\"\"\n Removes an edge from the graph.\n \"\"\"\n self.A[start] = [(node,weight) for (node,weight) in self.A[start] if node!=end]\n self.A[end] = [(node,weight) for (node,weight) in self.A[end] if node!=start]\n return\n \n def ConnectedNodes(self, start):\n \"\"\"\n To find the connected nodes for a given node, we use the inner adjacency map (sparse matrix).\n The map takes the node id and returns the list of all outgoing connections and weights.\n \"\"\"\n #returns all connected nodes\n if start not in self.A: return []\n return [node for (node,weight) in self.A[start] if node != start]\n \n def BFS(self, start):\n \"\"\"\n Returns a list of nodes, in order as visited from a BFS starting at start\n \"\"\"\n found, visited, Q = [], set([start]), Queue()\n Q.put(start)\n while not Q.empty():\n current = Q.get()\n found.append(current)\n #explore around.\n for neighbor in self.ConnectedNodes(current):\n if neighbor not in visited:\n Q.put(neighbor)\n visited.add(neighbor)\n return found\n \n def DFS(self, start, visited=None):\n \"\"\"\n Traverses the graph with depth-first search, recursively.\n \"\"\"\n #don't visit this node again\n if visited is None: visited=set()\n visited.add(start)\n \n #recrusive step: concatenate DFS of each neighbor\n traversal = [start]\n for neighbor in self.ConnectedNodes(start):\n if neighbor in visited: continue\n traversal.extend(self.DFS(neighbor, visited))\n #if we hit the base case, then we'll skip the loop\n return traversal\n \n def CanReach(self, start, end):\n \"\"\"\n Returns true if you can reach the end from the start.\n \"\"\"\n return end in self.DFS(start) #that was easy\n \n def CountConnectedComponents(self):\n \"\"\"\n Finds the number of connected components. A connected component is a subgraph\n which has a path between each pair of nodes. \n \"\"\"\n visited = set()\n num = 0\n while len(visited) < len(self.A):\n #get a node which isn't yet visited\n current = next(node for node in self.A.iterkeys() if node not in visited)\n #update the visited set with all the nodes reachable from here\n visited.update(self.BFS(current))\n num += 1\n return num\n \n def display(self):\n #use networkx to display this graph\n G = nx.Graph()\n for start,outgoing in self.A.iteritems():\n G.add_weighted_edges_from([(start, end, weight) for (end,weight) in outgoing])\n \n nx.draw_circular(G)\n show()\n \n def ConnectedComponents(self):\n \"\"\"\n Returns a list of connected components - each of which is a graph.\n \"\"\"\n N = [node for node in self.A.iterkeys()] #list of nodes\n subgraphs = []\n while len(N) > 0:\n connected = self.DFS(N[0])\n G = WeightedUndirectedGraph()\n for node,connections in self.A.iteritems():\n if node in connected:\n G.A[node] = connections\n \n subgraphs.append(G)\n N = [node for node in N if node not in connected]\n return subgraphs\n \n def HasCycles(self):\n \"\"\"\n Uses DFS to determine if the graph has cycles.\n If there are more than one connected components, then it does DFS on each.\n While searching depth-first, if we hit any node twice then there is a cycle!\n \"\"\"\n if self.CountConnectedComponents() == 1:\n #number of edges is double (we duplicate connections in a undirected graph)\n edge_count = sum(len(outgoing) for outgoing in self.A.itervalues())/2\n return edge_count > len(self.A) - 1\n\n return any([subGraph.HasCycles() for subGraph in self.ConnectedComponents()])\n \n \n def KruskalsMethod(self):\n \"\"\"\n Uses Kruskal's method to find a minimum cost spanning tree.\n Returns: an undirected graph: the spanning tree\n \"\"\"\n \n #start with a forest which has no edges\n T = WeightedUndirectedGraph()\n for start in self.A.iterkeys():\n T.AddNode(start)\n\n edge_list = [(a,b,w) for a,outgoing in self.A.iteritems() for (b,w) in outgoing]\n while T.CountConnectedComponents() > 1:\n #Be greedy on edge cost - add the least cost edge\n (start,end,weight) = min((edge for edge in edge_list),\n key = lambda x: x[2])\n\n #see if adding this would cause a cycle\n comps = T.CountConnectedComponents()\n T.AddEdge(start, end, weight)\n \n #remove the edges from the candidates\n edge_list = [(s,e,w) for (s,e,w) in edge_list \n if (s!=start or e!=end) and (s!=end or e!=start)]\n \n if T.CountConnectedComponents() == comps:\n #we didn't connect anything - we must have created a cycle!\n T.RemoveEdge(start, end)\n continue\n #if we didn't add a cycle, then keep going!\n return T\n \n \n def PathDijkstra(self, start, end):\n \"\"\"\n Uses Dijkstra's greedy algorithm to find a path from start to end.\n Returns the path, but it finds paths to all nodes. It could be modified\n to quit once 'end' is visited, if desired.\n Returns a tuple (path, dist).\n \"\"\"\n #Breadth-first-search with a greedy heuristic\n prev = {start:start} #given a node, it finds the previous one in the path\n dist = {node:sys.maxint for node in self.A.iterkeys()} #holds distance from start to each node in path\n dist[start] = 0 #start->start is zero\n visited = set()\n current = start\n while len(visited) < len(self.A):\n #find the node with the smallest dist not yet visited\n current = min((node for node in dist.iterkeys() if node not in visited),\n key = lambda x: dist[x])\n #mark this node as visited\n visited.add(current)\n #check neighbors\n for neighbor in self.ConnectedNodes(current):\n dist_to_neighbor = next(dist for node,dist in self.A[current] if node == neighbor)\n if dist[current]+dist_to_neighbor < dist[neighbor]:\n #this path is better, so take it\n dist[neighbor] = dist[current]+dist_to_neighbor\n prev[neighbor] = current\n \n #now just backtrace to get the path\n path = []\n current = end\n while prev[current] != current:\n path.append(current)\n current = prev[current]\n \n return ([start] + path[::-1], dist[end])\n ", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 9 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "G = WeightedUndirectedGraph()\n#add nodes\nfor i in range(1,7):\n G.AddNode(i)\n#add edges\nG.AddEdge(1,2,10)\nG.AddEdge(1,4,30)\nG.AddEdge(1,5,100)\nG.AddEdge(2,3,50)\nG.AddEdge(3,6,5)\nG.AddEdge(3,5,10)\nG.AddEdge(4,3,20)\nG.AddEdge(4,6,15)\nG.AddEdge(5,4,60)\n\n#new\nG.AddNode('a')\nG.AddNode('b')\nG.AddEdge('a','b',10)\n\n#tests\nprint G.PathDijkstra(1, 6)\nprint G.DFS(1)\nprint G.BFS(1)\nprint G.CanReach(1,6)\nprint G.CanReach(1, 'a')\nprint G.CountConnectedComponents()\nG.display()\n", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "([1, 4, 6], 45)\n[1, 2, 3, 6, 4, 5]\n[1, 2, 4, 5, 3, 6]\nTrue\nFalse\n2\n" | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "display_data", | |
"png": "iVBORw0KGgoAAAANSUhEUgAAAd8AAAFBCAYAAAA2bKVrAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlYlWX+BvAbUJbD5r7hvqUgIAIiiKCsllmOme1qq1pW\n0/qrHLVszLJmKsdccmqyxrLVypUdUVEUWRRwwV0REQEFZOc8vz+UZwRBQTnve5b7c11clWd5vyc5\n5z7f930WMyGEABERESnGXO0CiIiITA3Dl4iISGEMXy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yIiIoUxfImIiBTG8CUiIlIYw5eIiEhhDF8iIiKFMXyJiIgUxvAlIiJSGMOXiIhIYQxfIiIi\nhTF8iYiIFMbwJSIiUhjDl4iISGEMXyIiIoUxfImIiBTG8CUiIlIYw5eIiEhhDF8iIiKFMXyJiIgU\nxvAlIiJSGMOXiIhIYQxfIiIihTF8iYiIFMbwJSIiUhjDl4iISGEMXyIiIoUxfImIiBTG8CUiIlIY\nw5eIiEhhDF8iIiKFMXyJiIgUxvAlIiJSGMOXiIhIYQxfIiIihTF8iYiIFMbwJSIiUhjDl4iISGEM\nXyIiIoUxfImIiBTG8CUiIlIYw5eIiEhhDF8iIiKFMXyJiIgU9v8Z2q+P83X4FAAAAABJRU5ErkJg\ngg==\n", | |
"text": "<matplotlib.figure.Figure at 0x8700898>" | |
} | |
], | |
"prompt_number": 10 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "#we can display all the subgraphs\nfor subG in G.ConnectedComponents():\n subG.display()", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "display_data", | |
"png": "iVBORw0KGgoAAAANSUhEUgAAAfIAAAFBCAYAAACMzy0LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAC1ZJREFUeJzt3XGM3/Vdx/HX9Wivdz2g3SYhQ7p1Hf4BGmmZA8E4hA0H\nATNmgU3IFiZxpU6XQMgW0GyJurGRhUFC1wUHEzpwGBIbLI4mrmFuMhcJCVEgLN1AQQV1ra13tdz1\nzj+OP+p5hRa5XV/Z45Fc8rv7fL6X9x+Xe+b3/X7vewPT09PTAQAqLVroAQCA107IAaCYkANAMSEH\ngGJCDgDFhBwAigk5ABQTcgAoJuQAUEzIAaCYkANAMSEHgGJCDgDFhBwAigk5ABQTcgAoJuQAUEzI\nAaCYkANAMSEHgGJCDgDFhBwAigk5ABQTcgAoJuQAUEzIAaCYkANAMSEHgGJCDgDFhBwAigk5ABQT\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AaCYkANAMSEHgGJCDgDFhBwAigk5ABQTcgAoJuQAUEzIAaCY\nkANAMSEHgGJCDgDFhBwAigk5ABQTcgAoJuQAUEzIAaCYkANAMSEHgGJCDgDFhBwAigk5ABQTcgAo\nJuQAUEzIAaCYkANAMSEHgGJCDgDFhBwAigk5ABQTcgAoJuQAUEzIAaCYkANAMSEHgGJCDgDFhBwA\nigk5ABQTcgAoJuQAUEzIAaCYkANAMSEHgGJCDgDFhBwAigk5ABQTcgAoJuQAUEzIAaCYkANAMSEH\ngGJCDgDFhBwAiv0PEj23gEZ338kAAAAASUVORK5CYII=\n", | |
"text": "<matplotlib.figure.Figure at 0x8807ba8>" | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "display_data", | |
"png": "iVBORw0KGgoAAAANSUhEUgAAAd8AAAFBCAYAAAA2bKVrAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3XdUFHfbxvEvCygg9t5i71ED2LBhiYox1iigYk3sFTaW\naKJRY0zis6DYsPeuscXexa6AMcbYS+waC4p0dt4/DL7Ggqi7O1vuzzmc54Tdnbl4DnLtb+beGTtF\nURSEEEIIYTIatQMIIYQQtkbKVwghhDAxKV8hhBDCxKR8hRBCCBOT8hVCCCFMTMpXCCGEMDEpXyGE\nEMLEpHyFEEIIE5PyFUIIIUxMylcIIYQwMSlfIYQQwsSkfIUQQggTk/IVQgghTEzKVwghhDAxKV8h\nhBDCxKR8hRBCCBOT8hVCCCFMTMpXCCGEMDEpXyGEEMLEpHyFEEIIE5PyFUIIIUxMylcIIYQwMSlf\nIYQQwsSkfIUQQggTk/IVQgghTEzKVwghhDAxKV8hhBDCxKR8hRBCCBOT8hVCCCFMTMpXCCGEMDEp\nXyGEEMLEpHyFEEIIE5PyFUIIIUzMQe0AQqTFo0ePuH37NrGxsWTJkoX8+fOTLl06tWMJKxMXF8eN\nGzeIiorC1dWVvHnzkjFjRrVjCSsk5SvMll6vZ+fOnUz95R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OmTBljxRNWYvfu3XRr2pTjT5/yLp/UTQYau7jQePRoArRaY8UTNkBWvsKsfDdmDKcKFeJ7B4e3\nfq43xT9AkwwZCBw+XIpXpEmdOnVo4u9PSxcXotP4Gj3QO316lE8+oU+/fsaMJ2yAlK8wKxkzZmTj\nnj2sLVSI7unTcyeV5yrAAaC6iwuf9ezJ4GHDTJRSWDo7OzuCpkyhaPPm1HFx4cRbnn8VaOPszNny\n5f+vnft1iQOM4zj+UctxdyLGA8NYWdXVVeNYFC4MxjAtmUxLhqWrChsD2cC2JghLCzPbhnVlxXQW\nQTAs+BcM4aO41+sveNr7+fHlybeTExP13Jn48uBMJpP8PDvL4tZWng0GmQ6H+ZHbb/7mSX4n+ZRk\nYzzOm8kk7/f382E2y8LCv1xU879bWlrK56OjvN7by8vV1bxYXs5Rbgf3LnP7lHGS5NVolOfDYZ5u\nb+f76WlWVlbudd08Dt58edDm83m+HB7m68FB/lxc5Or6OqvjcTbW1/Nudzebm5tZXLSH5G5ubm5y\nfHycj7NZfp2f5/LqKuPBIE/W1vJ2ZyfT6TSj0ei+l8kjIr4AUObIAABl4gsAZeILAGXiCwBl4gsA\nZeILAGXiCwBl4gsAZeILAGXiCwBl4gsAZeILAGXiCwBl4gsAZeILAGXiCwBl4gsAZeILAGXiCwBl\n4gsAZeILAGXiCwBl4gsAZeILAGXiCwBl4gsAZeILAGXiCwBl4gsAZeILAGXiCwBl4gsAZeILAGXi\nCwBl4gsAZeILAGXiCwBl4gsAZeILAGXiCwBl4gsAZeILAGXiCwBl4gsAZeILAGXiCwBl4gsAZeIL\nAGXiCwBl4gsAZeILAGXiCwBl4gsAZeILAGXiCwBl4gsAZeILAGXiCwBl4gsAZX8BvY6cPmBSH+UA\nAAAASUVORK5CYII=\n", | |
"text": "<matplotlib.figure.Figure at 0x6377208>" | |
} | |
], | |
"prompt_number": 11 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Let's try out the spanning tree algorithms" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "G = WeightedUndirectedGraph()\n#add nodes\nfor i in range(1,7):\n G.AddNode(i)\n#add edges\nG.AddEdge(1,2,10)\nG.AddEdge(1,4,30)\nG.AddEdge(1,5,100)\nG.AddEdge(2,3,50)\nG.AddEdge(3,6,5)\nG.AddEdge(3,5,10)\nG.AddEdge(4,3,20)\nG.AddEdge(4,6,15)\nG.AddEdge(5,4,60)\n\nprint 'G has cycles:', G.HasCycles()\n\nT = G.KruskalsMethod()\nT.display()\nprint 'T has cycles:', T.HasCycles()", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "G has cycles: True\n" | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "display_data", | |
"png": "iVBORw0KGgoAAAANSUhEUgAAAd8AAAFBCAYAAAA2bKVrAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xd0FGX//vH3ppGEIKB0UIqAAqIk9A4iCiIISgkQeu+Q\nKKhYHrHwVdwgKAhKESSCgIJU6b2TBAUpCogFC0oLIQkpO78/Iv4Q6WRndjbX6xzOc9id3b3w5Mm1\n9z2fnXUYhmEgIiIipvGxOoCIiEh2o/IVERExmcpXRETEZCpfERERk6l8RURETKbyFRERMZnKV0RE\nxGQqXxEREZOpfEVEREym8hURETGZyldERMRkKl8RERGTqXxFRERMpvIVERExmcpXRETEZCpfERER\nk6l8RURETKbyFRERMZnKV0RExGQqXxEREZOpfEVEREym8hURETGZyldERMRkKl8RERGTqXxFRERM\npvIVERExmcpXRETEZCpfERERk6l8RURETKbyFRERMZnKV0RExGQqXxEREZOpfEVEREzmZ3UAkRtx\n5swZfv/9d5KTk8mTJw9FixYlICDA6ljiZVJSUjh+/Dhnz54lJCSEwoULkytXLqtjiRdS+YrHcrlc\nrFmzholvv82ajRspnCMHQQ4HpzMyuODrS48+feg9YADFixe3OqrY3MGDB5k0b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iIyVS+IiIiJlP5ioiImEzlKyIi\nYjKVr4iIiMlUviIiIiZT+YqIiJhM5SsiImIyla+IiIjJVL4iIiImU/mKiIiYTOUrIiJiMpWviIiI\nyVS+IiIiJlP5ioiImEzlKyIiYjKVr4iIiMlUviIiIiZT+YqIiJhM5SsiImIyla+IiIjJVL4iIiIm\nU/mKiIiYTOUrIiJisv8HjY0HcOrZvvwAAAAASUVORK5CYII=\n", | |
"text": "<matplotlib.figure.Figure at 0x88367b8>" | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "T has cycles: False\n" | |
} | |
], | |
"prompt_number": 12 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "That's all the algorithms covered in the lecture slides, excluding Solin's and Prim's spanning tree algorithms which only had one slide each.\n\n## Divide and Conquer Algorithms ##\n\nDivide and conquer is a nice paradigm for solving problems. Small problems are solved directly and big problems are just multiple smaller problems. Thus it fits a recursive paradigm very well.\n\n###1 - Finding the min of an unsorted list###\n\nIf the list is size 1, then that element is the min.\nIf the list is bigger, the min is the minimum of the two sub-mins." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "def divide_conquer_min(iterable):\n #base case\n if len(iterable) == 1:\n return iterable[0]\n \n #recursive step\n N = len(iterable)\n m_1,m_2 = divide_conquer_min(iterable[:N/2]), divide_conquer_min(iterable[N/2:])\n return m_1 if m_1 < m_2 else m_2\n\n#let's test it out\nelems = sorted(range(20),key= lambda x: hash(str(x)))\nprint 'list:', elems\nprint 'min of list:', divide_conquer_min(elems)\n", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "list: [3, 4, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 5, 6, 7, 8, 9, 0, 1, 2]\nmin of list: 0\n" | |
} | |
], | |
"prompt_number": 13 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "###2 - Tiling a defective chessboard ###\n\nYeah, I'm not writing code to do this because it's not really a problem which needs to be solved. In case he asks it on the exam, here's the rundown:\n\nA triomino (as opposed to a domino) is three squares making up a right angle. If you have a 2x2 board with one spot missing, you can fill the board with a triomino. This is the direct solution to a small problem.\n\nFor a bigger board, we're going to break it up into four subsquares, but first we need to make them defective so that the subproblems are similar to the big problem. Note that if we divide up the chessboard into four equal sized squares, one of them must have a defective spot - that's how our problem was defined. To make the other three defective, we place a triomino such that it leaves the defective one unchanged and covers one square of the nondefective subboards. Then we cover each recursively.\n\n" | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "###3 - Finding max and min simultaneously###\n\nTrivial extension of the min algorithm" | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "##Side note##\n\nDivide and conquer algorithms form a tree-like structure if you trace the subproblems. In the recursive implementation above, the traversal is similar to that of depth-first-search (using the call stack as a stack). In other words, the algorithm keeps trying to go down the tree until hitting a base case (leaf), and then goes up. We can change the traversal to be similar to breadth-first search by using a queue. Remember the initialization algorithm for leftist trees? It's similar to that. Here's the min algorithm using a breadth first manner, using a queue." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "def BF_min(iterable):\n #initialize the queue\n Q = Queue()\n for i in iterable:\n Q.put(i)\n \n #compute the min\n while not Q.empty():\n #pull two items off\n item1 = Q.get()\n if Q.empty():\n return item1\n item2 = Q.get()\n #put the minimum back in\n Q.put(item1 if item1 < item2 else item2)\n \n\n#let's test it out\nelems = sorted(range(20), key= lambda x: hash(str(x)))\nprint 'list:', elems\nprint 'min of list:', BF_min(elems)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "list: [3, 4, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 5, 6, 7, 8, 9, 0, 1, 2]\nmin of list: 0\n" | |
} | |
], | |
"prompt_number": 14 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "###4 - Merge Sort###\n\nIf a list has one element, it is sorted (base case). If it has more than that, divide it up into two (close to) equal sized sublists and sort those. After, combine the sorted lists." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "def merge(L_1, L_2):\n final = []\n while len(L_1) > 0 or len(L_2) > 0:\n #we take from L_1 if L_2 is empty or L_1's first element is smaller\n if len(L_2) == 0 or L_1[0] < L_2[0]:\n final.append(L_1[0])\n #check if we're done\n if len(L_1) == 1:\n final.extend(L_2)\n return final\n L_1 = L_1[1:]\n else:\n final.append(L_2[0])\n #check if we're done\n if len(L_2) == 1:\n final.extend(L_1)\n return final\n L_2 = L_2[1:]\n\ndef merge_sort(iterable):\n #base case\n if len(iterable) <= 1:\n return iterable\n \n #recursive step\n N = len(iterable)\n L_1, L_2 = merge_sort(iterable[:N/2]), merge_sort(iterable[N/2:])\n \n #combine the two lists\n return merge(L_1, L_2)\n\n#let's test it out\nelems = sorted(range(20), key= lambda x: hash(str(x)))\nprint 'list:', elems\nprint 'sorted list', merge_sort(elems)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "list: [3, 4, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 5, 6, 7, 8, 9, 0, 1, 2]\nsorted list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n" | |
} | |
], | |
"prompt_number": 15 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "###5 - Non recursive merge sort###\n\nJust use the queue idea from earlier, starting as singleton lists." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "def nonrecursive_merge_sort(iterable):\n #initialize the queue\n Q = Queue()\n for i in iterable:\n Q.put([i]) #singleton lists\n \n #pull off two lists, merge, and put back in queue\n while not Q.empty():\n #pull two items off\n L_1 = Q.get()\n if Q.empty():\n return L_1\n L_2 = Q.get()\n \n #merge and put\n Q.put(merge(L_1, L_2))\n\n#let's test it out\nelems = sorted(range(20), key= lambda x: hash(str(x)))\nprint 'list:', elems\nprint 'sorted list', nonrecursive_merge_sort(elems)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "list: [3, 4, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 5, 6, 7, 8, 9, 0, 1, 2]\nsorted list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n" | |
} | |
], | |
"prompt_number": 16 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Easy enough.\n\n###6 - Natural Merge Sort###\n\nThe goal of natural merge sort is to not mess up any parts of the lists which are already in order. Instead of starting at singleton lists, we start with sublists which are already sorted.\n\n" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "def natural_merge_sort(iterable):\n #initialize the queue\n Q = Queue()\n #add already sorted sublists\n sublist = [iterable[0]]\n for i in range(len(iterable)-1):\n if iterable[i+1] >= iterable[i]:\n sublist.append(iterable[i+1])\n else:\n Q.put(sublist)\n sublist = [iterable[i+1]]\n Q.put(sublist)\n \n #to see what it's doing\n qlist = [sublist for sublist in list(Q.queue)]\n print 'the queue:\\n', qlist\n print 'sorted list:'\n #pull off two lists, merge, and put back in queue\n while not Q.empty():\n #pull two items off\n L_1 = Q.get()\n if Q.empty():\n return L_1\n L_2 = Q.get()\n \n #merge and put\n Q.put(merge(L_1, L_2))\n\n#let's test it out\nelems = sorted(range(20), key= lambda x: hash(str(x)))\nprint 'list:', elems\nprint natural_merge_sort(elems)\n", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "list: [3, 4, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 5, 6, 7, 8, 9, 0, 1, 2]\nthe queue:\n[[3, 4, 11], [10, 13], [12, 15], [14, 17], [16, 19], [18], [5, 6, 7, 8, 9], [0, 1, 2]]\nsorted list:\n[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n" | |
} | |
], | |
"prompt_number": 17 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "I added some code to print the queue before doing the merge sort - it shows how subgroups were formed of elements which were already ordered." | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "###7 - Quick Sort###\n\nBase case: a list of size 1 is sorted. \n\nRecursive step: select a pivot, left group, right group. All elements of the left group are less than the pivot, and all elements of the right group are greater than the pivot. Quick sort each subgroup, then arrange in order: left, pivot, right.\n\n" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "def quicksort(iterable):\n #this is the base case\n if len(iterable) <= 1:\n return iterable\n \n #choose a pivot\n N = len(iterable)\n pivotInd = N/2\n pivot = iterable[pivotInd] #or iterable[0], whatever you feel like doing.\n \n #divide up the list\n left, right = [], []\n for i,item in enumerate(iterable):\n if item <= pivot and i!=pivotInd:\n left.append(item)\n elif item > pivot:\n right.append(item)\n \n #sort each half\n left,right = quicksort(left), quicksort(right)\n \n #combine\n return left + [pivot] + right \n\nelems = sorted(range(20), key= lambda x: hash(str(x)))\nprint 'list:', elems\nprint 'sorted list', quicksort(elems)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "list: [3, 4, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 5, 6, 7, 8, 9, 0, 1, 2]\nsorted list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n" | |
} | |
], | |
"prompt_number": 29 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "###8 - Quick sort in-place ###\n\nIt will be more messy, but we can also do quick sort in place. Let's first figure out an algorithm for in-place partitioning. This will need to take a list, a left bound (a) and a right bound (b), select a pivot and put everything less than the pivot to the left, and everything greater than the pivot to the right." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "#see slides\ndef in_place_partition(iterable, a, b):\n #you can use whatever scheme for picking the pivot\n pivot = iterable[a]\n #bounds on our processing\n left = a\n right = b\n \n #quit once we have crossover\n while left < right:\n \n #starting at the left, advance toward the pivot until we find a violator\n while iterable[left] <= pivot:\n left += 1\n #starting at the right, advance toward the pivot until we find a violator\n while iterable[right] > pivot:\n right -= 1\n #we found violators on both sides - swap them.\n if (left < right):\n iterable[left],iterable[right] = iterable[right],iterable[left]\n \n #put the pivot in the middle of the list\n iterable[a] = iterable[right]\n iterable[right] = pivot\n return iterable, right\n\nin_place_partition([5,6,2,1,5,1,4],0,6)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 19, | |
"text": "([1, 4, 2, 1, 5, 5, 6], 5)" | |
} | |
], | |
"prompt_number": 19 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "That was the hard part; now the quicksort algorithm is pretty easy." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "def inplace_quicksort(iterable, a=None,b=None):\n #a is the start and b is the end.\n a = 0 if a is None else a\n b = len(iterable) if b is None else b\n \n #base case: b=a+1, or a list of 1 element\n if b<=a+1:\n return iterable\n \n #recursive step: partition the list (in place)\n iterable, pivotInd = in_place_partition(iterable, a, b-1) #inclusive\n \n #sort halves in place\n iterable = inplace_quicksort(iterable, a, pivotInd)\n iterable = inplace_quicksort(iterable, pivotInd+1, b)\n return iterable\n\nelems = sorted(range(20), key= lambda x: hash(str(x)))\nprint 'list:', elems\nprint 'sorted list', inplace_quicksort(elems)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "list: [3, 4, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 5, 6, 7, 8, 9, 0, 1, 2]\nsorted list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n" | |
} | |
], | |
"prompt_number": 34 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "###9 - Rank finding###\n\nThe idea here is given an unsorted list, we want to find the k-th smallest element. The algorithm we use is a blend of indexed BST searching with quicksort. \n\nBase Case: list has one element - return it\n\nRecursive step: Pick a pivot, put everything smaller than the pivot to the left, and everything larger to the right. If the index of the pivot is equal to K, then we're done (return the pivot). If it's less, call kth_smallest(left,k). If it's greater, call kth_smallest(right, k=k-len(left)-1). Thus on average we can eliminate half the list at each step and solve this in O(n).\n" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "def kth_smallest(iterable, k):\n N = len(iterable)\n #base case: list has one element\n if N == 1:\n return iterable\n \n #recursive step - choose a pivot, make left and right lists\n \n pivot_ind, pivot = N/2, iterable[N/2]\n left = [item for i,item in enumerate(iterable) if item <= pivot and i!=pivot_ind]\n if k == len(left):\n #the kth largest is the pivot!\n return pivot\n if k < len(left):\n return kth_smallest(left, k)\n if k > len(left):\n right = [item for i,item in enumerate(iterable) if item > pivot and i!=pivot_ind] \n return kth_smallest(right, k-len(left)-1)\n \nelems = sorted(range(20), key= lambda x: hash(str(x)))\nprint 'list:', elems\nprint '1st smallest (index 1 if it were sorted)', kth_smallest(elems,k=1)\nprint 'median:', kth_smallest(elems, k=len(elems)/2)\nprint 'using O(nlogn) algorithm:', quicksort(elems)[len(elems)/2]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "list: [3, 4, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 5, 6, 7, 8, 9, 0, 1, 2]\n1st smallest (index 1 if it were sorted) 1\nmedian: 10\nusing O(nlogn) algorithm: 10\n" | |
} | |
], | |
"prompt_number": 31 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "###10 - Closest pair of points###\n\nThe goal here is: given a set of points in the plane, find the pair which are closest. Let's generate some points:\n" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "xvals = uniform(-1,1,(10))\nyvals = uniform(-1,1,(10))\npairs = [(x,y) for x,y in zip(xvals,yvals)]\nscatter(xvals, yvals)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 35, | |
"text": "<matplotlib.collections.PathCollection at 0x8700358>" | |
}, | |
{ | |
"metadata": {}, | |
"output_type": "display_data", | |
"png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEACAYAAAC08h1NAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFUtJREFUeJzt3X1Q1PeBx/HPCijgA2hiUIEcCWBQg1tyJMZ2bPFhQ8Rz\nY3qNkJo7mqSptbV2nFyah5tctTVGJ3245LjmQTsO9hpja1SwIjVpus0lSrhEJ20GW4HUBIgSFTEq\nASJ+749afALB/cH+gO/7NbMz7O539/fJd39+8pvv7m/XY4wxAgBYY5DbAQAAoUXxA4BlKH4AsAzF\nDwCWofgBwDIUPwBYxnHx33fffYqLi1N6enqnY5YsWaLU1FR5vV7t3bvX6SYBAA44Lv57771XpaWl\nnd5fUlKiqqoqVVZW6oUXXtCiRYucbhIA4IDj4p82bZpGjhzZ6f3FxcXKz8+XJE2ZMkWNjY2qr693\nulkAQJB6fY2/rq5OiYmJ7dcTEhJUW1vb25sFAHQiJG/uXvytEB6PJxSbBQB0ILy3NxAfH6+ampr2\n67W1tYqPj79kXEpKiqqrq3s7DgAMKMnJyaqqqrqix/T6Eb/f79f69eslSWVlZYqNjVVcXNwl46qr\nq2WM4WKMvv/977ueoa9cmAvmgrm4/CWYA2bHR/x33323/vCHP+jIkSNKTEz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mL+vr69n8z5eXlMsZYV/pSkPtET7zr\nHIzNmzebhIQEExkZaeLi4sztt99ujDGmrq7O5OTkGGOMqa6uNl6v13i9XjNp0iSzcuVKt+L2mu7M\ngzHGlJSUmPHjx5vk5OQBOQ/GGHP06FEzc+ZMk5qaanw+nzl27Jgxxq59oqPX+bnnnjPPPfdc+5hv\nf/vbJjk52UyePPmyn4jr77qai4KCAjNp0iTj9XrN1KlTze7du92M22vy8vLM2LFjTUREhElISDA/\n//nPHe8TnMAFAJbpE0s9AIDQofgBwDIUPwBYhuIHAMtQ/ABgGYofACxD8QOAZSh+ALDM/wOZ+bQa\nGjdMrwAAAABJRU5ErkJggg==\n", | |
"text": "<matplotlib.figure.Figure at 0x62c0438>" | |
} | |
], | |
"prompt_number": 35 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "And here's the algorithm:\n\nBase case: the plane has 2 points - those are the closest pair.\n\nRecursive step: sort all the pairs by x-coordinate. Split the plane in half, solve each half. If $d$ is the minimum distance for both subproblems, then look at points within $d$ of the split line. In this set of points, find the smallest pair where one lies in the left and the other lies in the right. Return the minimum of $d$ with the distance of the pair we just found.\n\n" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "def dist(point1, point2):\n return (point1[0]-point2[0])**2 + (point1[1]-point2[1])**2\n\ndef closest_pair(points, sort=True):\n \"\"\"\n Finds the closest pair of points using divide and conquer.\n Returns: point1, point2, distance\n \"\"\"\n #base case\n if len(points) == 2:\n return points[0],points[1],dist(points[0],points[1])\n elif len(points) == 1:\n return points[0],(0,0), sys.maxint\n elif len(points) == 0:\n return (0,0),(0,0),sys.maxint\n \n #sort (once) by x-coord\n if sort:\n points = sorted(points, key= lambda x: x[0])\n sort=False\n \n #divide into subproblems\n N = len(points)\n leftpoints = points[:N/2]\n rightpoints = points[N/2:]\n \n left_p1,left_p2,left_d = closest_pair(leftpoints, False)\n right_p1, right_p2,right_d = closest_pair(rightpoints, False)\n \n #compute minimum distance of the two\n if left_d <= right_d:\n d = left_d\n p1,p2 = left_p1, left_p2\n else:\n d = right_d\n p1,p2 = right_p1, right_p2\n \n #grab points within d of the split\n #**could be done more efficiently**\n leftmidpoints = [point for point in leftpoints if dist(point, points[N/2]) < d]\n rightmidpoints = [point for point in rightpoints if dist(point, points[N/2]) < d]\n \n #get pairs where one is in each half\n for lcandidate in leftmidpoints:\n for i,rcandidate in enumerate(rightmidpoints):\n if i == 6: break #max number of evals needed\n di = dist(lcandidate, rcandidate)\n if di <= d:\n d = di\n p1,p2 = lcandidate, rcandidate\n \n return p1, p2, d\n \np1,p2,dist = closest_pair(pairs)\nscatter(xvals, yvals, color='b')\nscatter([p1[0],p2[0]],[p1[1],p2[1]], color='r')\nshow()\nprint 'dist between red points:', dist", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "display_data", | |
"png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEACAYAAAC08h1NAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAE+1JREFUeJzt3X9w1PWdx/HXlyQYwq+Ap0tIchdNQpMi7IWLot7QRmGl\nhGEbO46k1WlGmZZiGWbuOj3sdHqFDiJc2z/ayVxVruVCp0UqKsQSUtS6dRRippBxphMsCRZNIuyB\nEAcJEIif+2NrQkxCNvvd7DfZz/Mxs0O+u5/vft989ssrHz7fH+sYY4wAANaY4HUBAIDEIvgBwDIE\nPwBYhuAHAMsQ/ABgGYIfACzjOvgfffRR+Xw+zZs3b8g269atU2Fhofx+v5qamtxuEgDgguvgf+SR\nR1RfXz/k63V1dWptbVVLS4ueeeYZrVmzxu0mAQAuuA7+RYsWacaMGUO+Xltbq6qqKknSwoUL1dnZ\nqXA47HazAIAYjfocf0dHh3Jzc3uXc3Jy1N7ePtqbBQAMISEHdz97VwjHcRKxWQDAIFJHewPZ2dlq\na2vrXW5vb1d2dvaAdgUFBTp+/PholwMASSU/P1+tra0jWmfU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\n", | |
"text": "<matplotlib.figure.Figure at 0x8822668>" | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "dist between red points: 0.0130980124457\n" | |
} | |
], | |
"prompt_number": 41 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "###11 - Greedy Knapsack Problem###\n\nThere's a nice dynamic programming solution to this problem, but we didn't get there. This solution is greedy on profit density, $\\frac{p_i}{w_i}$, which is just profit normalized by weight.\n\nGiven a value for K, which is the initial subset size, the algorithm is:\n\nFor all possible subsets of size <= K,\n\n fill knapsack by being greedy on profit density\n \n if solution is better than previous best, update best.\n \nreturn best\n\n\n" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "import itertools as it\ndef greedy_profit_density(capacity, profits, weights, K):\n \n assert len(profits) == len(weights), 'profits and weights must be parallel arrays!'\n \n #pdensity holds pairs of (profit density, item), ordered by profit density ascending\n pdensity = sorted([(p/w,i) for p,w,i in zip(profits,weights,range(len(weights)))],\n key = lambda x: x[0])\n bestprofit = 0\n bestknapsack = []\n \n for i in range(1,K+1): #for i = 0 up to K (inclusive)\n for initialset in it.combinations(range(len(profits)),i):\n knapsack = list(initialset)\n\n #if we're overpacked, then this is a bad combination\n currentcapacity = sum(weights[item] for item in initialset)\n if currentcapacity > capacity:\n break\n \n candidates = [pair for pair in pdensity if pair[1] not in initialset]\n currentitem = -1 #start at best profit density\n \n #pack to capacity using a greedy method on profit density\n while True:\n nextitem = pdensity[currentitem][1]\n if nextitem in knapsack:\n currentitem -= 1\n continue\n \n if currentcapacity + weights[nextitem] <= capacity:\n #we can fit the next item. pack her up\n knapsack.append(pdensity[currentitem][1])\n currentcapacity += weights[pdensity[currentitem][1]]\n currentitem -= 1\n else:\n #done packing\n break\n \n currentprofit = sum(profits[item] for item in knapsack)\n if currentprofit > bestprofit:\n bestprofit = currentprofit\n bestknapsack = knapsack\n \n return bestknapsack, bestprofit\n \nprofits = [2.,10.]\nweights = [3.,6.]\ncapacity= 7\nprint greedy_profit_density(capacity, profits, weights, K=1)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "([1], 10.0)\n" | |
} | |
], | |
"prompt_number": 56 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "profits = [10.,8.,6.]\nweights = [7.,3.,2.]\ncapacity= 7\nprint greedy_profit_density(capacity, profits, weights, K=1)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "([1, 2], 14.0)\n([1, 2], 14.0)\n" | |
} | |
], | |
"prompt_number": 58 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Well, that was fun." | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "# Old material #\n\nLet's do some old material in case it appears on the exam.\n\n### LZW compression ###\n\nIn LZW compression, we take advantage of the fact that text (data) usually doesn't have maximum entropy. In other words, it's not totally random and there are repeated parts. To exploit this, we build up a code table based on the text in such a way that it can be reconstructed after transmission without sending the code table. (Lossless compression).\n\nLet's try implementing it, limiting the messages to lowercase letters, and compressing it as integers." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "#alphabet = 'abcdefghijklmnopqrstuvwxyz'\nalphabet = 'ab'\n\ndef encode_LZW(string):\n #start each letter with an integer\n table = {letter:i for i,letter in enumerate(alphabet)}\n nextint = len(alphabet)\n \n encoded = []\n start = 0\n #scan from left to right\n while start < len(string):\n \n #find longest prefix which is in the table\n for end in range(start+1, len(string)+1):\n\n if end==len(string):\n #encode what's left\n encoded.append( table[ string[start:end] ] )\n return encoded\n \n #if it's not in the table, add it and encode the previous prefix\n if string[start:end] not in table:\n \n #add current prefix to table\n table[ string[start:end] ] = nextint\n nextint += 1\n \n #encode previous prefix\n encoded.append( table[ string[start:end-1] ] )\n start = end-1\n break\n \n return encoded\n\nprint encode_LZW('abababbabaabbabbaabba')", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "[0, 1, 2, 2, 3, 3, 5, 8, 8]\n" | |
} | |
], | |
"prompt_number": 80 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Now we just need to write a decompressor!\n" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "def decode_LZW(encoded):\n #start with our initial table, but reversed\n table = {i:letter for i,letter in enumerate(alphabet)}\n nextint = len(alphabet)\n decoded = []\n start = 0\n\n #scan from left to right\n for start in range(len(string)):\n #read value\n current = string[start]\n \n #decode\n decoded.append( current )\n \n #add to dictionary the string just output and the \n #first char of the next string\n if start != len(string)-1:\n \n #first char of next\n first_ch = table[ start + 1 ][0]\n \n #add to dict\n table[ nextint ] = current + first_ch\n nextint += 1\n \n return ''.join(decoded)\n\nstring = 'abababbabaabbabbaabba'\nprint 'encoded as: ', encode_LZW( string )\nprint 'when decoded:', decode_LZW( encode_LZW( string) )\nassert decode_LZW( encode_LZW( string ) ) == string, 'error'\nprint 'theyre equal!'", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "encoded as: [0, 1, 2, 2, 3, 3, 5, 8, 8]\nwhen decoded: abababbabaabbabbaabba\ntheyre equal!\n" | |
} | |
], | |
"prompt_number": 95 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Since I went through all that effort to write LZW, let's encode some things!" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "string = \"What the fuck did you just fucking say about me, you little bitch? I\u2019ll have you know I graduated top of my class in the Navy Seals, and I\u2019ve been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and I\u2019m the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. You\u2019re fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that\u2019s just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the United States Marine Corps and I will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. If only you could have known what unholy retribution your little \u201cclever\u201d comment was about to bring down upon you, maybe you would have held your fucking tongue. But you couldn\u2019t, you didn\u2019t, and now you\u2019re paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. You\u2019re fucking dead, kiddo\"\nstring = string.lower()\nalphabet = set(char for char in string)\nencoded = encode_LZW(string)\nprint 'the original string was:', len(string), 'chars long, the compressed was:', len(encoded), 'ints long.\\n\\n'\n\nprint 'decoded:', decode_LZW(encoded), '\\n\\n'\nprint 'encoded:', ''.join(str(i) for i in encode_LZW(string))", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "the original string was: 1537 chars long, the compressed was: 752 ints long.\n\n\ndecoded: " | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "what the fuck did you just fucking say about me, you little bitch? i\u2019ll have you know i graduated top of my class in the navy seals, and i\u2019ve been involved in numerous secret raids on al-quaeda, and i have over 300 confirmed kills. i am trained in gorilla warfare and i\u2019m the top sniper in the entire us armed forces. you are nothing to me but just another target. i will wipe you the fuck out with precision the likes of which has never been seen before on this earth, mark my fucking words. you think you can get away with saying that shit to me over the internet? think again, fucker. as we speak i am contacting my secret network of spies across the usa and your ip is being traced right now so you better prepare for the storm, maggot. the storm that wipes out the pathetic little thing you call your life. you\u2019re fucking dead, kid. i can be anywhere, anytime, and i can kill you in over seven hundred ways, and that\u2019s just with my bare hands. not only am i extensively trained in unarmed combat, but i have access to the entire arsenal of the united states marine corps and i will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. if only you could have known what unholy retribution your little \u201cclever\u201d comment was about to bring down upon you, maybe you would have held your fucking tongue. but you couldn\u2019t, you didn\u2019t, and now you\u2019re paying the price, you goddamn idiot. i will shit fury all over you and you will drown in it. you\u2019re fucking dead, kiddo \n\n\nencoded: 3320123243220154183113214161916435253142231294046481926174291235412145640231565456424193232244414841320104191101242443834445557212625339441730121631391553322528425184237113241229299426414342612347129151224297912265395971034141515136653425241031521362631773056134144133015401145213425136146527117119121491511111024425103304988413182181930775321199929711112234117926119135112253021113143312301823044150152961217424412112329261928151976513744159322064460722072211822413152138057233139254265671211278831405961721082401973223017177214192282262912472662514547497529142428176131929191822968321264124126371991101132139151961561581361441593252611761241362711341453042792323049128297646622822416265105137654935213150112177722297133842068702721373968208441252751243242401353224822032932712649121712657963313302143213344292471249290216202182285132543473441741764038433224299126402193141217525133296601228153105249123307325369321142635322517204171096837635215785248303176282683312966122423340390172702143804622073704036424718127729645824025413828486241373347356146100435484181521410523733239536916145167921016289202358157281353724878513254771901525101362109929525019545514410313620311511765336214843347323713427947436512771142683815126528233324714072901536382263081035572183922201664535230208408235503279144782901937213263429274380253255258144140100125430245382536111813434122522040830281342351113645266044374274841344652656156340274475104561972330724873877242912512638023226331529620326412253793528385636293733228912618256735656245358410710913637371535201637141622558125431049365248649631303232489625767764722832173300274146066716668572286805646535512352419316643201554371549350134712166314961564786627141626237579295517317335212691104989733245835440138304318517352467161621616051468613292655374463055852652919735261271229216171331601606572664994472170250450652703\n" | |
} | |
], | |
"prompt_number": 112 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Fun stuff. " | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "### Hash Table ###\n\nThere are two components to a hash table: \n\n1. a function mapping objects to an index\n2. a way to handle collisions\n\nLet's build a hash table for strings. To hash (convert to int) a string, I'll do some bitwise operations based on the ordinal values of each character. Hopefully if it's complicated enough, the values will spread out sorta uniformly." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "# def strhash(string):\n# value = 19\n# for ch in string:\n# value = value * 31 * ord(ch) + 1\n# return value / 3\n\nprint strhash('aaple')\nprint strhash('AAPL')\nprint strhash('u wot m8')\nprint strhash('orange')", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "2084275098019360008\n150252173586812\n6052857895987282548361784117\n7895143023514566094618\n" | |
} | |
], | |
"prompt_number": 142 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Seems legit. Now let's make the hash table" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "class HashTable(object):\n \n def __init__(self):\n self.items = [ [] for i in range(10)]\n self.itemcount = 0\n \n def __getitem__(self, obj):\n #hash, modulus, retrieve\n code = self.strhash(obj)\n ind = code % len(self.items)\n \n if len(self.items[ind]) == 0:\n print 'That item is not in the hash table'\n return\n else:\n #we have more than one item in that bucket.\n #go through until we hit ours\n return next(val for (key,val) in self.items[ind] if self.strhash(key) == code)\n \n def double_and_rehash(self):\n olditems = self.items[::]\n newitems = [[] for i in range(2*len(self.items))] #double size\n self.items = newitems\n for bucket in olditems:\n for key,value in bucket:\n self.__setitem__(key, value) #re-add to the new, doubled length, array\n \n def __setitem__(self, key, value):\n #add item to table\n code = self.strhash(key)\n ind = code%len(self.items)\n self.items[ind].append((key,value))\n self.itemcount += 1\n \n #if we are over capacity, then we need to resize the array and rehash everybody\n if self.itemcount > len(self.items) * 3 / 4:\n self.double_and_rehash()\n \n \n def strhash(self, string):\n value = 19\n for ch in string:\n value = value + 2**ord(ch) / 7\n return value / 3", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 152 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "h = HashTable()\nh['two leggers'] = 'suck'\nh['selfies'] = 'only on saturday'\nh['$wag'] = 'if you beliebe'\nprint h.items\nprint 'two leggers', h['two leggers']", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "[[], [], [], [('selfies', 'only on saturday')], [('$wag', 'if you beliebe')], [], [('two leggers', 'suck')], [], [], []]\ntwo leggers suck\n" | |
} | |
], | |
"prompt_number": 153 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment