0% found this document useful (0 votes)
32 views

UNIT-3

The document outlines the B.Tech course in Design and Analysis of Algorithms at Chandigarh College of Engineering, detailing the vision, mission, program educational objectives, outcomes, and course outcomes. It includes a syllabus covering various algorithms such as graph traversal, shortest path, and transitive closure, along with references for further reading. The course aims to equip students with essential skills and knowledge to address real-world engineering problems and foster lifelong learning.

Uploaded by

Navjot Dhadli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

UNIT-3

The document outlines the B.Tech course in Design and Analysis of Algorithms at Chandigarh College of Engineering, detailing the vision, mission, program educational objectives, outcomes, and course outcomes. It includes a syllabus covering various algorithms such as graph traversal, shortest path, and transitive closure, along with references for further reading. The course aims to equip students with essential skills and knowledge to address real-world engineering problems and foster lifelong learning.

Uploaded by

Navjot Dhadli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Chandigarh College of Engineering, Jhanjeri

Department of Computer Science & Engineering

Program Name: B.Tech


Course Code: BTCS403-18
Course Name: Design and Analysis of Algorithms

Prepared by: Ms. Navjot Kaur

Department of Computer Science & Engineering


Outlines
• Vision, Mission
• PO, PEOs
• CO
• Course Objective
• PTU Syllabus
• Topic
• References
Institute V/M & Department’s V/M
Institute Vision
1 To emerge as Institution of Technical excellence imparting professional education for sustainable development of society.
Department Vision
1 To provide imperative skills to students for meeting industry needs, and to become responsible engineers, entrepreneurs and
citizens.
Institute Mission
1 To provide quality technical education through state-of-the-art infrastructure and well qualified and experienced faculty.
2 Having academic flexibility through strong industry academia interactions.
3 Focus on students' employability, entrepreneurship, higher education and competitive examination.
4 Inculcate ethical and moral values in students.
Department Mission
1 To educate the students in the field of Computer-Science with ever-changing technologies and skill
2 To enable the students in solving real-time problems and make use of new technologies.
3 To have industry collaboration and interaction with professional societies for continuous development.
4 To help students in becoming successful entrepreneurs.

Department of Computer Science & Engineering 3


Program Educational Objectives (PEOs)
• Describe the career and professional accomplishments that the programme would prepare the graduates to achieve in a few years after their graduation.
• Our graduated students are expected to fulfill the following Program Educational Objectives (PEOs):
1) Core Competency: Successfully apply fundamental mathematical, scientific, and engineering principles in formulating and solving engineering
and real life problems for betterment of society.
2) Breadth: Will apply current industry accepted practices, new and emerging technologies to analyse, design, implement and maintain state of art
solutions.
3) Professionalism: Work effectively and ethically in ever changing global professional environment and multi-disciplinary environment.
4) Learning Environment: Demonstrate excellent communication and soft skills to fulfil their commitment towards social responsibilities and
foster life-long learning.
5) Preparation: Promote research and patenting to enhance technical and entrepreneurship skills within them.
Sr. No. Detail Revised Blooms’
Taxonomy Domain
1 Become Competent Computer Professionals. Apply
2 Have abilities to analyze the requirements of software and provide solutions through efficient product design. Analyze

3 Have successful career and meet the requirements of Indian and other Multi-National Companies. Higher order Thinking

4 Have exposure to advanced technologies, technical skills and opportunities to work as team members on Understand
multidisciplinary projects.

Department of Computer Science & Engineering 4


Program Outcomes & Program Specific Outcomes
Sr. No. Detail
PO1 Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an engineering specialization to the solution of complex engineering
problems.
PO2 Problem analysis: Identify, formulate, review research literature, and analyze complex engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
PO3 Design/development of solutions: Design solutions for complex engineering problems and design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental considerations.
PO4 Conduct investigations of complex problems: Use research-based knowledge and research methods including design of experiments, analysis and interpretation of data, and synthesis
of the information to provide valid conclusions.
PO5 Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools including prediction and modeling to complex engineering
activities with an understanding of the limitations.
PO6 The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
PO7 Environment and sustainability: Understand the impact of the professional engineering solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.
PO8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering practice.
PO9 Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams, and in multidisciplinary settings.
Communication: Communicate effectively on complex engineering activities with the engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive clear instructions.
PO10
Project management and finance: Demonstrate knowledge and understanding of the engineering and management principles and apply these to one’s own work, as a member and
PO11 leader in a team, to manage projects and in multidisciplinary environments.
Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent and life-long learning in the broadest context of technological change.
PO12
Students shall demonstrate skills, the knowledge and competence in the analysis, design and development of computer based systems addressing industrial and social issues.
PSO1
Students shall have competence to take challenges associated with future technological issues associated with security, wearable devices, augmented reality, Internet of Anything etc.
PSO2
Department of Computer Science & Engineering 5
Course Outcomes
CO Number Outcomes

CO1 Understand functional block diagram of microprocessor.

CO2 Apply instruction set for Writing assembly language programs.

CO3 Design a memory module and analyze its operation by interfacing with the CPU.

CO4 Classify hardwired and microprogrammed control units.

CO5 Understand the concept of pipelining and its performance metrics.

Department of Computer Science & Engineering 6


COURSE BOOKS
T
/ BOOK TITLE/AUTHORS/PUBLICATION
R

1
Fundamentals of Computer Algorithms – E. Horowitz, Sartaj Saini,
Galgotia Publications

2
Introduction to Algorithms, 4TH Edition, Thomas H Cormen, Charles
E Lieserson, Ronald L Rivest and Clifford Stein, MIT Press/McGraw-
Hill
3
Data Structures and Algorithms in C++, Weiss, 4 th edition, Pearson.
4
Algorithm Design, 1stEdition, Jon Kleinberg and ÉvaTardos, Pearson.

Department of Computer Applications 7


PTU Syllabus of Unit-3

Module3:
Graph and Tree Algorithms: Traversal algorithms: Depth First Search (DFS) and Breadth First Search (BFS);
Shortest path algorithms, Transitive closure, Minimum Spanning Tree, Topological sorting, Network Flow
Algorithm.
[10 hrs] (CO3)
BFS-LEVEL ORDER GRAPH
• BFS is implemented with the help of Queue:Let the traversal begins at Node A which is assigned a distance
value of “1”.
• Now the nodes adjacent to “A” are B,D and C.

• B is visited first and assigned a distance value of “2”.and the nodes adjacent to B are E and D.
• After B,
• D is visited next and the nodes adjacent to D are B,E and C.the node B is already visited so node C will be visited next.
• The nodes adjacent to C are A,B and D which are already visited.
• Hence Node E will be visited and assigned a value of 2
Algo: BST(G,A)
Given a graph”G”.This algo executes BFS beginning at a starting node “A”.
The variable STATUS tells us the current status of a node “Q” which is the name of
the queue.
1)Initialize all nodes to the ready state.
• Set status =0 to all nodes of the graph”G”.
2)Initialize first node and put it in queue “Q”
• A)Insert starting node A in queueQ
• B)Set STATUS=1(Waiting State)for Node A.
3)Repeat steps4 and 5 until queue “Q” is empty
4)A)remove the first nide,say N of Queue
• B) Process Node “N”
5)Add all the neighbours of N in queue
• A) Insert all the neighbours of N in the Queue
• B)Change STATUS=2(Waiting State) of all the neighbours of N
6)Exit
DFS (Depth First Search)

The depth-first search (DFS) algorithm starts with the initial node of graph G and goes deeper until we find the goal node or the
node with no children.

The step by step process to implement the DFS traversal is given as follows -
1. First, create a stack with the total number of vertices in the graph.
2. Now, choose any vertex as the starting point of traversal, and push that vertex into the stack.
3. After that, push a non-visited vertex (adjacent to the vertex on the top of the stack) to the top of the stack.
4. Now, repeat steps 3 and 4 until no vertices are left to visit from the vertex on the stack's top.
5. If no vertex is left, go back and pop a vertex from the stack.
6. Repeat steps 2, 3, and 4 until the stack is empty.
Step 1 - First, push H onto the stack.
STACK: H
Step 2 - POP the top element from the stack, i.e., H, and print
it. Now, PUSH all the neighbors of H onto the stack that are in
ready state.

Print: H]STACK: A

Step 3 - POP the top element from the stack, i.e., A, and print it.
Now, PUSH all the neighbors of A onto the stack that are in
ready state.
Print: A
STACK: B, D

Step 4 - POP the top element from the stack, i.e., D, and print
it. Now, PUSH all the neighbors of D onto the stack that are in
ready state.

Print: D
STACK: B, F
Step 5 - POP the top element from the stack, i.e., F, and print it. Now, PUSH all the neighbors of F onto the stack that are in
ready state.
Print: F
STACK: B
Step 6 - POP the top element from the stack, i.e., B, and print it. Now, PUSH all the neighbors of B onto the stack that are in
ready state.
Print: B
STACK: C
Step 7 - POP the top element from the stack, i.e., C, and print it. Now, PUSH all the neighbors of
C onto the stack that are in ready state
Print: C
STACK: E, G
Step 8 - POP the top element from the stack, i.e., G and PUSH all the neighbors of G onto the
stack that are in ready state.
Print: G
STACK: E
Step 9 - POP the top element from the stack, i.e., E and PUSH all the neighbors of E onto the stack
that are in ready state.
1.Print: E
2.STACK:
ALGO:DFT(G,A)
Given a Graph “G”.“A” is the starting node for traversal. The variable “STATUS” tells us the current status of a node”S” is the name of
Stack.
1) Initialize all nodes to the ready state.
Set STATUS=1 to all node of graph “G”
2) Initialize first node and put it in the stack”s”
A) Push the starting node A onto stack “S”
B) Set STATUS =2(WAITING STATE) for node “A”.
3)Repeat Step 3 & 4 until stack “S” is empty
4) Process the TOP node of stack”S”
A) POP the top node, say N of “S”
B) Process the node “N”
C)Set STATUS=3(Processed state) of node “N”
5)Add all the neighbour of N in stack
A)Push all the neighbours of N onto stack
B) Change STATUS=2(WAITING STATE) of all the neighbours of N
Shortest path algorithm

The shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the
weights of its constituent edges is minimized.
The problem of finding the shortest path between two intersections on a road map may be modeled as a special case of the
shortest path problem in graphs, where the vertices correspond to intersections and the edges correspond to road segments, each
weighted by the length or distance of each segment.
How to find Shortest Paths from Source to all Vertices using Dijkstra’s Algorithm

Given a weighted graph and a source vertex in the graph, find the shortest paths from the source to all the other vertices in
the given graph.

Note: The given graph does not contain any negative edge.
Examples:
Input: src = 0, the graph is shown below.
Algorithm :

• Create a set sptSet (shortest path tree set) that keeps track of vertices included in the shortest path tree, i.e.,
whose minimum distance from the source is calculated and finalized. Initially, this set is empty.

• Assign a distance value to all vertices in the input graph. Initialize all distance values as INFINITE . Assign the
distance value as 0 for the source vertex so that it is picked first.

• While sptSet doesn’t include all vertices

• Pick a vertex u that is not there in sptSet and has a minimum distance value.
• Include u to sptSet .
• Then update the distance value of all adjacent vertices of u .
• To update the distance values, iterate through all adjacent vertices.
• For every adjacent vertex v, if the sum of the distance value of u (from source) and weight of edge u-v ,
is less than the distance value of v , then update the distance value of v .
Illustration of Dijkstra Algorithm :
To understand the Dijkstra’s Algorithm lets take a graph and find the shortest path from source to all nodes.

Consider below graph and src = 0

Step 1:

• The set sptSet is initially empty and distances assigned to vertices are {0, INF, INF, INF, INF, INF, INF, INF} where
INF indicates infinite.
• Now pick the vertex with a minimum distance value. The vertex 0 is picked, include it in sptSet . So sptSet becomes
{0}. After including 0 to sptSet , update distance values of its adjacent vertices.

• Adjacent vertices of 0 are 1 and 7. The distance values of 1 and 7 are updated as 4 and 8.
• The following subgraph shows vertices and their distance values, only the vertices with finite distance values
are shown. The vertices included in SPT are shown in green colour.
Step 2:
• Pick the vertex with minimum distance value and not already included in SPT (not in sptSET ). The vertex 1 is picked
and added to sptSet .So sptSet now becomes {0, 1}. Update the distance values of adjacent vertices of 1. The distance
value of vertex 2 becomes 12 .
Step 3:

• Pick the vertex with minimum distance value and not already included in SPT (not in sptSET ). Vertex 7 is
picked. So sptSet now becomes {0, 1, 7}.

• Update the distance values of adjacent vertices of 7. The distance value of vertex 6 and 8 becomes finite ( 15
and 9 respectively).
Step 4:

• Pick the vertex with minimum distance value and not already included in SPT (not in sptSET ). Vertex 6 is
picked. So sptSet now becomes {0, 1, 7, 6} .

• Update the distance values of adjacent vertices of 6. The distance value of vertex 5 and 8 are updated.
• We repeat the above steps until sptSet includes all vertices of the given graph. Finally, we get the following S hortest
Path Tree (SPT).
Transitive Closure

In graph theory, transitive closure is the process of constructing a new graph from an input graph, where the new graph
has an edge between two nodes if there is a directed path between them in the input graph.
Transitive closure is used to answer reachability questions, such as whether it's possible to get from one node to another in
one or more hops. The transitive closure is usually stored as a Boolean matrix, where a value of 1 indicates that a node can
reach another node, and a value of 0 indicates that there is no connection.
Transitive Closure it the reachability matrix to reach from vertex u to vertex v of a graph. One graph is given,
we have to find a vertex v which is reachable from another vertex u, for all vertex pairs (u, v).

The final matrix is the Boolean type. When there is a value 1 for vertex u to vertex v, it means that there is at least one path
from u to v.
Transitive closure of a graph using Floyd Warshall Algorithm
Given a directed graph, determine if a vertex j is reachable from another
vertex i for all vertex pairs (i, j) in the given graph. Here reachable means
that there is a path from vertex i to j. The reach-ability matrix is called the
transitive closure of a graph.
Transitive closure of a graph
1 1 1 1
1 1 1 1
1 1 1 1
0 0 0 1

The graph is given in the form of adjacency matrix say ‘graph[V][V]’ where graph[i][j]
is 1 if there is an edge from vertex i to vertex j or i is equal to j, otherwise graph[i][j] is
0.
Floyd Warshall Algorithm can be used, we can calculate the distance matrix dist[V][V]
using Floyd Warshall, if dist[i][j] is infinite, then j is not reachable from i. Otherwise, j
is reachable and the value of dist[i][j] will be less than V
Minimum Spanning Tree
A spanning tree is defined as a tree-like subgraph of a connected, undirected graph that includes all the vertices of the graph. Or, to say in
Layman’s words, it is a subset of the edges of the graph that forms a tree (acyclic) where every node of the graph is a part of the tree.
The minimum spanning tree has all the properties of a spanning tree with an added constraint of having the minimum possible weights
among all possible spanning trees. Like a spanning tree, there can also be many possible MSTs for a graph.
Properties of a Spanning Tree:
• The spanning tree holds the below-mentioned principles:
• The number of vertices (V) in the graph and the spanning tree is the same.
• There is a fixed number of edges in the spanning tree which is equal to one less than the total number of vertices ( E = V-1 ).
• The spanning tree should not be disconnected, as in there should only be a single source of component, not more than that.
• The spanning tree should be acyclic, which means there would not be any cycle in the tree.
• The total cost (or weight) of the spanning tree is defined as the sum of the edge weights of all the edges of the spanning tree.
• There can be many possible spanning trees for a graph.
Minimum Spanning Tree

• A minimum spanning tree (MST) is defined as a spanning tree that has the minimum weight among all the possible
spanning trees.
• The minimum spanning tree has all the properties of a spanning tree with an added constraint of having the minimum
possible weights among all possible spanning trees. Like a spanning tree, there can also be many possible MSTs for a
graph.
• Algorithms to find Minimum Spanning Tree:
• There are several algorithms to find the minimum spanning tree from a given graph, some of them are listed below:
Kruskal’s Minimum Spanning Tree Algorithm

This is one of the popular algorithms for finding the minimum spanning tree from a connected, undirected graph. This is a
greedy algorithm.

The algorithm workflow is as below:


First, it sorts all the edges of the graph by their weights,
Then starts the iterations of finding the spanning tree.
At each iteration, the algorithm adds the next lowest-weight edge one by one, such that the edges picked until now does not
form a cycle.
This algorithm can be implemented efficiently using a DSU ( Disjoint-Set ) data structure to keep track of the connected
components of the graph. This is used in a variety of practical applications such as network design, clustering, and data
analysis.
Prim’s Minimum Spanning Tree Algorithm
This is also a greedy algorithm. This algorithm has the following workflow: It starts by selecting an arbitrary vertex and then
adding it to the MST. Then, it repeatedly checks for the minimum edge weight that connects one vertex of MST to another
vertex that is not yet in the MST. This process is continued until all the vertices are included in the MST. To efficiently select
the minimum weight edge for each iteration, this algorithm uses priority_queue to store the vertices sorted by their minimum
edge weight currently. It also simultaneously keeps track of the MST using an array or other data structure suitable considering
the data type it is storing. This algorithm can be used in various scenarios such as image segmentation based on color, texture,
or other features. For Routing, as in finding the shortest path between two points for a delivery truck to follow.
Topological sorting
Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed
edge u-v, vertex u comes before v in the ordering.

Output: 5 4 2 3 1 0
Explanation: The first vertex in topological sorting is always a vertex with an in-degree of 0 (a vertex with no
incoming edges).
A topological sorting of the following graph is “5 4 2 3 1 0”.
There can be more than one topological sorting for a graph. Another topological sorting of the following graph is “4
5 2 3 1 0”.
• In computer science, a topological sort or topological ordering of a directed graph is a linear ordering of its vertices such
that for every directed edge (u,v) from vertex u to vertex v, u comes before v in the ordering.
• For instance, the vertices of the graph may represent tasks to be performed, and the edges may represent constraints that one
task must be performed before another; in this application, a topological ordering is just a valid sequence for the tasks.
• Precisely, a topological sort is a graph traversal in which each node v is visited only after all its dependencies are
visited.
• A topological ordering is possible if and only if the graph has no directed cycles, that is, if it is a directed acyclic graph
(DAG). Any DAG has at least one topological ordering, and algorithms are known for constructing a topological ordering of
any DAG in linear time. Topological sorting has many applications, especially in ranking problems such as feedback arc set.
Topological sorting is also possible when the DAG has disconnected components.
This graph has many valid topological sorts, including:5, 7, 3, 11, 8, 2, 9, 10
(visual left-to-right, top-to-bottom)
3, 5, 7, 8, 11, 2, 9, 10 (smallest-numbered available vertex first)
3, 5, 7, 8, 11, 2, 10, 9 (lexicographic by incoming neighbors)
5, 7, 3, 8, 11, 2, 10, 9 (fewest edges first)
7, 5, 11, 3, 10, 8, 9, 2 (largest-numbered available vertex first)
5, 7, 11, 2, 3, 8, 9, 10 (attempting top-to-bottom, left-to-right)
3, 7, 8, 5, 11, 10, 2, 9 (arbitrary)

An alternative algorithm for topological sorting is based on depth-first search.


Ford-Fulkerson Algorithm(Network Flow Algorithm)

• The Ford-Fulkerson algorithm is a widely used algorithm to solve the maximum flow problem in a flow network. The
maximum flow problem involves determining the maximum amount of flow that can be sent from a source vertex to a sink
vertex in a directed weighted graph, subject to capacity constraints on the edges.

• The algorithm works by iteratively finding an augmenting path, which is a path from the source to the sink in the residual
graph, i.e., the graph obtained by subtracting the current flow from the capacity of each edge. The algorithm then increases
the flow along this path by the maximum possible amount, which is the minimum capacity of the edges along the path
Problem

• Given a graph which represents a flow network where every edge has a
capacity. Also, given two vertices source ‘s’ and sink ‘t’ in the graph, find the
maximum possible flow from s to t with the following constraints: Flow on an
edge doesn’t exceed the given capacity of the edge. Incoming flow is equal to
outgoing flow for every vertex except s and t. For example, consider the
following graph The maximum possible flow in the above graph is 23.
Ford-Fulkerson Algorithm

The following is simple idea of Ford-Fulkerson algorithm:

1. Start with initial flow as 0.

2. While there exists an augmenting path from the source to the sink:

1. Find an augmenting path using any path-finding algorithm, such as breadth-first search or depth-first search.

2. Determine the amount of flow that can be sent along the augmenting path, which is the minimum residual capacity along
the edges of the path.

3. Increase the flow along the augmenting path by the determined amount.

3. Return the maximum flow.


The key objectives of Graph and Tree Algorithms focus on solving problems efficiently using structured data representations
in graphs and trees:
1. Representation of Relationships and Hierarchies
2. Efficient Traversal of Data
3.Pathfinding and Shortest Paths
4. Minimum Spanning Tree (MST) Construction
5. Cycle Detection
6. Graph Connectivity and Components
Thankyou

You might also like