Question

114points Let G- (V,E) be a directed graph. The in-degree of a vertex v is the number of edges (a) Design an algorithm (give pseudocode) that, given a vertex v EV, computes the in-degree of v under (b) Design an algorithm (give pseudocode) that, given a vertex v E V, computes the in-degree of v incident into v. the assumption that G is represented by an adjacency list. Give an analysis of your algorithm. under the assumption that G is represented by an adjacency matrix. Give an analysis of your algorithm

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

Ans a) If the graph is represented as adjacency list then we just have to count the lenght of the list.

// i have assumed that list is implemented as a linked list.

int count(List ls){

int count=0;

List temp = ls;

while(temp != NULL){

count++;

temp = temp->next;

}

return count++;

}

Ans b) If the graph is represented as adjacency matrix then we just have to count the lenght of the list.

int count(Graph G,Vertex v, int nVertices){

int count=0;

for(int i=0;i<nVertices;i++){

if(G[v][i] == 1){ // it checks if there is an edge between vertex v and i.

count++;

}

}

return count;

}

Add a comment
Know the answer?
Add Answer to:
114points Let G- (V,E) be a directed graph. The in-degree of a vertex v is the...
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