final Flashcards

1
Q

mapping ADT

A

refers to items by a key rather than their index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

hashing

A

a hash function converts a key to an index; try f(x) = x % (# of keys)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

hash collision

A

keys hash to the same integer, potentially overwriting existing values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

runtime: mapping with mod hashing

A

put - O(n); get - O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

load factor

A

values hash function produces / entries currently in table;
capacity / entries;
minimal empty slots

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

runtime: mapping with rehashing

A

put - O(1); get - O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

mapping with dictionaries

A

dictionaries support O(1) for put and get, regardless of n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

only immutable built-ins can be keys, meaning:

A

only tuples and strings can be keys

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

sets

A

cannot be hashed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

tree

A

hierarchal collection of nodes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

root

A

top node of a tree

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

children

A

any node with a node above it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

parent

A

any node with a node below it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

edge

A

connections between two vertices; connect nodes in a graph

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

path

A

series of edges connecting two nodes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

path length

A

number of edges in a path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

depth

A

length of path from a node to the root

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

height

A

maximum depth of any node in a tree

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

descendants

A

all nodes for which there is a path from x’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

ancestors

A

all nodes which x is a descendant of

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

subtree

A

node x and its descendents; where x is not the parent node of the original tree

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

binary tree

A

nodes of a graph;
often stored as a set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

binary search tree

A

binary tree where all the descendants to the left are less and all the descendants to the right are greater

24
Q

graph - mathematic

A

a set of vertices V and a set of edges E: G(V, E)

25
vertices
nodes of a graph; oftern stored as a set
26
weighted edges
has a specific value, more or less than other edges
27
directed edges
an edge that points one way, signaling that inforation is carried in that direction
28
edge set - {(x, y)}
signals that x is connected to y, but not vice versa; x-y edge is directional
29
undirected edges
a path between two vertices; works in all directions
30
path
a set of vertices connected by edges; can get from edge a to edge d by edges b and c and the vertices in between
31
cycles
a path where v(0) = v(n); a path that can go in a circle
32
avoiding cycles
memoization
33
two nodes are connected if
there is a path between them
34
graph data structure: edge set
stores a set of vertices and a set of edges
35
graph data structure: adjacency set
stores a set of vertices and a dictionary of neighbors
36
EdgeSet: add_vertex(self, v):
self.V.add(v)
37
EdgeSet: add_edge(self, e):
self.E.add(e)
38
inheritance
class Class1(Class2): pass; Class1 inherits attributes and functions of Class2
39
remove_vertex(self,v):
self.V.remove(v)
40
remove_edge(self, e):
self.E.remove(e)
41
EdgeSet: __iter__(self):
return iter(self.V)
42
_neighbors(self, v):
nbrs = set(); for e in self.E: >if e[0] == v: nbrs.add(e[1]); return nbrs; new set to store new vertex' neighbors; if the source of the edge is v, add v to the dict as a destination
43
class AdjacencySet:
initialize with empty set of vertices, empty dict of neighbors; v = set() neighbors = dict()
44
Adjacency set
set for vertices, dictionary for edges; each vertex is a key, value is all neighbors
45
AdjacencySet: add_vertex
self.V.add(V)
46
AdjacencySet: remove_vertex
self.V.remove(V)
47
AdjacencySet: add_edge(self, e):
a, b = e; if a not in self.nbrs: self.nbrs[a] = {b}; else: self.nbrs[a].add(b); check if in dict.neighbors. else; add to neighbors
48
AdjacencySet: remove_edge:
a, b = e; self.nbrs[a].remove(b); if len(self.nbrs[a]) == 0: self.nbrs.pop(a)
49
AdjacencySet: _neighbors:
return iter(self.nbrs[v])
50
degree of a vertex
edges connected to that vertex
51
simple graph
don't self-loop, no multi-edges
52
breadth first search
begins at a source node, inspects neighboring nodes; inspects neighbors' neighbors, etc; queue of nodes in order of first explored, sorted lowest-first
53
depth first search
recursively explore one part before going back to the other, unexplored ones; stack of previously explored nodes, noting what can be explored in x many steps; sorted how the neighbors are stored/visited
54
guaranteed to find a path, not necessarily shortest
DFS
55
useful for exploring graphs + finding connected components
DFS
56
guaranteed to find a path, shortest
BFS