1-TopsortChptr

# 1-TopsortChptr - Topological Sorting Background Topological...

This preview shows pages 1–3. Sign up to view the full content.

Topological Sorting Background Topological sorting requires ranking a set of objects subject to constraints on the resultant topology--that is, on the placement of the objects. It occurs in many practical situations. For example, textbooks are often written so that each chapter builds on material covered earlier and cannot be understood without this base of information. Determining the order in which to present topics to ensure that all prerequisite material has been covered reduces to finding a topological sort of the topics. Other examples involving topological sorting are presented later. The approach to the topological sorting problem presented in this chapter and the characteristics of the final program are intended to serve as prototypes. The problem is substantial and the algorithm developed important, but it is the process by which it is achieved that is most important. Developing an efficient topological sorting program is a complex process and demonstrates the general problem solving methodology used in this text. It requires the application of structured programming concepts, during which the selection of data structures plays a significant role. The resultant topological sorting program is a model solution, representing nearly the best programmers can hope to achieve. Few solutions to problems have all its characteristics. It is concise and clear; correctness is easy to determine; and the storage and execution time requirements can be analyzed. Invalid input data are not difficult to deal with. What more can we ask? The following are some examples of problems whose solutions require topological sorting. Example 1 A large skyscraper is to be constructed. Imagine that you must write a program to prescribe the order in which all the tasks are to be performed. The tasks include T 3 --install windows; T 50 --install floors; T 8 --install window sashes; T 1000 --clear the ground; T 7 --build the foundation; T 9 --install doors. For any two tasks, it is possible to specify whether one should be done before the other. Clearly, T 8 must be done before T 3 , and T 1000 must be done before T 7 , while it makes no difference whether or not T 3 is done before T 9 . The constraint that T i be done before T j is represented as the pair ( i , j ). Example 2 Imagine that you want to write a book on data structures. All technical words used must be defined. First write down all the relevant words. If word w j uses w i in its definition, represent this constraint by the pair ( i , j ). Example 3 As a student you must take a number of courses to graduate. Represent the fact that course c j has course c i as a prerequisite by the pair ( i , j ).

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example 4 A number of books must be read for a course you are taking. Represent the fact that you prefer to read book i before book j by the pair ( i , j ).
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern