Joseph C. Osborn
CSCI 051a PO
November 26, 2019
next_states
implement algorithms
def dfs(...)
is some code implementing it\[O(n)\]
“To find an element in some list, compare the element against each element of the list. If it compares equal to any element return true, otherwise return false.”
def member(element, some_list): pass
def member(element, some_list): for elt in some_list: if elt == element: return True return False
member
function is called with longer and longer lists…member
?member
for worst-case performancemap
and filter
?
def map(a_fn, a_list): ret = [] for elt in a_list: ret.append(a_fn(elt)) return ret def filter(a_fn, a_list); ret = [] for elt in a_list: if a_fn(elt): ret.append(elt) return ret