Successfully reported this slideshow.

# Let P be an implementation of a min priority queue where- pint() takes.docx

Upcoming SlideShare
Asymptoticnotation
×

# Let P be an implementation of a min priority queue where- pint() takes.docx

Let P be an implementation of a min priority queue where: pint() takes 0(1) time. Initially, P has 0 elements. Insert(rr) takes 0(log2(s)) time where s is the number of elements in P. P. Insert() adds one element to P. P. Delete Min() takes 0(\\/s) time where s is the number of elements in P. P. Delete Min() removes one element from P. Consider the following procedure whose input is an undirected graph G. Edges of G are represented by an adjacency LIST, weight(ui) is a positive weight assigned to vertex (v*). Proc2(g) P. Init(); for each vertex Vi of G do for each edge (vi, V_j) incident on Vi do Let n be the number of vertices of G and let m be the number of edges of G. Assume that m >n. (a) Analyze lines 1-6 of Proc2 giving a bound on their asymptotic running time in terms of n and m. (b) Analyze lines 7-10 of Proc2 giving a bound on their asymptotic running time in terms of n and m. (c) Give the asymptotic running time of Proc2 in terms of n and m.
Solution
(a) here the code executes for m(n-1) times hence the asymptotic running time for 1-6 lines of proc2 is O(mn)
(b) here the code from 7-10 of proc2 runs for 2*number of edges times . This is because of undirected graph each edge weight will be inserted twice into the p hence the asymptotic notation representing the running time is O(2m)=> O(m)
(c) here simply we can obtain the result by adding the answers of (a) and (b) given above
Hence the asymptotic running time is : O(m(n+1)) => O(mn+m)
.

Let P be an implementation of a min priority queue where: pint() takes 0(1) time. Initially, P has 0 elements. Insert(rr) takes 0(log2(s)) time where s is the number of elements in P. P. Insert() adds one element to P. P. Delete Min() takes 0(\\/s) time where s is the number of elements in P. P. Delete Min() removes one element from P. Consider the following procedure whose input is an undirected graph G. Edges of G are represented by an adjacency LIST, weight(ui) is a positive weight assigned to vertex (v*). Proc2(g) P. Init(); for each vertex Vi of G do for each edge (vi, V_j) incident on Vi do Let n be the number of vertices of G and let m be the number of edges of G. Assume that m >n. (a) Analyze lines 1-6 of Proc2 giving a bound on their asymptotic running time in terms of n and m. (b) Analyze lines 7-10 of Proc2 giving a bound on their asymptotic running time in terms of n and m. (c) Give the asymptotic running time of Proc2 in terms of n and m.
Solution
(a) here the code executes for m(n-1) times hence the asymptotic running time for 1-6 lines of proc2 is O(mn)
(b) here the code from 7-10 of proc2 runs for 2*number of edges times . This is because of undirected graph each edge weight will be inserted twice into the p hence the asymptotic notation representing the running time is O(2m)=> O(m)
(c) here simply we can obtain the result by adding the answers of (a) and (b) given above
Hence the asymptotic running time is : O(m(n+1)) => O(mn+m)
.