Question

Make sure to answer part a and b. Consider the graph below. a. (5 points) Create an adjacency matrix. b. (5 points) Can this
0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • Below is the detailed solution of the above problem.

  1. Adjacency matrix is shown below (a matrix of size 6*6):

. B. Ot F D А 0 Adjacency list: А А A B O MUA BICIDEE 0 |||0||1 O Io 1 10 O ♡ololololo OOOO E o lolo 1 lo lolo M[i][j 2 l if

2.For topological sort : Yes this graph can be topologically sorted as a Directed Acyclic graph can be topologically sorted. Clearly we can see that the graph has no cycle and it is directed also.

Topological sorted order:  A F B C D E\

Indegree of a node is number of incoming edges to it.

Using the decrease by one method to topological sort we can get the above order, below is the algorithm for that.

  1. Calculate the in-degree of all the nodes in the graph and initialize a count variable to 0 i.e, it represents number of visited nodes.

  2. Now take all the nodes with indegree as 0 and put it in a queue.

  3. Now remove a vertex from the queue( and add it to our answer vector which will contain the topological sort of graph) and then increase the count variable by 1 as we visit this node and decrease indegree of all the node's neighboring nodes by 1, if some node's indegree become 0 then add it into queue.

  4. Repeat all the above step(3) until queue becomes empty.

  5. Now if our count variable is not euqal to total nodes in the graph that means some node is unvisited so topological sort is not possible otherwise we have our topological sort in our vector.

indegree={A:0, B:1, C:2, D:1, E:4, F:1}

So first A has indegree 0 so it is added into queue, then A is popped out and added to our answer then decreasing indegree of neighbors of A by 1 we get indegree={A:0, B:1, C:1, D:1, E:3, F:0},

so indegree of F becomes 0 so it is added to queue.

Now again an element is popped from queue i.e, F and added to our answer then updated indegree becomes, indegree={A:0, B:0, C:0, D:1, E:3, F:0}

So indegree of B and C becomes 0 so it is added to queue then now again we pop an element from queue i.e, B(and added to our answer) and update our indegree so it becomes, indegree={A:0, B:0, C:0, D:1, E:2, F:0}

Now pop C(and added to our answer) from the queue, and update the indegree {A:0, B:0, C:0, D:0, E:1, F:0}, so indegree of D becomes 0 so add it in queue,

Now pop D(and added to our answer) from queue and update our indegree as {A:0, B:0, C:0, D:0, E:0, F:0}, so indegree of E becomes 0 so add it in queue.

At last pop E(and added to our answer) from queue and now the queue will be empty.

Now we have our answer vector as {A F B C D E}.


answered by: ANURANJAN SARSAM
Add a comment
Answer #2
  • Below is the detailed solution of the above problem.
  1. Adjacency matrix is shown below (a matrix of size 6*6):

. B. Ot F D А 0 Adjacency list: А А A B O MUA BICIDEE 0 |||0||1 O Io 1 10 O ♡ololololo OOOO E o lolo 1 lo lolo M[i][j 2 l if

2.For topological sort : Yes this graph can be topologically sorted as a Directed Acyclic graph can be topologically sorted. Clearly we can see that the graph has no cycle and it is directed also.

Topological sorted order:  A F B C D E\

Indegree of a node is number of incoming edges to it.

Using the decrease by one method to topological sort we can get the above order, below is the algorithm for that.

  1. Calculate the in-degree of all the nodes in the graph and initialize a count variable to 0 i.e, it represents number of visited nodes.
  2. Now take all the nodes with indegree as 0 and put it in a queue.
  3. Now remove a vertex from the queue( and add it to our answer vector which will contain the topological sort of graph) and then increase the count variable by 1 as we visit this node and decrease indegree of all the node's neighboring nodes by 1, if some node's indegree become 0 then add it into queue.
  4. Repeat all the above step(3) until queue becomes empty.
  5. Now if our count variable is not euqal to total nodes in the graph that means some node is unvisited so topological sort is not possible otherwise we have our topological sort in our vector.

indegree={A:0, B:1, C:2, D:1, E:4, F:1}

So first A has indegree 0 so it is added into queue, then A is popped out and added to our answer then decreasing indegree of neighbors of A by 1 we get indegree={A:0, B:1, C:1, D:1, E:3, F:0},

so indegree of F becomes 0 so it is added to queue.

Now again an element is popped from queue i.e, F and added to our answer then updated indegree becomes, indegree={A:0, B:0, C:0, D:1, E:3, F:0}

So indegree of B and C becomes 0 so it is added to queue then now again we pop an element from queue i.e, B(and added to our answer) and update our indegree so it becomes, indegree={A:0, B:0, C:0, D:1, E:2, F:0}

Now pop C(and added to our answer) from the queue, and update the indegree {A:0, B:0, C:0, D:0, E:1, F:0}, so indegree of D becomes 0 so add it in queue,

Now pop D(and added to our answer) from queue and update our indegree as {A:0, B:0, C:0, D:0, E:0, F:0}, so indegree of E becomes 0 so add it in queue.

At last pop E(and added to our answer) from queue and now the queue will be empty.

Now we have our answer vector as {A F B C D E}.

So if you have any doubt regarding this solution then please feel free to ask in the comment section below and if it is helpful then please upvote this solution, THANK YOU.

Add a comment
Know the answer?
Add Answer to:
Make sure to answer part a and b. Consider the graph below. a. (5 points) Create...
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
  • Exercise 3 (35 points) Depth-First Search Consider the following graph G=(V,E): a) Complete V= {z, ....)...

    Exercise 3 (35 points) Depth-First Search Consider the following graph G=(V,E): a) Complete V= {z, ....) (Fill in the blanks. Sort V alphabetically in reverse z–a) b) Complete E = {(zz), ...} c) Complete the adjacency list as a table {sort Adiſul alphabetically in reverse zna} Vertices u Adj[u] {z, } y d) Execute Depth-First Search (DFS(G)) on Graph G. Respect the order of the adjacency list as completed in the previous question. Show all figures (a) through (p) just...

  • help with alogrthms Consider the following graph for problems 6, 7, & 8. (b f C...

    help with alogrthms Consider the following graph for problems 6, 7, & 8. (b f C d a (5 points) Starting at vertex a and resolving ties by the vertex alphabetical order, traverse the graph by depth-first search 7. and construct the corresponding depth-first search tree (5 points) Traverse the graph by breadth-first search and construct the corresponding breadth-first search tree. Start the 8. traversal at vertex a and resolve ties by the vertex alphabetical order. Consider the following graph...

  • expert please (0 points) Find the Compressed Row Storage (CRS) of the matrix below. Make sure...

    expert please (0 points) Find the Compressed Row Storage (CRS) of the matrix below. Make sure you use the method discussed in class using indexing that starts with 1. Your answer should consists of three vectors valy, col TOWA 0 0 0 0 0 0 0 0 0 0 8 0 -70 0 0 9 0 0 0 0 0 1 0 5 -7 6 0 0 0 5 0 -5 0 9 0 - MUUT VIRUS (0 points) 1...

  • 9 5 attempts left Check my work Be sure to answer all parts Report problem Hint points Rank the following groups in ord...

    9 5 attempts left Check my work Be sure to answer all parts Report problem Hint points Rank the following groups in order of decreasing priority: А. — СНз В. — СН,СHз С. —СН,СH,CH D.(CH2)3CH3 Solution 03:48:15 Guided Solution eBook References A В с D Highest Priority Lowest Priority

  • Please answer A and B 1. Consider the following adjacency matrix representing vertices v through v^:...

    Please answer A and B 1. Consider the following adjacency matrix representing vertices v through v^: weighted graph containing a ro 5 0 0 8 0 61 5 0 0 7 0 0 0 jo 0 0 0 0 1 3| 0 7 0 0 2 0 0 8 0 0 0 0 1 0 0 0 4 L6 0 3 0 0 4 0- 20 0 0 a. Draw the graph resulting from the adjacency matrix b. Assuming the...

  • **********Using Java*************** Create 5 CLASSES: Driver(main), Word, AnagramFamily, and 2 Comparators classes words.txt is a very...

    **********Using Java*************** Create 5 CLASSES: Driver(main), Word, AnagramFamily, and 2 Comparators classes words.txt is a very large file containing thousands of words. I will post some words down below. some of word.txt aa aah aahed aahing aahs aal aalii aaliis aals aardvark aardvarks aardwolf aardwolves aargh aarrgh aarrghh aas aasvogel aasvogels ab aba abaca abacas abaci aback abacterial abacus abacuses abaft abaka abakas abalone abalones abamp abampere abamperes abamps abandon abandoned abandoner abandoners abandoning abandonment abandonments abandons abapical abas abase...

  • PYTHON 3 node Node ADT Question. Question 3 (18 points): Purpose: To practice working with node chains created using...

    PYTHON 3 node Node ADT Question. Question 3 (18 points): Purpose: To practice working with node chains created using the Node ADT to implement slightly harder functionality Degree of Difficulty: Moderate to Tricky In this question you'll implement merge sort for node chains! Recall, merge sort is a divide-and-conquer technique that uses recursion to sort a given sequence (in this case a node chain). A overview of the algorithm is given below. Algorithm mergeSort (NC) Borts node chain NC using...

  • JavaScript - Sorting Assignment (arrays, classes, functions and higher order functions) Note: Please make sure to...

    JavaScript - Sorting Assignment (arrays, classes, functions and higher order functions) Note: Please make sure to use the ES6 keyword style => instead of the older function. For variables please use keyword let, not var, class and within the constructor, not function. Instructions: - Create a new JavaScript file and name it “Objects.js” - Create a class and make sure to use “names” as the identifier. - Create a constructor with the following elements: first ( value passed will be...

  • Consider the following mergeSortHelper method, which is part of an algorithm to recursively sort an array...

    Consider the following mergeSortHelper method, which is part of an algorithm to recursively sort an array of integers. /**  Precondition: (arr.length == 0 or 0 <= from <= to <= arr.length) * arr.length == temp.length */ public static void mergeSortHelper(int[] arr, int from, int to, int[] temp) { if (from < to) { int middle = (from + to) / 2; mergeSortHelper(arr, from, middle, temp); mergeSortHelper(arr, middle + 1, to, temp); merge(arr, from, middle, to, temp); } } The merge method...

  • make sure the answer is correct 100% Exercise 1: Suppose that 5 jobs will be processed...

    make sure the answer is correct 100% Exercise 1: Suppose that 5 jobs will be processed on a single machine. The jobs are ready for processing at time. The other job characteristics are as shown in the table below. Find the: Mean flow time, Average tardiness and number of tardy jobs using: a. FCFS (30 Points) b. EDD (30 Points) Job Processing Time Due Date 10 20 B 20 30 С 4 10 D 16 24 E 6 8 F...

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