Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

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

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Próximo SlideShare
Asymptoticnotation
Asymptoticnotation
Cargando en…3
×

Eche un vistazo a continuación

1 de 1 Anuncio

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

Descargar para leer sin conexión

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)
.

Anuncio
Anuncio

Más Contenido Relacionado

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

Más de darlened3 (20)

Anuncio

Más reciente (20)

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

  1. 1. 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)

×