class Node(object):
def __init__(self, data=None, next_node=None):
self.data = data
self.next_node = next_node
def get_data(self):
return self.data
def get_next(self):
return self.next_node
def set_next(self, new_next):
self.next_node = new_next
myObject = { key : value,
key : value,
key : value }
We're going to determine the time complexity of some operations on hash maps.
looking up a value based on a key
phone_book = {'wong': 4098, 'scott': 4139}
phone_book['wong']
O(1) - Constant
O(n) - Linear
O(logn) - Logarithmic
Adding or removing a pair
phone_book = {'wong': 4098, 'scott': 4139}
phone_book['cooper'] = 6802
O(1) - Constant
O(n) - Linear
O(n2) - Quadratic
Looping over the set
phone_book = {'wong': 4098, 'scott': 4139}
for name, num in phone_book.items()
print name
O(1) - Constant
O(n) - Linear
O(n2) - Quadratic
Time - O(n)
Space - O(1)
A method to solving problems where the solution depends on smaller forms of the same problem.
Solve part of the problem, and then combine that with the solution to the rest of the problem.
This varies a lot between organizations, interviewers and problems.
Let's pick a problem as a class and one of the TAs can mock interview me.