SlideShare a Scribd company logo
DATA STRUCTURES AND ALGORITHMS
LAB 7
Bianca Tesila
FILS, March 2014
OBJECTIVES
 Graphs
 DFS
 BFS
 Bipartite Graphs
GRAPHS: INTRODUCTION
 Pair of sets: G = (V, E)
 V = the set of vertices
 E = the set of edges; E ⊆ V x V
GRAPHS: INTRODUCTION
 Directed/ Undirected
GRAPHS: INTRODUCTION
 Weighted/ Unweighted
GRAPHS: INTRODUCTION
 Cyclic/ Acyclic
GRAPHS: REPRESENTATION
 Adjacency Matrix
 A V x V matrix, with AdjacencyMatrix[i][j] storing whether
there is an edge between the ith vertex and the jth vertex or
not
 Linked List of Neighbours
 One linked list per vertex, each storing directly reachable vertices
!! What are the advantages and disadvantages of each of
them?
GRAPHS: TRAVERSALS
Depth-First Search - Go as far as you can (if you have not visited that
node yet), otherwise, go back and try another way
 There is no source vertex
 All the vertices are traversed
DFS (vertex u) {
mark u as visited
for each vertex v directly reachable from u
if v is unvisited
DFS (v)
}
!! Initially, all the vertices are marked as unvisited.
GRAPHS: TRAVERSALS
!! Exercise:
 Emily wants to distribute candies to N students, one by one, with a
rule that if student A is teased by B, A can receive the candy before
B.
 Given the lists of students teased by each student, find a possible
sequence to give the candies.
GRAPHS: TRAVERSALS
Breadth-First Search - Instead of going as far as possible, BFS tries to
search all paths.
 Uses a start vertex for the traversal: s
 Determine the minimum number of edges (shortest path
considering that all the edges have the same weight = 1)
between the source s and all the other vertices of the graph
 Not all the vertices are traversed
 BFS makes use of a queue to store visited (but not dead) vertices,
expanding the path from the earliest visited vertices
while queue Q not empty
dequeue the first vertex u from Q
for each vertex v directly reachable from u
if v is unvisited
enqueue v to Q
mark v as visited
!! Initially, all the vertices, except for the start vertex, are marked as
unvisited and the queue contains only the start vertex .
GRAPHS: TRAVERSALS
!! Exercise:
Let’s consider un undirected graph, representing a social network.
Given an user, display all his friends (or information about them) having
the degree <=N (N is given). A is friend with B if there is an edge
between A and B; we say that the degree of friendship is 1. Friends of
friends have the degree of friendship 2.
GRAPHS: BIPARTITE GRAPHS
 A graph whose vertices can be divided into
two disjoint sets such that every edge connects a
vertex in U to one in V.
GRAPHS: BIPARTITE GRAPHS
!! Exercise:
Check if a graph is bipartite and if so, display the
components of those two sets U and V. The graph will
be represented by the lists of neighbors.
Check your code for the following graphs:
 G1=({ 1,2,3,4,5,6,7,8,9},{ 12, 13, 45, 56, 75, 24, 58, 79,
43, 89})
 G2=({ 1,2,3,4,5,6,7,8,9},{ 12, 13, 45, 56, 75, 24, 58, 79,
43, 89,47})
HOMEWORK
Finish all the lab assignments.
Ad

More Related Content

What's hot (20)

Bfs dfs
Bfs dfsBfs dfs
Bfs dfs
Amit Kumar Rathi
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
Ankit Kumar Singh
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
Hossain Md Shakhawat
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
Dhrumil Panchal
 
BFS
BFSBFS
BFS
jyothimonc
 
Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)
Md. Shafiuzzaman Hira
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
DEEPIKA T
 
Graphs
GraphsGraphs
Graphs
Zulkifal Yousaf
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
Muhammad Hammad Waseem
 
Graphs in Data Structure
Graphs in Data StructureGraphs in Data Structure
Graphs in Data Structure
lalithambiga kamaraj
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First Search
Nisha Soms
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
Md. Shafiuzzaman Hira
 
Adjacency list
Adjacency listAdjacency list
Adjacency list
Stefi Yu
 
Skiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first search
zukun
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - Graphs
Yi-Lung Tsai
 
Graphss
GraphssGraphss
Graphss
fika sweety
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
Anandhasilambarasan D
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
Pooja Bhojwani
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
hafsa komal
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
Ikhlas Rahman
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
Ankit Kumar Singh
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
Hossain Md Shakhawat
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
Dhrumil Panchal
 
Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)
Md. Shafiuzzaman Hira
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
DEEPIKA T
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First Search
Nisha Soms
 
Adjacency list
Adjacency listAdjacency list
Adjacency list
Stefi Yu
 
Skiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first search
zukun
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - Graphs
Yi-Lung Tsai
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
Pooja Bhojwani
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
hafsa komal
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
Ikhlas Rahman
 

Viewers also liked (20)

Structure & union
Structure & unionStructure & union
Structure & union
Rupesh Mishra
 
Normalization
NormalizationNormalization
Normalization
murdhani heena
 
Minimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiMinimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumi
Ibrahim Alfayoumi
 
Data structures and algorithms lab1
Data structures and algorithms lab1Data structures and algorithms lab1
Data structures and algorithms lab1
Bianca Teşilă
 
Normalization
NormalizationNormalization
Normalization
Nittaya Intarat
 
Pda
PdaPda
Pda
Self-employed
 
Push down automata
Push down automataPush down automata
Push down automata
Somya Bagai
 
0 1 knapsack problem
0 1 knapsack problem0 1 knapsack problem
0 1 knapsack problem
Maher Alshammari
 
0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programming0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programming
Maher Alshammari
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
danhumble
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
Maher Alshammari
 
My presentation minimum spanning tree
My presentation minimum spanning treeMy presentation minimum spanning tree
My presentation minimum spanning tree
Alona Salva
 
Push Down Automata (PDA)
Push Down Automata (PDA)Push Down Automata (PDA)
Push Down Automata (PDA)
Animesh Chaturvedi
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
Ram Sagar Mourya
 
structure and union
structure and unionstructure and union
structure and union
student
 
Normalization
NormalizationNormalization
Normalization
ochesing
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
Ram Sagar Mourya
 
Normalization
NormalizationNormalization
Normalization
Salman Memon
 
DBMS - Normalization
DBMS - NormalizationDBMS - Normalization
DBMS - Normalization
Jitendra Tomar
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization
emailharmeet
 
Minimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiMinimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumi
Ibrahim Alfayoumi
 
Data structures and algorithms lab1
Data structures and algorithms lab1Data structures and algorithms lab1
Data structures and algorithms lab1
Bianca Teşilă
 
Push down automata
Push down automataPush down automata
Push down automata
Somya Bagai
 
0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programming0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programming
Maher Alshammari
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
danhumble
 
My presentation minimum spanning tree
My presentation minimum spanning treeMy presentation minimum spanning tree
My presentation minimum spanning tree
Alona Salva
 
structure and union
structure and unionstructure and union
structure and union
student
 
Normalization
NormalizationNormalization
Normalization
ochesing
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization
emailharmeet
 
Ad

Similar to Data structures and algorithms lab7 (20)

Graph data structures for ppt for understanding.pptx
Graph data structures for ppt for understanding.pptxGraph data structures for ppt for understanding.pptx
Graph data structures for ppt for understanding.pptx
ramkumar649780
 
Graphs (1)
Graphs (1)Graphs (1)
Graphs (1)
Meet Patel
 
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPHUNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
VISWANATHAN R V
 
Talk on Graph Theory - I
Talk on Graph Theory - ITalk on Graph Theory - I
Talk on Graph Theory - I
Anirudh Raja
 
Graphs Presentation of University by Coordinator
Graphs Presentation of University by CoordinatorGraphs Presentation of University by Coordinator
Graphs Presentation of University by Coordinator
haseebanjum2611
 
Graphs
GraphsGraphs
Graphs
KomalPaliwal3
 
Graph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptxGraph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptx
bashirabdullah789
 
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH.pptx
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH.pptxUNIT IV NON LINEAR DATA STRUCTURES - GRAPH.pptx
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH.pptx
kncetaruna
 
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt
babanazar7204
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
DhruvilSTATUS
 
Graphs aktu notes computer networks.pptx
Graphs aktu notes computer networks.pptxGraphs aktu notes computer networks.pptx
Graphs aktu notes computer networks.pptx
TalhaKhan528682
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
KENNEDY GITHAIGA
 
Graphs
GraphsGraphs
Graphs
AkhileshSingh330
 
Graphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
Graphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdfGraphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
Graphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
timoemin50
 
Data Structures-Non Linear DataStructures-Graphs
Data Structures-Non Linear DataStructures-GraphsData Structures-Non Linear DataStructures-Graphs
Data Structures-Non Linear DataStructures-Graphs
sailaja156145
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptx
Rajitha Reddy Alugati
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
Afaq Mansoor Khan
 
Spanningtreesppt
SpanningtreespptSpanningtreesppt
Spanningtreesppt
Jyoshna Cec Cse Staf bejjam
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
KENNEDY GITHAIGA
 
Graph
GraphGraph
Graph
WinNie Sjr
 
Graph data structures for ppt for understanding.pptx
Graph data structures for ppt for understanding.pptxGraph data structures for ppt for understanding.pptx
Graph data structures for ppt for understanding.pptx
ramkumar649780
 
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPHUNIT IV NON LINEAR DATA STRUCTURES - GRAPH
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
VISWANATHAN R V
 
Talk on Graph Theory - I
Talk on Graph Theory - ITalk on Graph Theory - I
Talk on Graph Theory - I
Anirudh Raja
 
Graphs Presentation of University by Coordinator
Graphs Presentation of University by CoordinatorGraphs Presentation of University by Coordinator
Graphs Presentation of University by Coordinator
haseebanjum2611
 
Graph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptxGraph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptx
bashirabdullah789
 
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH.pptx
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH.pptxUNIT IV NON LINEAR DATA STRUCTURES - GRAPH.pptx
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH.pptx
kncetaruna
 
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt
babanazar7204
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
DhruvilSTATUS
 
Graphs aktu notes computer networks.pptx
Graphs aktu notes computer networks.pptxGraphs aktu notes computer networks.pptx
Graphs aktu notes computer networks.pptx
TalhaKhan528682
 
Graphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
Graphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdfGraphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
Graphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
timoemin50
 
Data Structures-Non Linear DataStructures-Graphs
Data Structures-Non Linear DataStructures-GraphsData Structures-Non Linear DataStructures-Graphs
Data Structures-Non Linear DataStructures-Graphs
sailaja156145
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptx
Rajitha Reddy Alugati
 
Ad

More from Bianca Teşilă (10)

Akka Streams - An Adobe data-intensive story
Akka Streams - An Adobe data-intensive storyAkka Streams - An Adobe data-intensive story
Akka Streams - An Adobe data-intensive story
Bianca Teşilă
 
Data structures and algorithms lab11
Data structures and algorithms lab11Data structures and algorithms lab11
Data structures and algorithms lab11
Bianca Teşilă
 
Data structures and algorithms lab10
Data structures and algorithms lab10Data structures and algorithms lab10
Data structures and algorithms lab10
Bianca Teşilă
 
Data structures and algorithms lab9
Data structures and algorithms lab9Data structures and algorithms lab9
Data structures and algorithms lab9
Bianca Teşilă
 
Data structures and algorithms lab8
Data structures and algorithms lab8Data structures and algorithms lab8
Data structures and algorithms lab8
Bianca Teşilă
 
Data structures and algorithms lab6
Data structures and algorithms lab6Data structures and algorithms lab6
Data structures and algorithms lab6
Bianca Teşilă
 
Data structures and algorithms lab5
Data structures and algorithms lab5Data structures and algorithms lab5
Data structures and algorithms lab5
Bianca Teşilă
 
Data structures and algorithms lab4
Data structures and algorithms lab4Data structures and algorithms lab4
Data structures and algorithms lab4
Bianca Teşilă
 
Data structures and algorithms lab3
Data structures and algorithms lab3Data structures and algorithms lab3
Data structures and algorithms lab3
Bianca Teşilă
 
Data structures and algorithms lab2
Data structures and algorithms lab2Data structures and algorithms lab2
Data structures and algorithms lab2
Bianca Teşilă
 
Akka Streams - An Adobe data-intensive story
Akka Streams - An Adobe data-intensive storyAkka Streams - An Adobe data-intensive story
Akka Streams - An Adobe data-intensive story
Bianca Teşilă
 
Data structures and algorithms lab11
Data structures and algorithms lab11Data structures and algorithms lab11
Data structures and algorithms lab11
Bianca Teşilă
 
Data structures and algorithms lab10
Data structures and algorithms lab10Data structures and algorithms lab10
Data structures and algorithms lab10
Bianca Teşilă
 
Data structures and algorithms lab9
Data structures and algorithms lab9Data structures and algorithms lab9
Data structures and algorithms lab9
Bianca Teşilă
 
Data structures and algorithms lab8
Data structures and algorithms lab8Data structures and algorithms lab8
Data structures and algorithms lab8
Bianca Teşilă
 
Data structures and algorithms lab6
Data structures and algorithms lab6Data structures and algorithms lab6
Data structures and algorithms lab6
Bianca Teşilă
 
Data structures and algorithms lab5
Data structures and algorithms lab5Data structures and algorithms lab5
Data structures and algorithms lab5
Bianca Teşilă
 
Data structures and algorithms lab4
Data structures and algorithms lab4Data structures and algorithms lab4
Data structures and algorithms lab4
Bianca Teşilă
 
Data structures and algorithms lab3
Data structures and algorithms lab3Data structures and algorithms lab3
Data structures and algorithms lab3
Bianca Teşilă
 
Data structures and algorithms lab2
Data structures and algorithms lab2Data structures and algorithms lab2
Data structures and algorithms lab2
Bianca Teşilă
 

Recently uploaded (20)

SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 

Data structures and algorithms lab7

  • 1. DATA STRUCTURES AND ALGORITHMS LAB 7 Bianca Tesila FILS, March 2014
  • 2. OBJECTIVES  Graphs  DFS  BFS  Bipartite Graphs
  • 3. GRAPHS: INTRODUCTION  Pair of sets: G = (V, E)  V = the set of vertices  E = the set of edges; E ⊆ V x V
  • 7. GRAPHS: REPRESENTATION  Adjacency Matrix  A V x V matrix, with AdjacencyMatrix[i][j] storing whether there is an edge between the ith vertex and the jth vertex or not  Linked List of Neighbours  One linked list per vertex, each storing directly reachable vertices !! What are the advantages and disadvantages of each of them?
  • 8. GRAPHS: TRAVERSALS Depth-First Search - Go as far as you can (if you have not visited that node yet), otherwise, go back and try another way  There is no source vertex  All the vertices are traversed DFS (vertex u) { mark u as visited for each vertex v directly reachable from u if v is unvisited DFS (v) } !! Initially, all the vertices are marked as unvisited.
  • 9. GRAPHS: TRAVERSALS !! Exercise:  Emily wants to distribute candies to N students, one by one, with a rule that if student A is teased by B, A can receive the candy before B.  Given the lists of students teased by each student, find a possible sequence to give the candies.
  • 10. GRAPHS: TRAVERSALS Breadth-First Search - Instead of going as far as possible, BFS tries to search all paths.  Uses a start vertex for the traversal: s  Determine the minimum number of edges (shortest path considering that all the edges have the same weight = 1) between the source s and all the other vertices of the graph  Not all the vertices are traversed  BFS makes use of a queue to store visited (but not dead) vertices, expanding the path from the earliest visited vertices while queue Q not empty dequeue the first vertex u from Q for each vertex v directly reachable from u if v is unvisited enqueue v to Q mark v as visited !! Initially, all the vertices, except for the start vertex, are marked as unvisited and the queue contains only the start vertex .
  • 11. GRAPHS: TRAVERSALS !! Exercise: Let’s consider un undirected graph, representing a social network. Given an user, display all his friends (or information about them) having the degree <=N (N is given). A is friend with B if there is an edge between A and B; we say that the degree of friendship is 1. Friends of friends have the degree of friendship 2.
  • 12. GRAPHS: BIPARTITE GRAPHS  A graph whose vertices can be divided into two disjoint sets such that every edge connects a vertex in U to one in V.
  • 13. GRAPHS: BIPARTITE GRAPHS !! Exercise: Check if a graph is bipartite and if so, display the components of those two sets U and V. The graph will be represented by the lists of neighbors. Check your code for the following graphs:  G1=({ 1,2,3,4,5,6,7,8,9},{ 12, 13, 45, 56, 75, 24, 58, 79, 43, 89})  G2=({ 1,2,3,4,5,6,7,8,9},{ 12, 13, 45, 56, 75, 24, 58, 79, 43, 89,47})
  • 14. HOMEWORK Finish all the lab assignments.