SlideShare a Scribd company logo
8/31/2020
1
UNIT-II
• Max-Min Problem
• Graphs problems: BFS
• DFS
• Articulation point
Material prepared by Dr. N. Subhash Chandra
From Web resources, Computer Algorithms , Horowitz, Sahni &
Rajasekaran
Max-Min Problem
TWO METHODS:
• Method 1 Straight forward: if we apply the general approach to
the array of size n, the number of comparisons required are 2n-2.
• Method-2: Divide and Conquer approach: we will divide the
problem into sub-problems and find the max and min of each group,
now max of each group will compare with the only max of another
group and min with min.
Problem: Analyze the algorithm to find the
maximum and minimum element from an
array.
1
2
8/31/2020
2
Straight forward Method: Max Min Problem
Divide Conquer method
Exercise problems: Construct Max-Min tree for
a) 25,13,8,50,98,-2,-17,45,55,88,97,5,-5
b) 78,-2,98,14,78,-10,67,45,39,100
3
4
8/31/2020
3
Divide and Conquer Method Algorithm
Analysis of Divide and Conquer Method
5
6
8/31/2020
4
Comparison of Straight forward method and
Divide and Conquer Method
Divide and Conquer the complexity 3n/2 – 2 is the best, average, worst case
number of comparison when n is a power of two.
Comparisons with Straight Forward Method:
Compared with the 2n – 2 comparisons for the Straight Forward method, this is a
saving of 25% in comparisons. It can be shown that no algorithm based on
comparisons uses less than 3n/2 – 2 comparisons.
Ex: n=8
Straight forward method: 2*8-2=14 comparisons
Divide and Conquer method: 3*8/2-2= 10 comparisons
Graph Traversal Algorithms
Traversing the graph means examining all the nodes and vertices of the
graph. There are two standard methods
• Breadth First Search
• Depth First Search
• Applications: Articulation point, Topological Sort, Convex hull
7
8
8/31/2020
5
Graph Applications
• Web pages with links
• Road maps (e.g., Google maps)
• Airline routes
• Facebook friends
• Family trees
• Paths through a maze
Paths
• path: A path from vertex a to b is a sequence of edges that
can be followed starting from a to reach b.
• can be represented as vertices visited, or edges taken
• example, one path from V to Z: {b, h} or {V, X, Z}
• What are two paths from U to Y?
• path length: Number of vertices
or edges contained in the path.
• neighbor or adjacent: Two vertices
connected directly by an edge.
• example: V and X
XU
V
W
Z
Y
a
c
b
e
d
f
g
h
9
10
8/31/2020
6
Reachability, connectedness
• reachable: Vertex a is reachable from b
if a path exists from a to b.
• connected: A graph is connected if every
vertex is reachable from any other.
• Is the graph at top right connected?
• strongly connected: When every vertex
has an edge to every other vertex.
XU
V
W
Z
Y
a
c
b
e
d
f
g
h
a
c
b
d
a
c
b
d
e
Loops and cycles
• cycle: A path that begins and ends at the same node.
• example: {b, g, f, c, a} or {V, X, Y, W, U, V}.
• example: {c, d, a} or {U, W, V, U}.
• acyclic graph: One that does
not contain any cycles.
• loop: An edge directly from
a node to itself.
• Many graphs don't allow loops.
XU
V
W
Z
Y
a
c
b
e
d
f
g
h
11
12
8/31/2020
7
Weighted graphs
• weight: Cost associated with a given edge.
• Some graphs have weighted edges, and some are unweighted.
• Edges in an unweighted graph can be thought of as having equal
weight (e.g. all 0, or all 1, etc.)
• Most graphs do not allow negative weights.
• example: graph of airline flights, weighted by miles between
cities:
Colcatta
Chennai
Mumb
Bhuv
Lacknow
Patna
Hyd
Delhi
Directed graphs
• directed graph ("digraph"): One where edges are one-way
connections between vertices.
• If graph is directed, a vertex has a separate in/out degree.
• A digraph can be weighted or unweighted.
• Is the graph below connected? Why or why not?
a
d
b
e
gf
c
13
14
8/31/2020
8
Digraph example
• Vertices= UW CSE courses (incomplete list)
• Edge (a, b) = a is a prerequisite for b
142
143 154
140
311
312
331
351
333
341
344403
352
373
120
410
332
374
131
421431 440
415
413
417
414
444446
450
451
452
Linked Lists, Trees, Graphs
• A binary tree is a graph with some restrictions:
• The tree is an unweighted, directed, acyclic graph (DAG).
• Each node's in-degree is at most 1, and out-degree is at most 2.
• There is exactly one path from the root to every node.
• A linked list is also a graph:
• Unweighted DAG.
• In/out degree of at most 1 for all nodes.
F
B
A E
K
H
JG
A B DC
15
16
8/31/2020
9
Searching for paths
• Searching for a path from one vertex to another:
• Sometimes, we just want any path (or want to know there is a
path).
• Sometimes, we want to minimize path length (# of edges).
• Sometimes, we want to minimize path cost (sum of edge weights).
• What is the shortest path from MIA to SFO?
Which path has the minimum cost?
ORD
PVD
MIA
DFW
SFO
LAX
LGA
HNL
$500
Algorithms
Breadth First Search Depth First Search
• Visit start vertex and put into a FIFO
queue.
• Repeatedly remove a vertex from the
queue, visit its unvisited adjacent vertices,
put newly visited vertices into the queue.
17
18
8/31/2020
10
Example
• Breadth-first traversal using a queue.
Order of
Traversal Queue rearA B D E C G F H I
Queue front
A
B D E
C G
F H
I
BFS-tree:
Note: The BFS-tree for undirected graph is a free tree
Example
• Depth-first traversal using an explicit stack.
Order of
Traversal StackA B C F E G D H I
The Preorder Depth First Tree:
Note: The DFS-tree for undirected graph is a free tree
19
20
8/31/2020
11
Example to search G using DFS, BFS
Searching in BFS, DFS
21
22
8/31/2020
12
BFS, DFS Example
DFS, BFS Example
Starting the DFS at A, visit A -> B -> C,
backtrack to B, visit E -> F, backtrack to A,
visit D -> G -> H.
Starting the BFS at A, visit A -> B -> D -> C
-> E -> G -> H -> F.
23
24
8/31/2020
13
Exercise problems: Traverse by BFS,DFS
BFS,DFS Algorithms
25
26
8/31/2020
14
Difference b/w DFS, BFS
Complexities: When a vertex is
removed from the queue, we
examine its adjacent vertices.
 O(n) if adjacency matrix used
 O(vertex degree) if adjacency
lists used
Total time
 O(mn), where m is number
of vertices in the component
that is searched (adjacency
matrix) = O(V2)
 Adjacency list =O(V+E)
Application of DFS: Articulation point
27
28
8/31/2020
15
Articulation point
Bi-Connected Components
29
30
8/31/2020
16
Algorithm for Bi-Connected graph
Finding Articulation point
31
32
8/31/2020
17
Finding Articulation point using DFS
Finding Articulation point using DFS
33
34
8/31/2020
18
Example 1
Example 1
35
36
8/31/2020
19
Example 1
Vertex 1 2 3 4 5 6 7 8 9 10
DFN(u) 1 6 3 2 7 8 9 10 5 4
L(u) 1 1 1 1 6 8 6 6 5 4
Example 2
37
38
8/31/2020
20
Example 2
Example 2
Vertex 1 2 3 4 5 6 7 8
DFN(u) 1 2 3 6 4 5 7 8
L(u) 1 2 3 6 4 5 6 6
39
40
8/31/2020
21
Example 3
Example 3
41
42
8/31/2020
22
Example 3
Example 3 Vertex 1 2 3 4 5 6 7 8
DFN(u) 1 2 3 4 5 6 8 7
L(u) 1 1 1 1 1 4 3 4
43
44
8/31/2020
23
Exercise Problems on Articulation points using DFS
Problems
45
46
8/31/2020
24
Algorithm for Articulation point
Time complexity of
above method is
O(V*(V+E)) for a
graph represented
using adjacency
list.
Algorithm to determine Bi-Connected Components
47
48

More Related Content

What's hot

Adjacency list
Adjacency listAdjacency list
Adjacency listStefi Yu
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
Muhammad Hammad Waseem
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
Keno benti
 
Graph representation
Graph representationGraph representation
Graph representationTech_MX
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
hamza javed
 
Graphss
GraphssGraphss
Graphss
fika sweety
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphsKumar
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structures
Savit Chandra
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsAakash deep Singhal
 
Tn 110 lecture 8
Tn 110 lecture 8Tn 110 lecture 8
Tn 110 lecture 8
ITNet
 
College Timetable Scheduling System
College Timetable Scheduling SystemCollege Timetable Scheduling System
College Timetable Scheduling System
ShardulKulkarni24
 
Talk on Graph Theory - I
Talk on Graph Theory - ITalk on Graph Theory - I
Talk on Graph Theory - I
Anirudh Raja
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
Abrish06
 
Graph therory
Graph theroryGraph therory
Graph therory
mohanrathod18
 
Data structure
Data structureData structure
Data structure
jagjot singh chopra
 
Graph theory
Graph theoryGraph theory
Graph theory
AparnaKumari31
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
Afaq Mansoor Khan
 
1.1.1B Measuring Segments
1.1.1B Measuring Segments1.1.1B Measuring Segments
1.1.1B Measuring Segments
smiller5
 

What's hot (20)

Adjacency list
Adjacency listAdjacency list
Adjacency list
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Graph representation
Graph representationGraph representation
Graph representation
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
 
Graphss
GraphssGraphss
Graphss
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structures
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithms
 
Tn 110 lecture 8
Tn 110 lecture 8Tn 110 lecture 8
Tn 110 lecture 8
 
Graphs
GraphsGraphs
Graphs
 
College Timetable Scheduling System
College Timetable Scheduling SystemCollege Timetable Scheduling System
College Timetable Scheduling System
 
Talk on Graph Theory - I
Talk on Graph Theory - ITalk on Graph Theory - I
Talk on Graph Theory - I
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graph therory
Graph theroryGraph therory
Graph therory
 
Data structure
Data structureData structure
Data structure
 
Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
1.1.1B Measuring Segments
1.1.1B Measuring Segments1.1.1B Measuring Segments
1.1.1B Measuring Segments
 

Similar to Unit ii divide and conquer -2

22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
chandrashekarr799
 
22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.ppt22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.ppt
KarunaBiswas3
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
MuhammadUmerIhtisham
 
U1 L5 DAA.pdf
U1 L5 DAA.pdfU1 L5 DAA.pdf
U1 L5 DAA.pdf
LakshyaBaliyan2
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
Tribhuvan University
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
Dabbal Singh Mahara
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
king779879
 
lec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.pptlec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.ppt
TalhaFarooqui12
 
LAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptxLAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptx
ionutionescuionut
 
Graphs
GraphsGraphs
Algorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptxAlgorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptx
zerihunnana
 
Minicourse on Network Science
Minicourse on Network ScienceMinicourse on Network Science
Minicourse on Network Science
Pavel Loskot
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
pournima055
 
Chapter 23 aoa
Chapter 23 aoaChapter 23 aoa
Chapter 23 aoa
Hanif Durad
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
Ruchika Sinha
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
kailash shaw
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
Rashmi Bhat
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
DhruvilSTATUS
 
Breadth first search
Breadth first searchBreadth first search
Breadth first search
Sazzad Hossain
 

Similar to Unit ii divide and conquer -2 (20)

22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
22-graphs1-dfs-bfs.ppt odiehehei7hoh97ho7bi6vi6go7gp
 
22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.ppt22-graphs1-dfs-bfs.ppt
22-graphs1-dfs-bfs.ppt
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
U1 L5 DAA.pdf
U1 L5 DAA.pdfU1 L5 DAA.pdf
U1 L5 DAA.pdf
 
Unit ix graph
Unit   ix    graph Unit   ix    graph
Unit ix graph
 
Unit 9 graph
Unit   9 graphUnit   9 graph
Unit 9 graph
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
 
10.graph
10.graph10.graph
10.graph
 
lec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.pptlec 09-graphs-bfs-dfs.ppt
lec 09-graphs-bfs-dfs.ppt
 
LAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptxLAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptx
 
Graphs
GraphsGraphs
Graphs
 
Algorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptxAlgorithms and data Chapter 3 V Graph.pptx
Algorithms and data Chapter 3 V Graph.pptx
 
Minicourse on Network Science
Minicourse on Network ScienceMinicourse on Network Science
Minicourse on Network Science
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 
Chapter 23 aoa
Chapter 23 aoaChapter 23 aoa
Chapter 23 aoa
 
Dijkstra.ppt
Dijkstra.pptDijkstra.ppt
Dijkstra.ppt
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
Breadth first search
Breadth first searchBreadth first search
Breadth first search
 

More from subhashchandra197

Unit-I Objects,Attributes,Similarity&Dissimilarity.ppt
Unit-I Objects,Attributes,Similarity&Dissimilarity.pptUnit-I Objects,Attributes,Similarity&Dissimilarity.ppt
Unit-I Objects,Attributes,Similarity&Dissimilarity.ppt
subhashchandra197
 
Unit-I- Introduction- Traits of Big Data-Final.pptx
Unit-I- Introduction- Traits of Big Data-Final.pptxUnit-I- Introduction- Traits of Big Data-Final.pptx
Unit-I- Introduction- Traits of Big Data-Final.pptx
subhashchandra197
 
Data Science : Unit-I -Hypothesis and Inferences.pptx
Data Science : Unit-I -Hypothesis and Inferences.pptxData Science : Unit-I -Hypothesis and Inferences.pptx
Data Science : Unit-I -Hypothesis and Inferences.pptx
subhashchandra197
 
UNIT-1 Data pre-processing-Data cleaning, Transformation, Reduction, Integrat...
UNIT-1 Data pre-processing-Data cleaning, Transformation, Reduction, Integrat...UNIT-1 Data pre-processing-Data cleaning, Transformation, Reduction, Integrat...
UNIT-1 Data pre-processing-Data cleaning, Transformation, Reduction, Integrat...
subhashchandra197
 
Data science Lecture Notes: Reporting vs Analysis.pptx
Data science Lecture Notes: Reporting vs Analysis.pptxData science Lecture Notes: Reporting vs Analysis.pptx
Data science Lecture Notes: Reporting vs Analysis.pptx
subhashchandra197
 
Unit ii divide and conquer -4
Unit ii divide and conquer -4Unit ii divide and conquer -4
Unit ii divide and conquer -4
subhashchandra197
 
Unit ii divide and conquer -3
Unit ii divide and conquer -3Unit ii divide and conquer -3
Unit ii divide and conquer -3
subhashchandra197
 
Unit ii divide and conquer -1
Unit ii divide and conquer -1Unit ii divide and conquer -1
Unit ii divide and conquer -1
subhashchandra197
 
Bs,qs,divide and conquer 1
Bs,qs,divide and conquer 1Bs,qs,divide and conquer 1
Bs,qs,divide and conquer 1
subhashchandra197
 
Recursive algorithms
Recursive algorithmsRecursive algorithms
Recursive algorithms
subhashchandra197
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
subhashchandra197
 
P,NP Hard, NP-Complete problems
P,NP Hard, NP-Complete problemsP,NP Hard, NP-Complete problems
P,NP Hard, NP-Complete problems
subhashchandra197
 
Turing machine material
Turing machine materialTuring machine material
Turing machine material
subhashchandra197
 
Turing machine types
Turing machine typesTuring machine types
Turing machine types
subhashchandra197
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
subhashchandra197
 
Disjoint sets union, find
Disjoint sets  union, findDisjoint sets  union, find
Disjoint sets union, find
subhashchandra197
 

More from subhashchandra197 (17)

Unit-I Objects,Attributes,Similarity&Dissimilarity.ppt
Unit-I Objects,Attributes,Similarity&Dissimilarity.pptUnit-I Objects,Attributes,Similarity&Dissimilarity.ppt
Unit-I Objects,Attributes,Similarity&Dissimilarity.ppt
 
Unit-I- Introduction- Traits of Big Data-Final.pptx
Unit-I- Introduction- Traits of Big Data-Final.pptxUnit-I- Introduction- Traits of Big Data-Final.pptx
Unit-I- Introduction- Traits of Big Data-Final.pptx
 
Data Science : Unit-I -Hypothesis and Inferences.pptx
Data Science : Unit-I -Hypothesis and Inferences.pptxData Science : Unit-I -Hypothesis and Inferences.pptx
Data Science : Unit-I -Hypothesis and Inferences.pptx
 
UNIT-1 Data pre-processing-Data cleaning, Transformation, Reduction, Integrat...
UNIT-1 Data pre-processing-Data cleaning, Transformation, Reduction, Integrat...UNIT-1 Data pre-processing-Data cleaning, Transformation, Reduction, Integrat...
UNIT-1 Data pre-processing-Data cleaning, Transformation, Reduction, Integrat...
 
Data science Lecture Notes: Reporting vs Analysis.pptx
Data science Lecture Notes: Reporting vs Analysis.pptxData science Lecture Notes: Reporting vs Analysis.pptx
Data science Lecture Notes: Reporting vs Analysis.pptx
 
Unit ii divide and conquer -4
Unit ii divide and conquer -4Unit ii divide and conquer -4
Unit ii divide and conquer -4
 
Unit ii divide and conquer -3
Unit ii divide and conquer -3Unit ii divide and conquer -3
Unit ii divide and conquer -3
 
Unit ii divide and conquer -1
Unit ii divide and conquer -1Unit ii divide and conquer -1
Unit ii divide and conquer -1
 
Bs,qs,divide and conquer 1
Bs,qs,divide and conquer 1Bs,qs,divide and conquer 1
Bs,qs,divide and conquer 1
 
Recursive algorithms
Recursive algorithmsRecursive algorithms
Recursive algorithms
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
P,NP Hard, NP-Complete problems
P,NP Hard, NP-Complete problemsP,NP Hard, NP-Complete problems
P,NP Hard, NP-Complete problems
 
Turing machine material
Turing machine materialTuring machine material
Turing machine material
 
Turing machine types
Turing machine typesTuring machine types
Turing machine types
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 
Disjoint sets union, find
Disjoint sets  union, findDisjoint sets  union, find
Disjoint sets union, find
 

Recently uploaded

在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 

Recently uploaded (20)

在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 

Unit ii divide and conquer -2

  • 1. 8/31/2020 1 UNIT-II • Max-Min Problem • Graphs problems: BFS • DFS • Articulation point Material prepared by Dr. N. Subhash Chandra From Web resources, Computer Algorithms , Horowitz, Sahni & Rajasekaran Max-Min Problem TWO METHODS: • Method 1 Straight forward: if we apply the general approach to the array of size n, the number of comparisons required are 2n-2. • Method-2: Divide and Conquer approach: we will divide the problem into sub-problems and find the max and min of each group, now max of each group will compare with the only max of another group and min with min. Problem: Analyze the algorithm to find the maximum and minimum element from an array. 1 2
  • 2. 8/31/2020 2 Straight forward Method: Max Min Problem Divide Conquer method Exercise problems: Construct Max-Min tree for a) 25,13,8,50,98,-2,-17,45,55,88,97,5,-5 b) 78,-2,98,14,78,-10,67,45,39,100 3 4
  • 3. 8/31/2020 3 Divide and Conquer Method Algorithm Analysis of Divide and Conquer Method 5 6
  • 4. 8/31/2020 4 Comparison of Straight forward method and Divide and Conquer Method Divide and Conquer the complexity 3n/2 – 2 is the best, average, worst case number of comparison when n is a power of two. Comparisons with Straight Forward Method: Compared with the 2n – 2 comparisons for the Straight Forward method, this is a saving of 25% in comparisons. It can be shown that no algorithm based on comparisons uses less than 3n/2 – 2 comparisons. Ex: n=8 Straight forward method: 2*8-2=14 comparisons Divide and Conquer method: 3*8/2-2= 10 comparisons Graph Traversal Algorithms Traversing the graph means examining all the nodes and vertices of the graph. There are two standard methods • Breadth First Search • Depth First Search • Applications: Articulation point, Topological Sort, Convex hull 7 8
  • 5. 8/31/2020 5 Graph Applications • Web pages with links • Road maps (e.g., Google maps) • Airline routes • Facebook friends • Family trees • Paths through a maze Paths • path: A path from vertex a to b is a sequence of edges that can be followed starting from a to reach b. • can be represented as vertices visited, or edges taken • example, one path from V to Z: {b, h} or {V, X, Z} • What are two paths from U to Y? • path length: Number of vertices or edges contained in the path. • neighbor or adjacent: Two vertices connected directly by an edge. • example: V and X XU V W Z Y a c b e d f g h 9 10
  • 6. 8/31/2020 6 Reachability, connectedness • reachable: Vertex a is reachable from b if a path exists from a to b. • connected: A graph is connected if every vertex is reachable from any other. • Is the graph at top right connected? • strongly connected: When every vertex has an edge to every other vertex. XU V W Z Y a c b e d f g h a c b d a c b d e Loops and cycles • cycle: A path that begins and ends at the same node. • example: {b, g, f, c, a} or {V, X, Y, W, U, V}. • example: {c, d, a} or {U, W, V, U}. • acyclic graph: One that does not contain any cycles. • loop: An edge directly from a node to itself. • Many graphs don't allow loops. XU V W Z Y a c b e d f g h 11 12
  • 7. 8/31/2020 7 Weighted graphs • weight: Cost associated with a given edge. • Some graphs have weighted edges, and some are unweighted. • Edges in an unweighted graph can be thought of as having equal weight (e.g. all 0, or all 1, etc.) • Most graphs do not allow negative weights. • example: graph of airline flights, weighted by miles between cities: Colcatta Chennai Mumb Bhuv Lacknow Patna Hyd Delhi Directed graphs • directed graph ("digraph"): One where edges are one-way connections between vertices. • If graph is directed, a vertex has a separate in/out degree. • A digraph can be weighted or unweighted. • Is the graph below connected? Why or why not? a d b e gf c 13 14
  • 8. 8/31/2020 8 Digraph example • Vertices= UW CSE courses (incomplete list) • Edge (a, b) = a is a prerequisite for b 142 143 154 140 311 312 331 351 333 341 344403 352 373 120 410 332 374 131 421431 440 415 413 417 414 444446 450 451 452 Linked Lists, Trees, Graphs • A binary tree is a graph with some restrictions: • The tree is an unweighted, directed, acyclic graph (DAG). • Each node's in-degree is at most 1, and out-degree is at most 2. • There is exactly one path from the root to every node. • A linked list is also a graph: • Unweighted DAG. • In/out degree of at most 1 for all nodes. F B A E K H JG A B DC 15 16
  • 9. 8/31/2020 9 Searching for paths • Searching for a path from one vertex to another: • Sometimes, we just want any path (or want to know there is a path). • Sometimes, we want to minimize path length (# of edges). • Sometimes, we want to minimize path cost (sum of edge weights). • What is the shortest path from MIA to SFO? Which path has the minimum cost? ORD PVD MIA DFW SFO LAX LGA HNL $500 Algorithms Breadth First Search Depth First Search • Visit start vertex and put into a FIFO queue. • Repeatedly remove a vertex from the queue, visit its unvisited adjacent vertices, put newly visited vertices into the queue. 17 18
  • 10. 8/31/2020 10 Example • Breadth-first traversal using a queue. Order of Traversal Queue rearA B D E C G F H I Queue front A B D E C G F H I BFS-tree: Note: The BFS-tree for undirected graph is a free tree Example • Depth-first traversal using an explicit stack. Order of Traversal StackA B C F E G D H I The Preorder Depth First Tree: Note: The DFS-tree for undirected graph is a free tree 19 20
  • 11. 8/31/2020 11 Example to search G using DFS, BFS Searching in BFS, DFS 21 22
  • 12. 8/31/2020 12 BFS, DFS Example DFS, BFS Example Starting the DFS at A, visit A -> B -> C, backtrack to B, visit E -> F, backtrack to A, visit D -> G -> H. Starting the BFS at A, visit A -> B -> D -> C -> E -> G -> H -> F. 23 24
  • 13. 8/31/2020 13 Exercise problems: Traverse by BFS,DFS BFS,DFS Algorithms 25 26
  • 14. 8/31/2020 14 Difference b/w DFS, BFS Complexities: When a vertex is removed from the queue, we examine its adjacent vertices.  O(n) if adjacency matrix used  O(vertex degree) if adjacency lists used Total time  O(mn), where m is number of vertices in the component that is searched (adjacency matrix) = O(V2)  Adjacency list =O(V+E) Application of DFS: Articulation point 27 28
  • 16. 8/31/2020 16 Algorithm for Bi-Connected graph Finding Articulation point 31 32
  • 17. 8/31/2020 17 Finding Articulation point using DFS Finding Articulation point using DFS 33 34
  • 19. 8/31/2020 19 Example 1 Vertex 1 2 3 4 5 6 7 8 9 10 DFN(u) 1 6 3 2 7 8 9 10 5 4 L(u) 1 1 1 1 6 8 6 6 5 4 Example 2 37 38
  • 20. 8/31/2020 20 Example 2 Example 2 Vertex 1 2 3 4 5 6 7 8 DFN(u) 1 2 3 6 4 5 7 8 L(u) 1 2 3 6 4 5 6 6 39 40
  • 22. 8/31/2020 22 Example 3 Example 3 Vertex 1 2 3 4 5 6 7 8 DFN(u) 1 2 3 4 5 6 8 7 L(u) 1 1 1 1 1 4 3 4 43 44
  • 23. 8/31/2020 23 Exercise Problems on Articulation points using DFS Problems 45 46
  • 24. 8/31/2020 24 Algorithm for Articulation point Time complexity of above method is O(V*(V+E)) for a graph represented using adjacency list. Algorithm to determine Bi-Connected Components 47 48