Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 . 2 4 . On page 6 2 there is a high - level description of the quicksort algorithm. ( a ) Write down
On page there is a highlevel description of the quicksort algorithm.
a Write down the pseudocode for quicksort.
b Show that its worstcase running time on an array of size n is Theta n
c Show that its expected running time satisfies the recurrence relation
Tn On n nX iTi Tn i
Then, show that the solution to this recurrence is On log n
In Section we described an algorithm that multiplies two nbit binary integers x and y in time n a where a log Call this procedure fastmultiplyx y
a We want to convert the decimal integer n a followed by n zeros into binary. Here is the algorithm assume n is a power of :
function pwrbinn
if n : return
else: z
return fastmultiplyz z
Fill in the missing details. Then give a recurrence relation for the running time of the algorithm, and solve the recurrence.
b Next, we want to convert any decimal integer x with n digits where n is a power of into binary. The algorithm is the following:
function decbinx
if n :
return binaryx
else:
split x into two decimal numbers xL xR with n digits each
return
Here binary is a vector that contains the binary representation of all onedigit integers. That is binary binary up to binary Assume that a lookup in binary takes O time. Fill in the missing details. Once again, give a recurrence for the running time of the algorithm, and solve it
For each node u in an undirected graph, let twodegreeu be the sum of the degrees of us neighbors. Show how to compute the entire array of twodegree values in linear time, given a graph in adjacency list format.
Rewrite the explore procedure Figure so that it is nonrecursive that is explicitly use a stack The calls to previsit and postvisit should be positioned so that they have the same effect as in the recursive procedure.
Undirected vs directed connectivity.
a Prove that in any connected undirected graph G V E there is a vertex v in V whose removal leaves G connected. Hint: Consider the DFS search tree for G
b Give an example of a strongly connected directed graph G V E such that, for every v in V removing v from G leaves a directed graph that is not strongly connected.
c In an undirected graph with connected components it is always possible to make the graph connected by adding only one edge. Give an example of a directed graph with two strongly connected components such that no addition of one edge can make the graph strongly connected.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started