SlideShare a Scribd company logo
1 of 40
TOPOLOGICAL SORT
DONE BY
D.STELLA
A.SHEREEN FATHIMA
ALGORITHM ANALYSIS LAB(CSB3105)
B.S.ABDUR RAHMAN UNIVERSITY
Overview
To be discussed in the presentation
❖Preface
❖Problem Statement
❖What is Topological Sorting
❖Visual Representation
❖The problem to be solved
❖The algorithm behind it
❖Algorithm Analysis
❖Result
PREFACE
Problem
Description
Student
Activities
Topological
sort
Algorithm of
topology
sorting
Complexity
Of an algorithm
1.Students have various activities to be done
everyday.
2.Such activities range from studying to eating to
napping and so on.
3.The major problem; How can all these activities
be achieved, along with time management and
also organization and optimization of the
activities.
PROBLEM STATEMENT
WHICH IDEAL ALGORITHM
IS USED TO SORT THE
STUDENT ACTIVITIES?
Topological Sort
Define
A topological sort or
topological ordering of a
directed graph is a linear
ordering of its vertices such
that for every directed edge uv
from vertex u to vertex v, u
comes before v in the
ordering.
Topological
sorting algorithm
Technically
Done in a way that for every
edge ab from vertex a to b, the
vertex a comes before the vertex b
in the topological ordering.
In other words, the topological
sorting of a Directed Acyclic
Graph is linear ordering of all of
its vertices.
ALGORITHM FOR TOPOLOGICAL SORT
- Compute the indegrees of all vertices
- Find a vertex U with indegree 0 and print it (store it in the
ordering)If there is no such vertex then there is a cycle and the
vertices cannot be ordered. Stop.
- Remove U and all its edges (U,V) from the graph.
- Update the indegrees of the remaining vertices.
- Repeat steps 2 through 4 while there are vertices to be processed
Representation
Consider this
1 2
4 5
76
3
Indegrees
0: 1, 2
1: 5
2: 3, 6, 7
3: 4
- Select 1
1 2
4 5
76
3
1
Indegrees
0: 1, 2
1: 5
2: 3, 6, 7
3: 4
- Select 1, 2
1 2
4 5
76
3
1 2
Indegrees
0: 1, 2
1: 5
2: 3, 6, 7
3: 4
- Select 1, 2, 5
1 2
4 5
76
3
1 2 5
Indegrees
0: 1, 2
1: 5
2: 3, 6, 7
3: 4
- Select 1, 2, 5, 4
1 2
4 5
76
3
1 2 5 4
Indegrees
0: 1, 2
1: 5
2: 3, 6, 7
3: 4
- Select 1, 2, 5, 4, 3
1 2
4 5
76
3
1 2 5 4 3
Indegrees
0: 1, 2
1: 5
2: 3, 6, 7
3: 4
- Select 1, 2, 5, 4, 3, 6
1 2
4 5
76
3
1 2 5 4 3 6
Indegrees
0: 1, 2
1: 5
2: 3, 6, 7
3: 4
- Select 1, 2, 5, 4, 3, 6, 7
1 2
4 5
76
3
1 2 5 4 3 6 7
Topologically
sorted
1 2
4 5
76
3
1 2 5 4 3 6 7
Student
Activity
Optimization
These are the list of activities
performed by the student.
They need to be ordered to
enhance time management of the
student and increase the
optimization of the activities
done.
Hence, this problem is named as
“Student Activity Organization”
The activities are drawn
into nodes and the
entire activity chart is
made into a Graph
ALGORITHM FOR TOPOLOGICAL SORT
1. Compute the indegrees of all activity vertices
2. Find an activity vertex x with indegree 0 and print it (store it
in the queue).
3. If there is no such vertex then there is a cycle and the vertices
cannot be ordered. Stop.
4. Remove x and all its edges (U,V) from the graph.
5. Update the indegrees of the remaining activity vertices.
6. Repeat steps 2 through 4 while there are activity vertices to be
processed.
QUEUE
QUEUE
2
QUEUE
QUEUE
QUEUE
QUEUE
QUEUE
QUEUE
QUEUE
QUEUE
QUEUE
QUEUE
Optimized
Student Activities
1. Wake up
2. Study ADA
3. Nap
4. Breakfast
5. Study Program
1 2 3 4 5 6 7 8 9 10 11
6. Workout
7. At College
8. Attend class
9. Play
10. Sleep
11. Dream
TOPOLOGICAL SORT
ALGORITHM ANALYSIS
1. Store each vertex’s In-degree
in an array.
2.While there are vertices remaining:
• Find a vertex with In-degree zero
and output it
• Reduce In-degree of all vertices
adjacent to it by 1
3.This algorithm running time will be a
quardratic time.
COMPLEXITY OF AN ALGORITHM
For input graph G = (V,E), Run Time = ?
Break down into total time required to:
§ Initialize In-Degree array: O(|E|)
§ Find vertex with in-degree 0:|V| vertices, each takes O(|V|) to search In-Degree array.
§ Reduce In-Degree of all vertices adjacent to a vertex: O(|E|)
§ Output and mark vertex:O(|V|)
§ Total time = O(|V|²)
§ Total time= O(|V|² + |E|) Quadratic time!
Topological sort (using array along with queue)
1.Store each vertex’s In-Degree in an array
2. Initialize queue with all “in-degree=0” vertices
3. While there are vertices remaining in the
queue:
(a) Dequeue and output a vertex
(b) Reduce In-Degree of all vertices adjacent to it by 1
(c) Enqueue any of these vertices whose In-Degree
became zero
4. If all vertices are output then success,
otherwise there is a cycle.
1. Complexity of an algorithm
Initialize In-Degree array: O(|V| + |E|)
Initialize Queue with In-Degree 0 vertices: O(|V|)
Dequeue and output vertex:
› |V| vertices, each takes only O(1) to dequeue and
output: O(|V|)
Reduce In-Degree of all vertices adjacent to a vertex
and Enqueue any In-Degree 0 vertices:
› O(|E|)
For input graph G=(V,E) run time = O(|V| + |E|)
Linear time
39
Thus students activities has been ordered
in
a short complexity time O (V+E)
THANK YOU

More Related Content

Similar to Topological Sort Algorithm Optimizes Student Activities

Topological Sort Algorithm.pptx
Topological Sort Algorithm.pptxTopological Sort Algorithm.pptx
Topological Sort Algorithm.pptxMuhammadShafi89
 
Analysis of Algorithms - 3
Analysis of Algorithms - 3Analysis of Algorithms - 3
Analysis of Algorithms - 3AtakanAral
 
Deep Learning in Recommender Systems - RecSys Summer School 2017
Deep Learning in Recommender Systems - RecSys Summer School 2017Deep Learning in Recommender Systems - RecSys Summer School 2017
Deep Learning in Recommender Systems - RecSys Summer School 2017Balázs Hidasi
 
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...Pierre Schaus
 
AI-04 Production System - Search Problem.pptx
AI-04 Production System - Search Problem.pptxAI-04 Production System - Search Problem.pptx
AI-04 Production System - Search Problem.pptxPankaj Debbarma
 
Ai2418281871
Ai2418281871Ai2418281871
Ai2418281871IJMER
 
Data Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search AlgorithmsData Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search AlgorithmsFerdin Joe John Joseph PhD
 
Array sorting
Array sortingArray sorting
Array sortingALI RAZA
 
K means cluster ML
K means cluster  MLK means cluster  ML
K means cluster MLBangalore
 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfAkashSingh625550
 
Classification decision tree
Classification  decision treeClassification  decision tree
Classification decision treeyazad dumasia
 
Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxssuser01e301
 
Ee184405 statistika dan stokastik statistik deskriptif 2 numerik
Ee184405 statistika dan stokastik   statistik deskriptif 2 numerikEe184405 statistika dan stokastik   statistik deskriptif 2 numerik
Ee184405 statistika dan stokastik statistik deskriptif 2 numerikyusufbf
 
Time Table Management system
Time Table Management systemTime Table Management system
Time Table Management systemShaswat Lovee
 
Improved Teaching Leaning Based Optimization Algorithm
Improved Teaching Leaning Based Optimization AlgorithmImproved Teaching Leaning Based Optimization Algorithm
Improved Teaching Leaning Based Optimization Algorithmrajani51
 
10. Introduction to Datastructure
10. Introduction to Datastructure10. Introduction to Datastructure
10. Introduction to DatastructureNilesh Dalvi
 

Similar to Topological Sort Algorithm Optimizes Student Activities (20)

Topological Sort Algorithm.pptx
Topological Sort Algorithm.pptxTopological Sort Algorithm.pptx
Topological Sort Algorithm.pptx
 
Analysis of Algorithms - 3
Analysis of Algorithms - 3Analysis of Algorithms - 3
Analysis of Algorithms - 3
 
Gram-Schmidt process
Gram-Schmidt processGram-Schmidt process
Gram-Schmidt process
 
Deep Learning in Recommender Systems - RecSys Summer School 2017
Deep Learning in Recommender Systems - RecSys Summer School 2017Deep Learning in Recommender Systems - RecSys Summer School 2017
Deep Learning in Recommender Systems - RecSys Summer School 2017
 
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...
One Problem, Two Structures, Six Solvers and Ten Years of Personnel Schedulin...
 
AI-04 Production System - Search Problem.pptx
AI-04 Production System - Search Problem.pptxAI-04 Production System - Search Problem.pptx
AI-04 Production System - Search Problem.pptx
 
Ai2418281871
Ai2418281871Ai2418281871
Ai2418281871
 
Sortings .pptx
Sortings .pptxSortings .pptx
Sortings .pptx
 
Data Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search AlgorithmsData Structures and Algorithm - Week 9 - Search Algorithms
Data Structures and Algorithm - Week 9 - Search Algorithms
 
Array sorting
Array sortingArray sorting
Array sorting
 
K means cluster ML
K means cluster  MLK means cluster  ML
K means cluster ML
 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdf
 
Classification decision tree
Classification  decision treeClassification  decision tree
Classification decision tree
 
Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptx
 
2ND COT.pptx
2ND COT.pptx2ND COT.pptx
2ND COT.pptx
 
Ee184405 statistika dan stokastik statistik deskriptif 2 numerik
Ee184405 statistika dan stokastik   statistik deskriptif 2 numerikEe184405 statistika dan stokastik   statistik deskriptif 2 numerik
Ee184405 statistika dan stokastik statistik deskriptif 2 numerik
 
Time Table Management system
Time Table Management systemTime Table Management system
Time Table Management system
 
Improved Teaching Leaning Based Optimization Algorithm
Improved Teaching Leaning Based Optimization AlgorithmImproved Teaching Leaning Based Optimization Algorithm
Improved Teaching Leaning Based Optimization Algorithm
 
10. Introduction to Datastructure
10. Introduction to Datastructure10. Introduction to Datastructure
10. Introduction to Datastructure
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 

Recently uploaded

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 

Recently uploaded (20)

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 

Topological Sort Algorithm Optimizes Student Activities

  • 1. TOPOLOGICAL SORT DONE BY D.STELLA A.SHEREEN FATHIMA ALGORITHM ANALYSIS LAB(CSB3105) B.S.ABDUR RAHMAN UNIVERSITY
  • 2. Overview To be discussed in the presentation ❖Preface ❖Problem Statement ❖What is Topological Sorting ❖Visual Representation ❖The problem to be solved ❖The algorithm behind it ❖Algorithm Analysis ❖Result
  • 4. 1.Students have various activities to be done everyday. 2.Such activities range from studying to eating to napping and so on. 3.The major problem; How can all these activities be achieved, along with time management and also organization and optimization of the activities. PROBLEM STATEMENT
  • 5. WHICH IDEAL ALGORITHM IS USED TO SORT THE STUDENT ACTIVITIES?
  • 6. Topological Sort Define A topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge uv from vertex u to vertex v, u comes before v in the ordering.
  • 7. Topological sorting algorithm Technically Done in a way that for every edge ab from vertex a to b, the vertex a comes before the vertex b in the topological ordering. In other words, the topological sorting of a Directed Acyclic Graph is linear ordering of all of its vertices.
  • 8. ALGORITHM FOR TOPOLOGICAL SORT - Compute the indegrees of all vertices - Find a vertex U with indegree 0 and print it (store it in the ordering)If there is no such vertex then there is a cycle and the vertices cannot be ordered. Stop. - Remove U and all its edges (U,V) from the graph. - Update the indegrees of the remaining vertices. - Repeat steps 2 through 4 while there are vertices to be processed
  • 10. Indegrees 0: 1, 2 1: 5 2: 3, 6, 7 3: 4 - Select 1 1 2 4 5 76 3 1
  • 11. Indegrees 0: 1, 2 1: 5 2: 3, 6, 7 3: 4 - Select 1, 2 1 2 4 5 76 3 1 2
  • 12. Indegrees 0: 1, 2 1: 5 2: 3, 6, 7 3: 4 - Select 1, 2, 5 1 2 4 5 76 3 1 2 5
  • 13. Indegrees 0: 1, 2 1: 5 2: 3, 6, 7 3: 4 - Select 1, 2, 5, 4 1 2 4 5 76 3 1 2 5 4
  • 14. Indegrees 0: 1, 2 1: 5 2: 3, 6, 7 3: 4 - Select 1, 2, 5, 4, 3 1 2 4 5 76 3 1 2 5 4 3
  • 15. Indegrees 0: 1, 2 1: 5 2: 3, 6, 7 3: 4 - Select 1, 2, 5, 4, 3, 6 1 2 4 5 76 3 1 2 5 4 3 6
  • 16. Indegrees 0: 1, 2 1: 5 2: 3, 6, 7 3: 4 - Select 1, 2, 5, 4, 3, 6, 7 1 2 4 5 76 3 1 2 5 4 3 6 7
  • 18. Student Activity Optimization These are the list of activities performed by the student. They need to be ordered to enhance time management of the student and increase the optimization of the activities done. Hence, this problem is named as “Student Activity Organization”
  • 19. The activities are drawn into nodes and the entire activity chart is made into a Graph
  • 20. ALGORITHM FOR TOPOLOGICAL SORT 1. Compute the indegrees of all activity vertices 2. Find an activity vertex x with indegree 0 and print it (store it in the queue). 3. If there is no such vertex then there is a cycle and the vertices cannot be ordered. Stop. 4. Remove x and all its edges (U,V) from the graph. 5. Update the indegrees of the remaining activity vertices. 6. Repeat steps 2 through 4 while there are activity vertices to be processed.
  • 21.
  • 22. QUEUE
  • 24. QUEUE
  • 25. QUEUE
  • 26. QUEUE
  • 28. QUEUE
  • 29. QUEUE
  • 30. QUEUE
  • 31. QUEUE
  • 32. QUEUE
  • 33. Optimized Student Activities 1. Wake up 2. Study ADA 3. Nap 4. Breakfast 5. Study Program 1 2 3 4 5 6 7 8 9 10 11 6. Workout 7. At College 8. Attend class 9. Play 10. Sleep 11. Dream
  • 35. 1. Store each vertex’s In-degree in an array. 2.While there are vertices remaining: • Find a vertex with In-degree zero and output it • Reduce In-degree of all vertices adjacent to it by 1 3.This algorithm running time will be a quardratic time.
  • 36. COMPLEXITY OF AN ALGORITHM For input graph G = (V,E), Run Time = ? Break down into total time required to: § Initialize In-Degree array: O(|E|) § Find vertex with in-degree 0:|V| vertices, each takes O(|V|) to search In-Degree array. § Reduce In-Degree of all vertices adjacent to a vertex: O(|E|) § Output and mark vertex:O(|V|) § Total time = O(|V|²) § Total time= O(|V|² + |E|) Quadratic time!
  • 37. Topological sort (using array along with queue) 1.Store each vertex’s In-Degree in an array 2. Initialize queue with all “in-degree=0” vertices 3. While there are vertices remaining in the queue: (a) Dequeue and output a vertex (b) Reduce In-Degree of all vertices adjacent to it by 1 (c) Enqueue any of these vertices whose In-Degree became zero 4. If all vertices are output then success, otherwise there is a cycle.
  • 38. 1. Complexity of an algorithm Initialize In-Degree array: O(|V| + |E|) Initialize Queue with In-Degree 0 vertices: O(|V|) Dequeue and output vertex: › |V| vertices, each takes only O(1) to dequeue and output: O(|V|) Reduce In-Degree of all vertices adjacent to a vertex and Enqueue any In-Degree 0 vertices: › O(|E|) For input graph G=(V,E) run time = O(|V| + |E|) Linear time
  • 39. 39 Thus students activities has been ordered in a short complexity time O (V+E)