Question

For a directed graph the in-degree of a vertex is the number of edges it has coming in to it, and the out- degree is the numb

1 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student,

Let G is a directed Graph with v vertices and e edges.

a) Pseudocode for computing in-degrees and out-degrees.

/**********************code start here ************************/

degree( G[][], int v)

int in[v] , out[v]

// initialize every index of in[] and out[] with 0

for i <-- 0 to e:

for j <-- 0 to e:

if G[i][j] equals 1:

in[i] = in[i] + 1

out[j] = out[j] + 1

// end of if

// end of for

// end of for

//end of degree

b) Calculating time complexity of above algorithm if graph has n vertices.

degree( G[][], int v) // O(1)

int in[v] , out[v] //O(1)

// initialize every index of in[] and out[] with 0

for i <-- 0 to e: //O(n)

for j <-- 0 to e: // O(n)

if G[i][j] equals 1: // O(1)

in[i] = in[i] + 1 // O(1)

out[j] = out[j] + 1 // O(1)

// end of if

// end of for

// end of for

//end of degree

Total Time complexity = 1 + 1 + n*n(1 +1 +1)   // n*n because, for every iteration in first loop, second loop is running n times

= 2 + 3n

= O(n^2) [ as n^2 is the biggest term in the above equation]

Add a comment
Know the answer?
Add Answer to:
For a directed graph the in-degree of a vertex is the number of edges it has...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT