Topological Sort using DFS :-
Step 1: Select any node from which you want to start. So, suppose if I select 11.
Step2: Then we enter 11 into the visited set. Now, treverse all the nodes which can be reached from 11.
Step 3: From 11, I can reach 2. So, put 2 in the visited node. Now, from 2 can I reach any further node? No. So pop the node 2 and put it into a shorted set.
Step 4: Come back to 11, we again check from 11 which node can we reach i.e., 9 So, put it into a visited set & 9 has no further node. So we pop the node 9 and put it into a sorted set.
Step 5: Repeat step 4. In this we get node 10 in the sorted set.
Step 6: Come back to 11 & check Is there any further node which can be visted from 11? The answer is No. So, we pop the node 11 and put it into a sorted set.
Step 7: Now I have to select one more node. So, suppose I select the node 7. So put it into the visted set & the check the node which can be reach from the node 7. From 7 we can reach 11 & 8 but we already visited the node 11 so we direct visit the node 8.
Step 8: Put the 8 into the visited set & then pop it and put it into the sorted set.
Step 9: Now I select one more node from 5 or 3. So suppose I select 5 so put it into visited set & from this all the node are already visited so we pop it & put it into a sorted set.
Step 10: Similarly the step 9, node 3 also has all visited node so we directly pop from the visited node & put it into a sorted node.
So, the final sorted set is 3,5,7,8,11,10,9,2
And the sorted graph will be:
3. Apply Topological sort algorithm on the following graph. Then, draw the sorted graph. 11 marvel
Apply the topological sort algorithm to the graph. Follow the algorithm in you textbook and clearly show the content of the three lists: resultList, noIncoming and remainingEdges after each iteration. 2. Apply the topological sort algorithm to the graph below. Follow the algorithm in you textbook and clearly show the content of the three lists: resultList, nolncoming and remainingEdges after each iteration GraphTopologicalSort (graph) { resultList = empty list of vertices no Incoming = list of all vertices with no...
7. Can the following graph be topologically sorted? Justify your answer. If it can, use the algorithm discussed in class to provide a topological sort. a. 7. Can the following graph be topologically sorted? Justify your answer. If it can, use the algorithm discussed in class to provide a topological sort. a.
(A) Consider the following algorithm for computing a topological sort of a DAG G: add the vertices to an initially empty list in non-decreasing order of their indegrees. Either argue that the algorithm correctly computes a topological sort of G, or provide an example on which the algorithm fails. (B) Can the number of strongly connected components of a graph decrease if a new edge is added? Why or why not? Can it increase? Why or why not? (C) What...
Describe an algorithm to test whether a given directed graph is a tree. Hint: Modify topological sort.
The weights of edges in a graph are shown in the table above. Apply the sorted edges algorithm to the graph. Give your answer as a list of vertices, starting and ending at vertex A. Example: ABCDEFA
3.3. Run the DFS-based topological ordering algorithm on the following graph. Whenever you have a choice of vertices to explore, always pick the one that is alphabetically first. (a) Indicate the pre and post numbers of the nodes. (b) What are the sources and sinks of the graph? (c) What topological ordering is found by the algorithm? (d) How many topological orderings does this graph have? 3.3. Run the DFS-based topological ordering algorithm on the following graph. Whenever you have...
A method sort(a, b, c) will receive 3 parameters a, b, and c, and print a ascending sorted results. For example, sort(3,1,4) will print 1,3,4, sort(- 2,10,3) will return -2,3,10. Draw flowchart diagram to illustrate the algorithm in this method. NOTE: you DON’T have to consider the case that the number of parameters are greater than 3.
In the following graph, write a Java program using Topological Sort. please write java code and show me the output. Thank you :) b.
. Shell sort is a sorting algorithm similar to insertion sort. Research shell sort and apply that to the following array. Show your work in Detail. [15 points] 45 20 50 10 80 30 60 70 40 90 2. Is Shell sort a stable sorting algorithm? Answer this with an example. [10 points] 3. Apply Merge Sort to sort the following list. Show your work in Detail. [15 Points] 45 20 50 10 80 30 60 70 40 90 4....
JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration skill Problem description: Write the following eight methods and write a main function to test these methods // return the index of the first occurrence of key in arr // if key is not found in arra, return -1 public static int linearSearch(int arr[], int key) // sort the arr from least to largest by using select sort algorithm public stati void selectSort(int arr[])...