How to resolve the algorithm Topological sort step by step in the UNIX Shell programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Topological sort step by step in the UNIX Shell programming language

Table of Contents

Problem Statement

Given a mapping between items, and items they depend on, a topological sort orders items so that no item precedes an item it depends upon. The compiling of a library in the VHDL language has the constraint that a library must be compiled after any library it depends on. A tool exists that extracts library dependencies.

Write a function that will return a valid compile order of VHDL libraries from their dependencies.

Use the following data as an example:

Note: the above data would be un-orderable if, for example, dw04 is added to the list of dependencies of dw01.

There are two popular algorithms for topological sorting:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Topological sort step by step in the UNIX Shell programming language

Source code in the unix programming language

$ awk '{ for (i = 1; i <= NF; i++) print $i, $1 }' <
> des_system_lib   std synopsys std_cell_lib des_system_lib dw02 dw01 ramlib ieee
> dw01             ieee dw01 dware gtech
> dw02             ieee dw02 dware
> dw03             std synopsys dware dw03 dw02 dw01 ieee gtech
> dw04             dw04 ieee dw01 dware gtech
> dw05             dw05 ieee dware
> dw06             dw06 ieee dware
> dw07             ieee dware
> dware            ieee dware
> gtech            ieee gtech
> ramlib           std ieee
> std_cell_lib     ieee std_cell_lib
> synopsys         
> !
ieee
dware
dw02
dw05
dw06
dw07
gtech
dw01
dw04
std_cell_lib
synopsys
std
dw03
ramlib
des_system_lib


  

You may also check:How to resolve the algorithm Combinations with repetitions step by step in the Elixir programming language
You may also check:How to resolve the algorithm Equilibrium index step by step in the Prolog programming language
You may also check:How to resolve the algorithm Draw a clock step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the Scheme programming language
You may also check:How to resolve the algorithm Program termination step by step in the TI-89 BASIC programming language