Homework 4, What does this algorithm do.
Short Description:
In this homework you will evaluate an algorithm to
- Trace an algorithm.
- Describe the task accomplished by this algorithm.
- Argue that the algorithm is correct and discuss performance
This assignment is worth 40 points.
Goals
When you finish this homework, you should have:
- Improved your skills at algorithm analysis. (Objective 4)
Formal Description
Unknown(G = (V,E), s)
// G is a directed graph.
// s ∈ V
// H is a Heap the key is cost.
- For each vertex in V
- v.parent = unknown
- v.cost = ∞
- v.status = unknown
- H.Insert(v)
- EndFor
- s.cost = 0
- H.DecreaseKey(s)
- s.parent = null;
- s.status = discovered
- While H.Size() > 0
- u = H.ExtractMin()
- u.status = finished
- For each v $\in$ U.Adj()
- If v.status ≠ finished
- If v.cost > u.cost + w(u,v)
- v.parent = u
- v.cost = u.cost+w(u,v);
- H.DecreaseKey(v)
- v.status = discovered
- EndIf
- EndIf
- EndFor
- EndWHile
This assumes that the function DecreaseKey
has been implemented on the heap. This function requires that the heap be augmented by an an index array. This will allow an item to be located in O(1). After the item is located, its cost is adjusted and HeapifyUp() is called on it. DecreaseKey is $O(\log n)$.
- [10 points] Trace this algorithm with the following undirected weighted graph pictured below.
- Use multiple copies of this graph (one for each iteration of loop h)
- Show the parent pointers at each step
- Show the cost at each step.
- Indicate the node "u" at each step (from line 12)
-
- [10 points] What does this algorithm do?
- Do this step before you move on.
- Consider the reverse of the parent pointers. What is this tree?
- This might be hard to determine at first, tracing the algorithm the following graph might help.
-
- If that doesn't help, try adding up the values of all the edges selected.
- [10 points] The purpose of this algorithm is to find a tree which connects all nodes where the sum of the weights of the edges of the tree is minimized.
- Argue that this algorithm accomplishes this task.
- [10 points] What is the performance of this algorithm?
- Provide an argument to support your claim.
Discussion
Please reference any sources you used to accomplish this homework.
Required Files
A word document.
Submission
Submit the assignment to the D2L folder Homework 4 by the due date.