Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
15 views
31 pages
Graph New
Data structure
Uploaded by
Mubashra Rashid
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save graph new For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
15 views
31 pages
Graph New
Data structure
Uploaded by
Mubashra Rashid
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save graph new For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 31
Search
Fullscreen
Ways to represent a graph 2 Gizan st - Mare races wn be sf reignbow,/~ icsSoeetnae aeteeeeteeenel etentt Edge set - Store the pair of nodes/vertices connected with an edge. Eg - ((0,4), 0,4), (2, 4)) Other implementations to represent a graph also exists. For e.g. Compact list representation, cost adjacency list, cost adjacency matrix et. adjacency matrix is also a simple thing, you make a matrix like this, so for this graph i will make like this, i will write 01,2 here »Adjacency list = Mark the nodes with the list of its neighbors 0 9 © © —~ pay 1 + O-@-@/7 lit 2-7 @-O@°@ — (D) i hop iu understand this thing that tAdjacency matrix = A,= 1 for an edge between i andj, 0 otherwise! ETiTeR-\St MMA) RLM UAloM XXMONCA ON ORONCKEK ORCA RE KORCKONOKeKOneKeNeKe Ne) ‘ 1 Gey }Graph Traversal Graph traversal refers to the process of visiting (checking and/or Uptating) eros aE TCs ‘Sequence of steps known as Graph traversal algorithm can be used to traverse err) ‘Two Algorithms of Graph Traversal are: ee gee a) Depth First Search (DFS) Rein But this thing comes to your mind because you have a small graph. edGraph Traversal 7 os Graph traversal refers to the process of visiting (checking and/or Updating) each vertex(node) in a graph. een ee ee eet rr) FOS TN Re ene re vo ee SN Ct eed Raa SS eat fee ache — PaO Which will definitely make sense in the upcoming videos. oy een omeBFS spanning tree (5 -Consder the graph shown at the right ‘= Me can stat with any source node 9Lets start wth 0 ‘= Trytoconstructa tree with 0 as the root as long as your node is there in the graph |BFS spanning tree ‘Consider the graph shown atthe right! We can start wth any source node Lets start wth 0 Try to construct tree with 0 as the root Mark al the sideways o duplicate edges (above a node) 0s dashed ‘This constructed tree is called as BFS Spanning Tree ‘= Level order traversal of @ BFS spanning tee is a valid BFS ‘waversal of @ raph!Mefed 2 BFS Traversal feat x _— (> ‘Consider the graph shown atthe right! Y 9 Wecan start with any source node {B> Lets start with O and insert inthe queve ‘= Visita the connected vertices and enqueue them for exploration 0 2 2ahse = Oto te oan o HLH KEE ps fa SRoTelm elect Col an Lei esicu traversal cameBFS Traversal - Exploring 0 ‘Consider the graph shown atthe right! We can start wth any source node Lets start with 0 and insert tin the queue Visita the connected vertices and enqueue them for exploration (inary order) (is now explore Lot's go to the next in queue (3) Repeat the same for other elements in the queue are aol: malaBFS Traversal - Exploring 3 o }—{1 1.83 are also explored Repeat the same for other elements in the queue Visite geen Expl SurgBFS Traversal - Exploring 4, 5,6 ‘Consider the graph shown atthe right! We can start wth any source node Lets start with O and insert tin the queue Visit al the connected vertices and enqueue them for exploration (01s now explored Lt’ go to the next in queue (2) Repeat the same for other elements inthe queue Visited: 0, 1, 2, Exploration Quetiialielak!Important points 0 }—_{1 We can start with any vertex | There can be multiple BFS results for a given graph a) G . (Hint: Start with nodes other than 0) Now here we will talk about some important pointsMain Zoom Class a “~~ WITH QUIZ COMPETITION ~~~ THURSDAY, 14 December 2023 Qatar - 07:15 PM Pakistan - 09:15 PM << a India - 09:45 PMI started from one in this case SomF If it is not visited. if it is visited than this if will not work yDFS Procedure Start by putting any one of the graph's vertices on top of a stack, Take the top item of the stack and add it to the visited list Create a list of that vertex’s adjacent nodes. Add the ‘ones which aren't in the visited lst to the top of the stack Keep repeating steps 2 and 3 until the stack is empty.DFS Procedure Start by putting anyone of the graphs vertices ontop ora sac Take the top item of the stack and add it to the visited list Create a list of that vertex’s adjacent nodes. Add the ‘ones which aren't in the visited lst to the top of the stack. Keep repeating steps 2 and 3 until the stack is empty. Be Viskd: 01234562 ute B OR LOSINi 042 ° DFS Procedure e 4 Atart by putting any one ofthe graphs vertices on top of a stack, 2-“ate the top tem ofthe stack and ad tothe vised 2 list 3-Create a list of that vertex’s adjacent nodes. Add the ‘ones which aren't in the visited lst to the top of the {6} stack [3] 4. Keep repeating steps 2 and 3 until the stack is empty. Bp Vist; © 12345 62Ni o4 ° DFS Procedure 3 Atart by putting any one ofthe graphs vertices on top of a stack, _2--Take the top item of the stack and add it to the visited list _3- Create a list ofthat vertex’s adjacent nodes. Add the @} ‘ones which aren't in the visited lst to the top of the 0] stack [3 feteenerenrte teresa sten renee sere ind: 0.1 234562,DFS Procedure - Step 1 1. Start by putting any one of the graph's vertices on top of a stack Lets put O into the stack! Visited:DFS Procedure - Step 2 Start by putting any one of the graph's vertices on top of a stack Lets put 0 into the stack! 2. Take the top item of the stack and add it to the visited list ~0is now visited! Visited: 0DFS Procedure - Step 3 1. Start by putting any one of the graph's vertices on top Of a stack ~ Lets put O into the stack! Take the top item of the stack and add it to the visited list Create a list of that vertex’s adjacent nodes. Add the ‘ones which aren't in the visited lst to the top of the stack. gs Visited: 0,DFS Procedure - Step 2 1. Take the top item of the stack and add it to the visited list 1 is now visited! Visited: 0, 1DFS Procedure - Step 2 1. Take the top item of the stack and add it to the visited list - 1 is now visited! Visited: 0, 1,2, 4 Soho le ailNS Oe UR neat ries Succeed et ord (oD ae = ao emailSubgraphs ‘= Asubgraph of a graph G is a graph whose vertices and edges are subsets of the original graph G. A — G 5 e Este MiB mUcel MVM Le neal cM Amn -Re lalla MUnr-(a Une Relea o) graph okay, i hope it is clear that some nodes will come from our originalConnected and Complete Graphs. = _Aconnected graphiis graph that is connected in tte Sense of a topological space, i.e., there is a ath from any point to any other point in the graph. ‘Aggraph that is not connected is said to be disconnected, ‘A complete graph is a simple undirected graph in which every pair of distinct vertices is connected by a unique edge Quick Quiz: f= Is the graph on the right @ connected graph? So i will complete graph, so it is a complete graph okay, if i took 4 nodes, so 1,2,3,4 are my 4 nodes, one 1, one 2, one 3 and one 4 aA afc) mi er- es) oval area le ciota = Asubgraph of a graph G is a graph whose vertices and édges aré subsets Crue Pu Eee AS graph G iff (if and only if} 4 All vertices of G must be presént in S eo EnaNo of spanning trees for Complete Graphs \# A complete graph has n*? Spanning Trees where nis the number of vertices in the graph Quick Quiz: ‘= Draw 3 spanning trees for the graph at the right
You might also like
BFS AND DFS
PDF
No ratings yet
BFS AND DFS
9 pages
UNIT 4-Graph-1
PDF
No ratings yet
UNIT 4-Graph-1
59 pages
Lecture 4 - Requirements Engineering
PDF
No ratings yet
Lecture 4 - Requirements Engineering
82 pages
DSA MK Lect4 PDF
PDF
No ratings yet
DSA MK Lect4 PDF
73 pages
Graph Search:: Breadth-First Search (BFS) Depth-First Search (DFS)
PDF
No ratings yet
Graph Search:: Breadth-First Search (BFS) Depth-First Search (DFS)
42 pages
Data Structures: R. K. Ghosh
PDF
No ratings yet
Data Structures: R. K. Ghosh
138 pages
Depth-First Search 1
PDF
No ratings yet
Depth-First Search 1
15 pages
Depth-First Search 1
PDF
No ratings yet
Depth-First Search 1
15 pages
L21 Graphs Clean
PDF
No ratings yet
L21 Graphs Clean
166 pages
CPgrahs
PDF
No ratings yet
CPgrahs
7 pages
Part2 3GraphTraversal
PDF
No ratings yet
Part2 3GraphTraversal
99 pages
1
PDF
No ratings yet
1
4 pages
01-Toturial Week2
PDF
No ratings yet
01-Toturial Week2
77 pages
GRAPHS
PDF
No ratings yet
GRAPHS
43 pages
Graph Traversal - DFS & BFS
PDF
100% (1)
Graph Traversal - DFS & BFS
42 pages
16 DFS
PDF
No ratings yet
16 DFS
15 pages
BFS_AND_DFS_29
PDF
No ratings yet
BFS_AND_DFS_29
95 pages
DS Graphs
PDF
No ratings yet
DS Graphs
88 pages
Graphs - 1
PDF
No ratings yet
Graphs - 1
20 pages
Data Structures & Algorithms ppt 4
PDF
No ratings yet
Data Structures & Algorithms ppt 4
36 pages
Graphs
PDF
No ratings yet
Graphs
43 pages
Graph 2
PDF
No ratings yet
Graph 2
22 pages
DSA
PDF
No ratings yet
DSA
48 pages
Unit 3 Lecture 2
PDF
No ratings yet
Unit 3 Lecture 2
21 pages
Basic Search and Traversal Techniques
PDF
No ratings yet
Basic Search and Traversal Techniques
18 pages
Lecture 16
PDF
No ratings yet
Lecture 16
52 pages
Ds-unit-4
PDF
No ratings yet
Ds-unit-4
5 pages
COMP20007 Design of Algorithms: Graph Traversal
PDF
No ratings yet
COMP20007 Design of Algorithms: Graph Traversal
22 pages
Unit 5
PDF
No ratings yet
Unit 5
78 pages
Graph (1)
PDF
No ratings yet
Graph (1)
4 pages
Lec25 DFS I
PDF
No ratings yet
Lec25 DFS I
25 pages
DS Lecture Week 13
PDF
No ratings yet
DS Lecture Week 13
38 pages
Learn Graph-Traversal Through Animations
PDF
No ratings yet
Learn Graph-Traversal Through Animations
32 pages
lecture11_2025_05_09
PDF
No ratings yet
lecture11_2025_05_09
32 pages
Graph
PDF
No ratings yet
Graph
90 pages
Traversing Graphs:: A Journey Through Connected Data
PDF
No ratings yet
Traversing Graphs:: A Journey Through Connected Data
19 pages
Solve SE Past Papers
PDF
No ratings yet
Solve SE Past Papers
43 pages
Unit-5 - Oops
PDF
No ratings yet
Unit-5 - Oops
27 pages
DSA Chapter 7 - Graphs
PDF
No ratings yet
DSA Chapter 7 - Graphs
71 pages
Unit II Notes
PDF
No ratings yet
Unit II Notes
25 pages
2 Uninformed Search
PDF
No ratings yet
2 Uninformed Search
41 pages
graphs
PDF
No ratings yet
graphs
28 pages
bfs_dfs_1
PDF
No ratings yet
bfs_dfs_1
9 pages
Ch8 Graph
PDF
No ratings yet
Ch8 Graph
22 pages
UNIT 5 (1)
PDF
No ratings yet
UNIT 5 (1)
19 pages
UNIT V
PDF
No ratings yet
UNIT V
25 pages
Checkpoint_Week_2
PDF
No ratings yet
Checkpoint_Week_2
13 pages
Class_ppt1_Graphs
PDF
No ratings yet
Class_ppt1_Graphs
22 pages
Breadth First Search
PDF
No ratings yet
Breadth First Search
8 pages
Unit - 5
PDF
No ratings yet
Unit - 5
34 pages
17-BFS, DFS-05-02-2025
PDF
No ratings yet
17-BFS, DFS-05-02-2025
32 pages
Httpslms Ou Edu Vn241pluginfile Php217729mod - resourcecontent1DsA-04-Graph PDF
PDF
No ratings yet
Httpslms Ou Edu Vn241pluginfile Php217729mod - resourcecontent1DsA-04-Graph PDF
36 pages
Graphs 1
PDF
No ratings yet
Graphs 1
17 pages
Graph
PDF
No ratings yet
Graph
26 pages
B - F S (BFS) D - F S (DFS) : Raph Earch
PDF
No ratings yet
B - F S (BFS) D - F S (DFS) : Raph Earch
43 pages
Unit III - Graphs
PDF
No ratings yet
Unit III - Graphs
36 pages
M & S Qa
PDF
No ratings yet
M & S Qa
13 pages
Unit 5ds
PDF
No ratings yet
Unit 5ds
16 pages
Best Graph Notes
PDF
No ratings yet
Best Graph Notes
8 pages
12th Done
PDF
No ratings yet
12th Done
12 pages
Graph Terminologies
PDF
No ratings yet
Graph Terminologies
8 pages
Exp 12
PDF
No ratings yet
Exp 12
7 pages
It Series Lecture Week 8
PDF
No ratings yet
It Series Lecture Week 8
13 pages
Network Devices
PDF
No ratings yet
Network Devices
4 pages