Exam Questions Flashcards
1
Q
How can array top be found, (an element whose neighbor(s) are smaller?
A
FindTop(array)
Check array borders.
Check the middle element if it is the top.
If not check the half for the greatest neighbor to the middle element.
2
Q
How can you show that a problem is in NP?
A
Show we can verify problem correctness in P. (polynomial time)
3
Q
How can you prove that a dynamic programming algorithm is correct?
A
Since you have an optimal way of describing a correct solution for index j and given for 0, this holds by induction. OPT(j).
4
Q
What are the steps for an exchange argument?
A
- Assume a Greedy Solution and Another Optimal Solution: Start by considering the solution generated by the greedy algorithm and another arbitrary optimal solution.
- Find a Difference: Identify a point where the greedy solution differs from the assumed optimal solution.
- Exchange to Improve: Show that this difference can be “exchanged” or modified in the optimal solution without losing optimality, thereby making the optimal solution more similar to the greedy solution.
- Iterate the Process: Continue exchanging elements until the arbitrary solution looks exactly like the greedy one, proving that the greedy solution is also optimal.