(a) Given the following list of numbers:
3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5
trace the execution for quicksort with median–of–three partitioning and a cutoff of 3.
(b) The processing time of an algorithm is described by the following recurrence equation (c
is a positive constant):
T(n) = 3T(n/3) + 2cn; T(1) = 0
What is the running time complexity of this algorithm? Justify.
(c) You decided to improve insertion sort by using binary search to find the position p where
the new insertion should take place.
(c.1) What is the worst–case complexity of your improved insertion sort if you take account
of only the comparisons made by the binary search? Justify.
(c.2) What is the worst–case complexity of your improved insertion sort if only
swaps/inversions of the data values are taken into account?
Problem #3: (35 pts)
(a) Either draw a graph with the following specified properties, or explain why no such graph exists:
A simple graph with five vertices with degrees 2, 3, 3, 3, and 5.
(b) Consider the following graph. If there is ever a decision between multiple neighbor nodes in the BFS or DFS algorithms, assume we always choose the letter closest to the beginning of the alphabet first.
(b.1) In what order will the nodes be visited using a Breadth First Search starting from vertex A and using a queue ADT?
(b.2) In what order will the nodes be visited using a Depth First Search starting from vertex A and using a stack ADT?
(c) Show the ordering of vertices produced by the topological sort algorithm given in class starting from vertex V1 when it is run on the following direct acyclic graph (represented by
its adjacency list, in–degree form). Justify.
V0 —
V1 —
V2 V0, V1
V3 V0, V1
V4 V0, V2
V5 V1
V6 V2, V4, V5
V7 V6