Assignment 1
Assignment 1
Assignment 1
CCCS 314 Design and Analysis of Algorithms
Fall 2025
Instructions:
The assignment must be submitted before the allocated Date/Time.
The assignment must by uploaded on LMS / sent by email to [email protected].
Plagiarism will be punished according to university rules.
1/7
Question 1: [PLO S1 / CLO 2.1] [5 marks]
Write a 1000 to 1500 word report on Topological Sorting and what kind of problems
can be solved using this method.
2/7
2. Algorithms for Topological Sorting
There are two main algorithms for computing a topological sort
in a DAG: Kahn's Algorithm and the Depth-First Search (DFS)
Approach. Each algorithm takes a different approach to organizing
the graph into a topologically sorted order.
3/7
Time Complexity: Like Kahn's Algorithm, the DFS-based approach
also runs in O(V+E), making it similarly efficient.
4/7
3.3 Dependency Resolution in Package Managers
In programming environments, package managers (e.g., npm for
JavaScript or apt for Linux) use topological sorting to manage
dependencies among packages. Before installing a package, its
dependencies must be installed first. A topological sort determines
the correct order for installation, preventing missing dependencies.
Example: In a digital circuit with gates G1, G2, and G3, where
G3 depends on G2, and G2 on G1, a topological sort yields an order
like G1 → G2 → G3, ensuring signals propagate in the right order.
5/7
3.6 Data Serialization in Databases
In databases, data serialization involves saving and restoring data
structures with dependencies. Tables with foreign key constraints
need to be serialized in a specific order to maintain referential
integrity. Topological sorting provides a way to determine this order,
ensuring that referenced data is created before the data that depends
on it.
5. Example Problem
Problem: Given n tasks with dependencies, determine if it is
possible to complete all tasks. If so, provide a completion order.
Solution:
1. Represent tasks as nodes and dependencies as directed edges in a
DAG.
6/7
2. Use Kahn's algorithm or the DFS-based method to perform a
topological sort.
3. If the topological sort includes all nodes, a valid order exists;
otherwise, there is a cycle, and completing all tasks is impossible.
4.
6. Conclusion
Topological sorting is a key tool in algorithm design and analysis,
offering efficient solutions to ordering problems in directed acyclic
graphs. Its applications span project management, academic planning,
dependency management, circuit design, and more. Although it
requires a DAG and does not handle cycles, topological sorting’s linear
time complexity and versatility make it a powerful method in both
theoretical and practical computer science.
7/7