Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The three for loops are nested Consider the following function whose input is an

ID: 3758479 • Letter: T

Question

The three for loops are nested

Consider the following function whose input is an undirected graph G. Edges of G are represented by an adjacency LIST.

procedure func1(G)

1 s 0;

2 foreach vertex vi V (G) do

3 foreach edge (vi , vj ) incident on vi do

4 foreach vertex vp V (G) do

5 if (vj = vp) then

6 s s + 1;

7 end

8 end

9 end

10 end

11 return (s);

Let n be the number of vertices of G and let m be the number of edges of G. Analyze the running time of Function func1, giving a bound on its asymptotic running time in terms of n and m.

Explanation / Answer

Solution :

After analyzing, the running time of function func1 is O(m log n).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote