LN12 NP-complete problems Flashcards

1
Q

How can the shortest paths in a Directed Acyclic Graph (DAG) be efficiently computed?

A

By using a topological order, which allows computing shortest paths in O(m) time by iterating from the source node and updating distances for each edge.

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

Why can we apply the same algorithm for longest paths in DAGs by replacing min with max?

A

Since DAGs have no cycles, paths can be extended without revisiting nodes, making the approach safe for finding maximum distances.

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

What is the Union-Find data structure used for in Kruskal’s MST algorithm?

A

Union-Find helps efficiently check if adding an edge would form a cycle by determining if two nodes belong to the same component, maintaining disjoint sets as trees.

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

Describe the Union-Find optimization known as “path compression.”

A

Path compression flattens the structure of the tree by making all nodes on the path point directly to the root, reducing future search times for Find operations.

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

How does the greedy algorithm for Interval Partitioning work?

A

Intervals are sorted by their start times, and each interval is assigned to the first subset where it does not overlap with any interval, minimizing the number of subsets.

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

Explain the duality-based proof technique for the Interval Partitioning greedy algorithm.

A

The proof shows that the algorithm achieves the minimum possible number of partitions by equating the maximum overlapping intervals as a lower bound on required partitions.

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

Why is finding the longest path NP-complete in general graphs, but feasible in DAGs?

A

In general graphs, longest paths can contain cycles, making the problem exponentially complex. In DAGs, no cycles exist, enabling linear time solutions with topological order.

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

What purpose does sorting edges serve in Kruskal’s algorithm for MST?

A

Sorting edges by cost ensures each addition to the MST is the cheapest option, enabling optimal MST construction.

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

How does Union-by-size improve the efficiency of Union operations in Union-Find?

A

Union-by-size links the smaller tree to the root of the larger tree, minimizing the number of relabelings and reducing tree depth.

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

Why can shortest paths in DAGs be solved with a dynamic programming approach?

A

The directed acyclic structure allows updating shortest distances in a single pass following the topological order, treating each subpath as an independent subproblem.

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

What is the time complexity for computing shortest paths in a DAG?

A

The complexity is O(n + m), where n is the number of nodes and m is the number of edges, due to single-pass processing of each edge.

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

How does the greedy approach in Interval Partitioning ensure optimality?

A

The algorithm minimizes partitions by assigning each interval to the earliest possible subset, achieving the lower bound on subsets required due to maximum overlaps.

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

In Union-Find, how many times can an element be relabeled in the worst case?

A

Each element can be relabeled at most log₂(n) times, as each Union operation doubles the set size, leading to an O(n log n) time bound.

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

What is the role of duality in optimization problems like Interval Partitioning?

A

Duality provides a lower bound on the primal solution by establishing a maximum condition that must be met, ensuring optimality when the primal solution meets this bound.

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

Describe the key difference between BFS-based shortest paths and Dijkstra’s algorithm in non-negative edge-weighted graphs.

A

BFS is optimal for unit weights by processing nodes layer by layer, while Dijkstra’s uses a priority queue to manage varying weights, selecting the minimum distance nodes iteratively.

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