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.

More Related Content

What's hot

Bfs dfs
Bfs dfsBfs dfs
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
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
 
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 listStefi 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 searchzukun
 
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
 

What's hot (20)

Bfs dfs
Bfs dfsBfs dfs
Bfs dfs
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
 
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
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
 
BFS
BFSBFS
BFS
 
Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)Graph Algorithms: Breadth-First Search (BFS)
Graph Algorithms: Breadth-First Search (BFS)
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Graphs
GraphsGraphs
Graphs
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
Graphs in Data Structure
Graphs in Data StructureGraphs in Data Structure
Graphs in Data Structure
 
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
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
 
Adjacency list
Adjacency listAdjacency list
Adjacency list
 
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
 
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
 
Graphss
GraphssGraphss
Graphss
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
 

Viewers also liked

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 lab1Bianca Teşilă
 
Pda
PdaPda
Push down automata
Push down automataPush down automata
Push down automataSomya 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 langauagesdanhumble
 
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 unionstudent
 
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
 

Viewers also liked (20)

Structure & union
Structure & unionStructure & union
Structure & union
 
Normalization
NormalizationNormalization
Normalization
 
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
 
Data structures and algorithms lab1
Data structures and algorithms lab1Data structures and algorithms lab1
Data structures and algorithms lab1
 
Normalization
NormalizationNormalization
Normalization
 
Pda
PdaPda
Pda
 
Push down automata
Push down automataPush down automata
Push down automata
 
0 1 knapsack problem
0 1 knapsack problem0 1 knapsack problem
0 1 knapsack problem
 
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
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
 
My presentation minimum spanning tree
My presentation minimum spanning treeMy presentation minimum spanning tree
My presentation minimum spanning tree
 
Push Down Automata (PDA)
Push Down Automata (PDA)Push Down Automata (PDA)
Push Down Automata (PDA)
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
 
structure and union
structure and unionstructure and union
structure and union
 
Normalization
NormalizationNormalization
Normalization
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
 
Normalization
NormalizationNormalization
Normalization
 
DBMS - Normalization
DBMS - NormalizationDBMS - Normalization
DBMS - Normalization
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization
 

Similar to Data structures and algorithms lab7

Graphs (1)
Graphs (1)Graphs (1)
Graphs (1)
Meet Patel
 
Talk on Graph Theory - I
Talk on Graph Theory - ITalk on Graph Theory - I
Talk on Graph Theory - I
Anirudh Raja
 
Graphs
GraphsGraphs
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-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
DhruvilSTATUS
 
Graphs
GraphsGraphs
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
 
lec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.pptlec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.ppt
TalhaFarooqui12
 
358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13
sumitbardhan
 
Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
satvikkushwaha1
 
Daa chpater 12
Daa chpater 12Daa chpater 12
Daa chpater 12
B.Kirron Reddi
 
Analysis &amp; design of algorithm
Analysis &amp; design of algorithmAnalysis &amp; design of algorithm
Analysis &amp; design of algorithm
rahela bham
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Graphs
GraphsGraphs
Graphs
LavanyaJ28
 

Similar to Data structures and algorithms lab7 (20)

Graphs (1)
Graphs (1)Graphs (1)
Graphs (1)
 
Talk on Graph Theory - I
Talk on Graph Theory - ITalk on Graph Theory - I
Talk on Graph Theory - I
 
Graphs
GraphsGraphs
Graphs
 
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
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
 
Graphs
GraphsGraphs
Graphs
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptx
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Spanningtreesppt
SpanningtreespptSpanningtreesppt
Spanningtreesppt
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
 
Graph
GraphGraph
Graph
 
lec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.pptlec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.ppt
 
358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13
 
Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
 
8-Graph.ppt
8-Graph.ppt8-Graph.ppt
8-Graph.ppt
 
Daa chpater 12
Daa chpater 12Daa chpater 12
Daa chpater 12
 
Analysis &amp; design of algorithm
Analysis &amp; design of algorithmAnalysis &amp; design of algorithm
Analysis &amp; design of algorithm
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Unit V - ppt.pptx
 
Graphs
GraphsGraphs
Graphs
 

More from 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 lab11Bianca Teşilă
 
Data structures and algorithms lab10
Data structures and algorithms lab10Data structures and algorithms lab10
Data structures and algorithms lab10Bianca Teşilă
 
Data structures and algorithms lab9
Data structures and algorithms lab9Data structures and algorithms lab9
Data structures and algorithms lab9Bianca Teşilă
 
Data structures and algorithms lab8
Data structures and algorithms lab8Data structures and algorithms lab8
Data structures and algorithms lab8Bianca Teşilă
 
Data structures and algorithms lab6
Data structures and algorithms lab6Data structures and algorithms lab6
Data structures and algorithms lab6Bianca Teşilă
 
Data structures and algorithms lab5
Data structures and algorithms lab5Data structures and algorithms lab5
Data structures and algorithms lab5Bianca Teşilă
 
Data structures and algorithms lab4
Data structures and algorithms lab4Data structures and algorithms lab4
Data structures and algorithms lab4Bianca Teşilă
 
Data structures and algorithms lab3
Data structures and algorithms lab3Data structures and algorithms lab3
Data structures and algorithms lab3Bianca Teşilă
 
Data structures and algorithms lab2
Data structures and algorithms lab2Data structures and algorithms lab2
Data structures and algorithms lab2Bianca Teşilă
 

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
 
Data structures and algorithms lab11
Data structures and algorithms lab11Data structures and algorithms lab11
Data structures and algorithms lab11
 
Data structures and algorithms lab10
Data structures and algorithms lab10Data structures and algorithms lab10
Data structures and algorithms lab10
 
Data structures and algorithms lab9
Data structures and algorithms lab9Data structures and algorithms lab9
Data structures and algorithms lab9
 
Data structures and algorithms lab8
Data structures and algorithms lab8Data structures and algorithms lab8
Data structures and algorithms lab8
 
Data structures and algorithms lab6
Data structures and algorithms lab6Data structures and algorithms lab6
Data structures and algorithms lab6
 
Data structures and algorithms lab5
Data structures and algorithms lab5Data structures and algorithms lab5
Data structures and algorithms lab5
 
Data structures and algorithms lab4
Data structures and algorithms lab4Data structures and algorithms lab4
Data structures and algorithms lab4
 
Data structures and algorithms lab3
Data structures and algorithms lab3Data structures and algorithms lab3
Data structures and algorithms lab3
 
Data structures and algorithms lab2
Data structures and algorithms lab2Data structures and algorithms lab2
Data structures and algorithms lab2
 

Recently uploaded

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 

Recently uploaded (20)

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 

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.