The.Algorithm.Design.Manual.Springer-Verlag.1998
The.Algorithm.Design.Manual.Springer-Verlag.1998 The.Algorithm.Design.Manual.Springer-Verlag.1998
Lecture 15 - DFS and BFS A topological sort of a graph is an ordering on the vertices so that all edges go from left to right. Only a DAG can have a topological sort. Any DAG has (at least one) topological sort. Listen To Part 17-5 Applications of Topological Sorting Topological sorting is often useful in scheduling jobs in their proper sequence. In general, we can use it to order things given constraints, such as a set of left-right constraints on the positions of objects. Example: Dressing schedule from CLR. Example: Identifying errors in DNA fragment assembly. Certain fragments are constrained to be to the left or right of other fragments, unless there are errors. Solution - build a DAG representing all the left-right constraints. Any topological sort of this DAG is a consistant ordering. If there are cycles, there must be errors. A DFS can test if a graph is a DAG (it is iff there are no back edges - forward edges are allowed for DFS on directed graph). Listen To Part 17-6 file:///E|/LEC/LECTUR16/NODE15.HTM (6 of 8) [19/1/2003 1:35:08]
Lecture 15 - DFS and BFS Algorithm Theorem: Arranging vertices in decreasing order of DFS finishing time gives a topological sort of a DAG. Proof: Consider any directed edge u,v, when we encounter it during the exploration of vertex u: ● If v is white - we then start a DFS of v before we continue with u. ● If v is grey - then u, v is a back edge, which cannot happen in a DAG. ● If v is black - we have already finished with v, so f[v]
- Page 929 and 930: Lecture 9 - catch up Next: Lecture
- Page 931 and 932: Lecture 10 - tree restructuring 1.
- Page 933 and 934: Lecture 10 - tree restructuring Lis
- Page 935 and 936: Lecture 10 - tree restructuring Not
- Page 937 and 938: Lecture 10 - tree restructuring Cas
- Page 939 and 940: Lecture 11 - backtracking Next: Lec
- Page 941 and 942: Lecture 11 - backtracking Only 63 s
- Page 943 and 944: Lecture 11 - backtracking Recursion
- Page 945 and 946: Lecture 11 - backtracking Specifica
- Page 947 and 948: Lecture 12 - introduction to dynami
- Page 949 and 950: Lecture 12 - introduction to dynami
- Page 951 and 952: Lecture 12 - introduction to dynami
- Page 953 and 954: Lecture 12 - introduction to dynami
- Page 955 and 956: Lecture 12 - introduction to dynami
- Page 957 and 958: Lecture 13 - dynamic programming ap
- Page 959 and 960: Lecture 13 - dynamic programming ap
- Page 961 and 962: Lecture 13 - dynamic programming ap
- Page 963 and 964: Lecture 14 - data structures for gr
- Page 965 and 966: Lecture 14 - data structures for gr
- Page 967 and 968: Lecture 14 - data structures for gr
- Page 969 and 970: Lecture 14 - data structures for gr
- Page 971 and 972: Lecture 14 - data structures for gr
- Page 973 and 974: Lecture 14 - data structures for gr
- Page 975 and 976: Lecture 15 - DFS and BFS Next: Lect
- Page 977 and 978: Lecture 15 - DFS and BFS In a DFS o
- Page 979: Lecture 15 - DFS and BFS It could u
- Page 983 and 984: Lecture 16 - applications of DFS an
- Page 985 and 986: Lecture 16 - applications of DFS an
- Page 987 and 988: Lecture 16 - applications of DFS an
- Page 989 and 990: Lecture 17 - minimum spanning trees
- Page 991 and 992: Lecture 17 - minimum spanning trees
- Page 993 and 994: Lecture 17 - minimum spanning trees
- Page 995 and 996: Lecture 17 - minimum spanning trees
- Page 997 and 998: Lecture 17 - minimum spanning trees
- Page 999 and 1000: Lecture 18 - shortest path algorthm
- Page 1001 and 1002: Lecture 18 - shortest path algorthm
- Page 1003 and 1004: Lecture 18 - shortest path algorthm
- Page 1005 and 1006: Lecture 18 - shortest path algorthm
- Page 1007 and 1008: Lecture 18 - shortest path algorthm
- Page 1009 and 1010: Lecture 19 - satisfiability Next: L
- Page 1011 and 1012: Lecture 19 - satisfiability Why? Th
- Page 1013 and 1014: Lecture 19 - satisfiability between
- Page 1015 and 1016: Lecture 19 - satisfiability Note th
- Page 1017 and 1018: Lecture 20 - integer programming Ex
- Page 1019 and 1020: Lecture 20 - integer programming Ne
- Page 1021 and 1022: Lecture 21 - vertex cover Proof: VC
- Page 1023 and 1024: Lecture 21 - vertex cover Question:
- Page 1025 and 1026: Lecture 21 - vertex cover seen to d
- Page 1027 and 1028: Lecture 22 - techniques for proving
- Page 1029 and 1030: Lecture 22 - techniques for proving
Lecture 15 - DFS and BFS<br />
<strong>Algorithm</strong><br />
<strong>The</strong>orem: Arranging vertices in decreasing order of DFS finishing time gives a topological sort of a<br />
DAG.<br />
Proof: Consider any directed edge u,v, when we encounter it during the exploration of vertex u:<br />
● If v is white - we then start a DFS of v before we continue with u.<br />
● If v is grey - then u, v is a back edge, which cannot happen in a DAG.<br />
● If v is black - we have already finished with v, so f[v]