Skip to content

Instantly share code, notes, and snippets.

View lukeneil's full-sized avatar

Luke Neilson lukeneil

View GitHub Profile
# Merging a list of sorted lists
#
# O(N log N) best/avg/worst time complexity
# Requires O(N) extra space for copying
def merge(list_of_lists):
if len(list_of_lists) == 0:
return []
elif len(list_of_lists) == 1:
return list_of_lists[0]
# Bucket helper class as used by HashTable
class Bucket:
def __init__(self, key, val, next_bucket = None):
self.key = key
self.val = val
self.next = next_bucket
# A simple HashTable for storing & retrieving (k, v) pairs
# Implementation details:
# * Assumes the key is a string