Frequently asked questions Flashcards

(11 cards)

1
Q

Solve the recurrance T(n) = T(n−1) + n, with T(1) = 1

A

Θ(n²)

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

What is the complexity or the algorithm this recurrence represents?

A

Merge Sort, O(n log n)

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

Which data structure would you use to verify matched brackets like [{()}]?

A

Stack

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

What is the psudocode for inorder transversal

A

if node ≠ null:
inorder(node.left)
visit(node)
inorder(node.right)

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

What is the pseudocode for preorder transversal

A

if node ≠ null:
visit(node)
preorder(node.left)
preorder(node.right)

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

What is the pseudocode for postorder transversal

A

if node ≠ null:
postorder(node.left)
postorder(node.right)
visit(node)

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

What algorithm is this:
for i = 0 to n - m
j = 0
while (P[j] == T[i + j])

A

Naive String Matching — searching P inside T

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

Given a DAG or a node sequence, which one is a valid topological sort?

A

Use dependency direction — earlier node must come before dependent

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

Triple loop where inner while (k < n) k *= 2

A

O(n² log n)

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

What does Prim’s algorithm compute?

A

Minimum Spanning Tree (MST)

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

T(n) = 4T(n/2) + n²
Use the Master Theorem to solve this recurrence

A

Θ(n² log n)

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