Author: Gabriel Meringolo, Marco Zangari
Sample code for classic data structures and sorting algorithms
radix_sort(list)
Big O runtime: O(kn)
from graph_1 import Graph
g = Graph()
Big O runtime: O(1)
g.add_node(1)
Big O runtime: O(1)
g.add_edge(1, 2)
Big O runtime: O(1)
g.nodes()
[1, 2]
Big O runtime: O(1)
g.edges()
[(1, 2)]
Big O runtime: O(n**2)
g.del_node(1)
Big O runtime: O(n**2)
g.del_edge((1, 2))
Big O runtime: O(n**2)
g.has_node(1)
True
Big O runtime: O(1)
g.neighbors(1)
[2, 3, 4]
Big O runtime: O(1)
g.adjacent((1, 7))
False
Big O runtime: O(1)
g.breadth_first_traversal(1)
[1, 2, 3, 4, 5]
Big O runtime: O(n)
g.breadth_first_traversal(1)
[1, 2, 5, 3, 5]
Big O runtime: O(nk)
from priority_que import Priorityq
pq = Priorityq()
Big O runtime: O(1)
pq.insert(2,3)
Big O runtime: O(1)
pq.peek()
Big O runtime: O(n)
pq.pop()
Big O runtime: O(n)
from max_heap import MaxHeap
mh = MaxHeap()
Big O runtime: O(1)
mh.push(1)
Big O runtime: O(log n)
mh.pop()
Big O runtime: O(log n)
from deque import Deque
dq = Deque()
Big O runtime: O(1)
dq.append('one')
Big O runtime: O(1)
dq.append('one')
Big O runtime: O(1)
dq.pop()
Big O runtime: O(1)
dq.popleft()
Big O runtime: O(1)
dq.peek()
dq.peekleft()
Big O runtime: O(1)
dq.size()
Big O runtime: O(1)
from que_ import Queue
q = Queue()
Big O runtime: O(1)
q.enqueue('one')
Big O runtime: O(1)
q.dequeue()
Big O runtime: O(1)
q.peek()
Big O runtime: O(1)
q.size()
Big O runtime: O(1)
len(q)
Big O runtime: O(1)
from doubly_linked_list import DoublyLinKedList
dll = DoublyLinkedList()
Big O runtime = O(1)
dll.push('one')
Big O runtime = O(1)
dll.append('one')
Big O runtime = O(1)
ll.pop()
Big O runtime = O(1)
ll.shift()
Big O runtime = O(1)
ll.remove('one')
Big O runtime = O(n)
from stack import Stack
stck = Stack()
Big O runtime: O(1)
stck.push('one')
Big O runtime: O(1)
stck.pop()
Big O runtime: O(1)
len(stck)
Big O runtime: O(1)
from linked_list import LinkedList
ll = LinkedList()
Big O runtime: O(1)
ll.push('one')
Big O runtime: O(1)
ll.pop()
'one'
Big O runtime: O(1)
ll.push('one')
len(ll)
1
Big O runtime: O(1)
ll.search('one')
<linked_list.Node at 0x106b6ce10>
Big O runtime: O(n)
node = ll.search('one')
ll.remove(node)
Big O runtime: O(n)
ll.push('one')
ll.push('two')
ll.push('three')
ll.display()
"('one', 'two', 'three')"
Big O runtime: O(n)
Written in python, tested with pytest and tox.