CIS 1210 TA Review

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/104

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:01 PM on 4/29/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

105 Terms

1
New cards

Definition of matching GS alg

a subset S of ordered pairs in M × W such that each member of M and each member of W appears in at most one pair in S

2
New cards

Def of perfect matching GS alg

it is a matching and has the property that each member of M and each member of W appears in exactly one pair of S’

3
New cards

What does it mean for pair (m, w’) to be called an instability wrt matching S in GS alg?

(m, w’) does not belong to S, but each of m and w’ prefers the other to their partner in S

4
New cards

When is a matching stable GS alg?

1. it is perfect 2. there are no instabilities with respect to S

5
New cards

In GS, each man proposing is matched with his _________ valid partner and each woman is matched with her __________ valid partner.

best, words

6
New cards

What is a valid partner mean in GS alg?

A woman w is a valid partner of a man m if there is a stable matching that contains the pair (m, w)

7
New cards

What is POC method for insertion sort?

Initialization, maintenance, & termination

8
New cards

Definition. O-notation

9
New cards

Definition. Ω-notation

10
New cards

Definition. Θ-notation

11
New cards

Definition. o-notation

12
New cards

Definition. ω-notation

13
New cards

Definition of SMT

14
New cards

Θ(n log n)

15
New cards
16
New cards

Θ(n2)

17
New cards

Θ(nlg3)

18
New cards

Θ(n2)

19
New cards

20
New cards

Let t be the iteration of the first call to Partition during which one of the elements from yi , yi+1, ..., yj is used as the pivot. Why must such a pivot exist?

Every element becomes a pivot exactly once.

21
New cards

What is the probability in quicksort that yi or yj is chosen as the pivot where i < j?

2/(j - i + 1)

22
New cards

What can the following be simplified to in qucksort?

23
New cards

What is a naive runtime for quicksort when you manually choose pivot?

O(n2)

24
New cards

What is naive runtime for counting inversions alg?

O(n2)

25
New cards

What is rough algorithm for counting inversions?

Similar to merge sort we divide array and half and count inversions + sort. Do same for combine step except when a > b, b must be smaller than all remaining elements in A so we add all remaining elements to count of inversions.

26
New cards

What is the runtime for optimized counting inversions?

O(nlgn)

27
New cards

What is the lower bound on the number of elements <= median of medians x? What about lower bound on the number of elements >= median of medians x? Based on lower bound, what is an upper bound on the worst case # of elements select is called on recursively?

at most 7n/10 + 6 elements = n - (3n/10 - 6)

28
New cards

What is alg for select?

29
New cards

What is the runtime for select?

O(n) proof by substitution

30
New cards

Prove runtime for select

31
New cards

Explain why sorting is important in closest pair.

Sorting is important in the closest‑pair algorithm because it makes the combine step run in linear time. After dividing the points into left and right halves, the algorithm needs to examine only the points that lie in the vertical strip of width 2δ. To do this efficiently, we maintain the points sorted by y‑coordinate. This ordering is crucial: it ensures that when scanning the strip, each point only needs to be compared with the next at most 7 points in y‑order.

This 7‑point bound comes from the geometric packing argument (sometimes explained using the pigeonhole principle): in a δ×2δ rectangle, you cannot fit more than 8 points that are all at least δ apart. Therefore, once the strip is sorted by y, the algorithm only checks a constant number of neighbors per point, making the combine step O(n).

32
New cards

What is the runtime for push, pop, peek, isEmpty operations for a stack?

33
New cards

When do you decrease size of the array capacity in stack pop?

When the stack is equal to ¼ of the array capacity

34
New cards

What is the runtime for enqueue, dequeue, peek, isEmpty operations for a queue?

35
New cards

What are the properties of a binary heap data structure?

It is a nearly complete binary tree. Each node of the tree corresponds to an element of the array. The tree is completely filled on all levels except possibly the lowest, which is filled from the left up to a point.

36
New cards

What is the max-heap property? min-heap property?

Max-heap: A[Parent(i)] ≥ A[i], Min-heap: A[Parent(i)] ≤ A[i]

37
New cards

What is the height of a heap?

⌊lgn⌋

38
New cards

The root is stored at index 1, and if a node is at index i, then:
Parent(i): _________
Left(i): ____________
Right(i): __________

39
New cards

What two properties are stored to access heaps?

A.length, which is the number of elements in the array, and A.heapsize, which is the number of array elements that are actually part of the heap. Even though A is potentially filled with numbers, only the elements in A[1..A.heapsize] are actually part of the heap.

40
New cards

What is the runtime of Max-Heapify procedure?

O(lg n)

41
New cards

What is the runtime of Build-Max-Heap procedure?

O(n)

42
New cards

What is the runtime of Heapsort procedure?

O(n lg n)

43
New cards

Explain algorithm for Max-Heapify.

44
New cards

What is an upper bound on the number of children in the L/R subtrees in max-heapify?

L tree >= R tree. Worst case is when bottom level is half full so n/2 nodes belong to L tree. Remaining n/2 nodes are split evenly. Upper bound <= 2n/3

45
New cards

What is the time recurrence for max-heapify?

46
New cards

What is the algorithm for Build-Max-Heap?

47
New cards

How many nodes could there be in binary tree of height h?

2h+1-1

48
New cards

What is the maximum number of nodes on the bottom level a heap?

2h nodes on the bottom level
2h=2h+1/2= (n + 1)/2 <= n/2

49
New cards

What is the loop invariant for build max heap?

50
New cards

Explain linear time for Build-Max-Heap.

51
New cards

What is the algorithm for heapsort?

52
New cards

What is the algorithm for looking at heap maximum? Runtime?

Return the value at the top of the heap. Θ(1)

53
New cards

What is the algorithm for extracting heap maximum? Runtime?

O(lg n)

54
New cards

What is the algorithm for extracting heap increase key? Runtime?

O(lg n)

55
New cards

What is the algorithm for max heap insert key? Runtime?

O(lg n)

56
New cards

What is the definition of a prefix code for S?

57
New cards

Def of ABL (Average bits per letter) in Huffman’s encoding

58
New cards

Suppose we take a rooted tree T in which each node that is not a leaf has exactly two children; i.e. T is a binary tree. Further, suppose that the number of leaves is equal to the size of the alphabet S, and we label each leaf with a distinct letter in S. Such a labeled binary tree T naturally describes a prefix code. For each letter x ∈ S, we follow the path from the root to the leaf labeled x. Each time the path goes from a node to its left child, we write down a 0, and each time the path goes from a node to its right child, we write down a 1. We take the resulting string of bits as the encoding for x.

Lemma 1. The encoding of S constructed from T as described above is a prefix code

59
New cards

One thing to note immediately about the optimal binary tree T is that it is full. That is, each node that is not a leaf has exactly two children. To see why, suppose the optimal tree weren’t full. Then we could take any node with only one child, remove it from the tree, and replace it by its lone child. This would create a new tree T 0 such that ABL(T 0 ) < ABL(T), contradicting the optimality of T.

60
New cards

61
New cards

Specifically, let v be a leaf in T ∗ whose depth is a large as possible. Leaf v has a parent u, and since T ∗ must be full, u has another child, w, which is a sibling of v. Note that w is also a leaf in T ∗ , otherwise, v would not be the deepest possible leaf. Now, since v and w are siblings at the greatest depth, our level-by-level labelling process will reach them last. The leaves at this deepest level will receive the lowest frequency letters, and since we argued above that the order in which we assign these letters to the leaves within this level doesn’t matter.

62
New cards

Describe Huffman’s Algorithm

63
New cards

Formal definition of layers in BFS

64
New cards

Describe BFS algorithm

65
New cards

66
New cards

67
New cards

Describe DFS algorithm

68
New cards

69
New cards

70
New cards

Definition of tree edges, back edges, forward edges, cross edges.

71
New cards

What does white, gray and black mean in classifying edges (tree, back, forward, cross)?

72
New cards

73
New cards

We’d like to characterize bipartite graphs. In order to do so, let’s consider some examples of bipartite graphs. Clearly, a triangle graph is not bipartite. More generally, any cycle of odd length cannot be bipartite. If C = (v1 v2 ... v2k v2k+1) is an odd cycle which we try to two-color, note that the even-indexed nodes and odd-indexed nodes must have different colors. Since there is an edge between v1 and v2k+1, both of which are the same color, it is impossible to two-color an odd cycle. Moreover, if a graph G simply contains an odd cycle, it cannot be two-colorable.

74
New cards

75
New cards

76
New cards

77
New cards

Describe Kahn’s Algorithm for Topological Ordering

78
New cards

Describe Tarjan’s Algorithm for Topological Ordering

79
New cards

Prove Tarjan’s Algorithm for Topological Ordering

80
New cards

Describe Kosaraju’s Algorithm

81
New cards

82
New cards

83
New cards

84
New cards

85
New cards

What is the Dijkstra’s invariant for dist(s, t)?

At any point in time, dist[t] ≥ d(s, t), and when t is finished, dist[t] = d(s, t)

86
New cards

Describe Dijkstra's algorithm

87
New cards

88
New cards

What is the runtime of Dijkstra’s?

O((V + E) lgV)

89
New cards

Describe Shortest Path in DAG Algorithm

90
New cards

What is the runtime for Shortest Path in DAG Algorithm?

O(n + m)

91
New cards

What is the POC for Shortest Path in DAG Algorithm?

92
New cards

Definition of spanning subgraph

A spanning subgraph of G is a subgraph of G that contains all the vertices in G.

93
New cards

Definition of a minimum weight spanning subgraph

A minimum weight spanning subgraph or minimum spanning subgraph is a spanning subgraph whose total cost is the minimum over all other spanning subgraphs.

94
New cards

Proposition 1. Let T be a minimum cost set of edges as described above. Then (V, T) is a tree

95
New cards

Describe Prim’s Algorithm

Another way to phrase Prim’s algorithm is that it starts with T = {s} and at each step, chooses the lightest weight edge crossing the cut (T, V − T) (here we use T as a set of vertices) and adds it to the growing tree.

96
New cards

What is the runtime of Prim’s algorithm?

O(mlgn)

97
New cards

Describe Kruskal’s algorithm

98
New cards

What data structure is needed in Kruskal’s algorithm?

Union find

99
New cards

What is the runtime of Kruskal’s?

O(m log m) = O(m log n), dominates all union find operations

100
New cards

Describe the algorithm for reverse-delete