Frequently asked questions Flashcards
(11 cards)
Solve the recurrance T(n) = T(n−1) + n, with T(1) = 1
Θ(n²)
What is the complexity or the algorithm this recurrence represents?
Merge Sort, O(n log n)
Which data structure would you use to verify matched brackets like [{()}]?
Stack
What is the psudocode for inorder transversal
if node ≠ null:
inorder(node.left)
visit(node)
inorder(node.right)
What is the pseudocode for preorder transversal
if node ≠ null:
visit(node)
preorder(node.left)
preorder(node.right)
What is the pseudocode for postorder transversal
if node ≠ null:
postorder(node.left)
postorder(node.right)
visit(node)
What algorithm is this:
for i = 0 to n - m
j = 0
while (P[j] == T[i + j])
Naive String Matching — searching P inside T
Given a DAG or a node sequence, which one is a valid topological sort?
Use dependency direction — earlier node must come before dependent
Triple loop where inner while (k < n) k *= 2
O(n² log n)
What does Prim’s algorithm compute?
Minimum Spanning Tree (MST)
T(n) = 4T(n/2) + n²
Use the Master Theorem to solve this recurrence
Θ(n² log n)