Quiz 3 Flashcards

1
Q

What are the two main components of a graph data structure?

A

Vertices (V) and edges (E)

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

How is a sparse graph defined compared to a dense graph?

A

A sparse graph has E = O(V) edges while a dense graph has E = O(V^2) edges.

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

What is the runtime complexity of Kruskal’s algorithm to find the minimum spanning tree?

A

O(E log E) or O(E log V)

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

What is Prim’s algorithm and how does it differ from Kruskal’s algorithm?

A

Prim’s grows a MST starting from a single root vertex, adding minimum weight edges. Kruskal’s builds up a MST by adding edges in increasing weight order without cycles.

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

What is the greedy method and what are its pros and cons?

A

It optimizes locally without regard for long-term consequences. Pros: simple, efficient. Cons: often suboptimal.

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

When can greedy algorithms lead to optimal solutions?

A

For problems exhibiting optimal substructure like shortest paths, minimum spanning trees.

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

What is the optimal coin change problem an example of?

A

A greedy algorithm for optimization.

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

What is the goal of scheduling problems like minimizing time in system?

A

To schedule jobs/tasks to optimize an objective like average completion time.

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

What is the 0/1 knapsack problem?

A

Packing the most valuable set of items without exceeding a weight capacity.

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

How do you select objects for the knapsack problem using the greedy method?

A

In decreasing order of value per unit weight.

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

What is the purpose of backtracking and branch and bound algorithms?

A

To search a solution space represented as a tree.

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

How do backtracking and branch and bound differ in traversing a state space tree?

A

Backtracking uses depth-first search while branch and bound uses breadth-first search.

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

What is the optimal substructure property needed for dynamic programming?

A

Optimal solutions are built from optimal solutions to subproblems.

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

What is the divide and conquer algorithm strategy?

A

Break a problem into subproblems, solve subproblems, and combine solutions.

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

When is divide and conquer most useful?

A

For problems that can be recursively broken down into smaller instances like sorting, matrix multiplication.

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

What is the principle of optimality for dynamic programming?

A

Optimal solutions to a problem contain optimal solutions to subproblems.

17
Q

What is the specialized principle of optimality?

A

The optimal sequence of decisions leaves subproblems optimal.

18
Q

What is the problem with greedy method on the sequential storage problem?

A

It fails if objects have different access probabilities.

19
Q

How do you optimally order files for sequential storage?

A

In increasing order of cost/probability ratio.

20
Q

What is the goal of scheduling problems like maximizing profit?

A

To schedule jobs to maximize objectives like profit within constraints.

21
Q

How do you select jobs using the greedy method for scheduling with deadlines?

A

Select the most profitable remaining job that meets its deadline.

22
Q

What is the fractional knapsack problem?

A

A knapsack problem where fractions of items can be taken.

23
Q

How do you prove the greedy method optimally solves knapsack problems?

A

By showing the residual after swapping items is always nonnegative.

24
Q

What are the different selection methods for the knapsack problem?

A

Maximum value, minimum weight, maximum value/weight ratio.

25
Q

What is the runtime complexity to implement knapsack using greedy?

A

O(n log n) for sorting + O(n) for greedy selection.

26
Q

What are the main operations for Kruskal’s algorithm?

A

Sort edges, find connected components, merge components.

27
Q

What is the A* search algorithm related to?

A

Branch and bound with a least cost heuristic.

28
Q

What is alpha-beta pruning in game trees?

A

Pruning subtrees that cannot improve the minimax value.

29
Q

What are heuristics and how are they used in backtracking and branch and bound?

A

Estimates of cost to guide tree search, like with A* algorithm.

30
Q

What is the complexity class of problems like TSP that dynamic programming can solve?

A

NP-hard

31
Q

What are the differences between top down and bottom up dynamic programming?

A

Top down uses recursion, bottom up iteratively solves subproblems.

32
Q

What problems exhibit optimal substructure for dynamic programming?

A

Problems like shortest paths, text editing distance.

33
Q

What is memoization and how does it help dynamic programming?

A

Caching results of solved subproblems to avoid re-computation.

34
Q

What are the differences between greedy and dynamic programming?

A

Greedy optimizes locally, DP globally by combining subsolutions.

35
Q

What heuristic does Dijkstra’s algorithm use to find shortest paths?

A

Minimum distance from source vertex.

36
Q

What are some examples of problems where a greedy approach finds optimal solutions?

A

Minimum spanning trees, shortest paths, Huffman coding.

37
Q

How does parallelism help overcome performance issues with dynamic programming?

A

Subproblems can be solved concurrently at each stage.

38
Q

What is the runtime complexity of Floyd-Warshall algorithm for all pairs shortest paths?

A

O(V^3)