SlideShare a Scribd company logo
DESIGN AND ANALYSIS OF ALGORITHMSRemember this: “No problem is too tough if u spend enuf time on it”				-A great manQuestion:an+bn=cn  find a,b,c Answer: Ethoingayirukku!!an+bn=cn PRESENTED BY ARVIND KRISHNAA J
CONTENTS OF THE UNITGRAPH TRAVERSALS
CONNECTED COMPONENTS
SPANNING TREES
BI-CONNECTED COMPONENTS
BRANCH AND BOUND:GENERAL METHODS(FIFO & LC)
0/1 KNAPSACK PROBLEM
INTRODUCTION TO NP-HARD AND NPCOMPLETENESSPRESENTED BY ARVIND KRISHNAA JUNIT –V SYLLABUS
AIM:The main aim of any graph traversal algorithm is for a given graph G=(V,E) is to determine whether there exists a path starting from a vertex v to a vertex uPRESENTED BY ARVIND KRISHNAA JGRAPH TRAVERSALS
PRESENTED BY ARVIND KRISHNAA JGRAPH TRAVERSALS
PRESENTED BY ARVIND KRISHNAA JBREADTH FIRST SEARCHBASIC IDEA:Visits graph vertices by moving across to all the neighbors of last visited vertex b BFS uses a queuea vertex is inserted into queue when it is reached for the first time, and is marked as visited.a vertex is removed from the queue, when it identifies all unvisited vertices that are adjacent to the vertex b
PRESENTED BY ARVIND KRISHNAA JALGORITHM FOR BFSvoid BFS(int v){//v being a starting vertexint u=v;Queue q[SIZE];visited[v]=1;do{for all vertices w adjacent to to u{	if(visited[w]==0)//w is unvisited	{q.AddQ(w);visited[w]=1;	}}if(Q.Empty())	return;q.Delete(u);}while(1);}
PRESENTED BY ARVIND KRISHNAA JAN EXAMPLE GRAPH12364578
PRESENTED BY ARVIND KRISHNAA JPERFORMING THE BREADTH FIRST TRAVERSALvoid BFT(graph G,int n){int i;boolean visited[SIZE];for(i=1;i<=n;i++)visited[i]=0;for(i=1;i<=n;i++)if(!visited[i])	BFS[i};}
PRESENTED BY ARVIND KRISHNAA JDEPTH FIRST SEARCHBASIC IDEAStarting vertex is arbitrarily chosen or determined by the problem.Visits graph’s vertices by always moving away from last visited vertex to unvisited one, backtracks if no adjacent unvisited vertex is available.Uses a stacka vertex is pushed onto the stack when it’s reached for the first timea vertex is popped off the stack when it becomes a dead end, i.e., when there is no adjacent unvisited vertex
PRESENTED BY ARVIND KRISHNAA JALGORITHM FOR DFSvoid DFS(int v){visited[v]=1;for each vertex w adjacent to v	{	if(!visited[w])		DFS[w];}}
PRESENTED BY ARVIND KRISHNAA Jfor the graph.....ABDEC
PRESENTED BY ARVIND KRISHNAA JAPPLICATIONSBREADTH FIRST SEARCH:Greedy graph algorithmsfinding the minimum spanning tree using PRIM’S ALGORITHMsingle source (or) all pair shortest path using DIJKSTRA’S ALGORITHMNETWORK FLOW PROBLEMTesting for connected componentsDEPTH FIRST SEARCH:Testing for biconnected components(bi-connectivity)for eg., checking for the connectivity of a network
PRESENTED BY ARVIND KRISHNAA JCONNECTED COMPONENTSDEFINITION:Two vertices in a graph are in the same connected component if and only if there is a path from one vertex to the otherNOTE:BFS algorithm can be used to test whether a graph is connected or notIf a graph G is connected then only 1 call to the function BFT(G,n) is made
The number of calls made to the BFT function can be used to roughly determine the number of “disconnected” componentsPRESENTED BY ARVIND KRISHNAA JDETERMINING A CONNECTED COMPONENTSTRATEGYAll newly visited vertices on a call to BFS represent vertices in a connected component of GTo display the connected components modify BFS to put newly visited vertices into a listConsider for the graph discussed previously.....
PRESENTED BY ARVIND KRISHNAA JFOR THE DIRECTED GRAPHABCEDF
PRESENTED BY ARVIND KRISHNAA JTHE DFS LIST ISELIST MADE IN THE FIRST CALLLIST MADE DURING THE SECOND CALLAs the number of calls made to the function is 2 it means that the graph is not connectedThere are two sets of connected components represented above
PRESENTED BY ARVIND KRISHNAA JSPANNING TREEBFS SPANNING TREE1BFS SPANNING TREE:A spanning tree constructed by performing the Breadth first search of a graph2364578
PRESENTED BY ARVIND KRISHNAA JSPANNING TREEDFS SPANNING TREE1DFS SPANNING TREE:A spanning tree constructed by performing the Depth first search of a graph2364578
PRESENTED BY ARVIND KRISHNAA JBICONNECTED COMPONENTSNOTE: Henceforth the word “Graph” would be used instead of the term “undirected Graph”ARTICULATION POINT: A vertex v in a connected graph is said to be an articulation point if and only if the the deletion of the vertex v and all its edges incident to it “disconnects” the graph into two or more non-empty components.Biconnected graph: A graph G is said to be biconnected if and only if it contains no articulation pointsLet us see an example....
PRESENTED BY ARVIND KRISHNAA JA connected graph156247The articulation points are highlighted...removing them causes disconnection83109
PRESENTED BY ARVIND KRISHNAA JPOINTS TO NOTE	LEMMA: Two biconnected components can have at most one vertex in common and this vertex is an articulation point.TRANSLATION: The common vertex of two biconnected components is an articulation point.NOTE: No edge can be in two different biconnected components as this would require two common vertices(violation of Lemma!!)
PRESENTED BY ARVIND KRISHNAA JMAKING A CONNECTED GRAPH BICONNECTEDTECHNIQUE:Simply add “redundant” edges between the connected components that have the articulation point (say a) in common...for example the previously discussed connected graph can be made biconnected by adding the throbbing links(see next slide...if u r asleep pls continue...)
PRESENTED BY ARVIND KRISHNAA JConnected to biconnected...156247The articulation points are highlighted...removing them causes disconnection83109
PRESENTED BY ARVIND KRISHNAA JSCHEME TO CONSTRUCT A BICONNECTED COMPONENTfor each articulation point a{let B1,B2,…Bk be the biconnected components containing vertex a;	let vi,vi≠a, be a vertex in Bi  ,				1≤i≤k;add to G the edges (vi,vi+1),1≤i≤k;} 
SIMPLE ALGORITHM:Construct a DFS spanning tree for the given graphHave parameters dfn[u],L[u]Do a preorder traversal of the spanning tree and compute dfn[u] for each node as the ith node that is visitedCompute the value of L[u] asPRESENTED BY ARVIND KRISHNAA JIDENTIFYING ARTICULATION POINTSL[u]=min{ dfn[u],min{L[w]|w is a child of u}, min{ dfn[w]  | (u,w) is a back edge}
SIMPLE ALGORITHM:Nodes which satisfy L[w]≥dfn[u], w being the children of u are identified as articulation pointsSPECIAL CASE OF ROOT NODENote: The root node is always listed as an articulation pointif root node has exactly one childthen exclude the root node from AP listelseroot node is also an articulation pointPRESENTED BY ARVIND KRISHNAA JIDENTIFYING ARTICULATION POINTS contd...
PRESENTED BY ARVIND KRISHNAA JCOMPUTATIONS FOR THE GIVEN GRAPH
Oh MahaZeeya..Oh MahaZeeya..NakkaMukkaNakka...Oh Shakalakka..Oh Randakka..(x2)Oh Laahi Oh Laahi..AyakaYahiYahi..Me Hoo..Me Hoo...DailamoDailamo..RahtullaSonali Oh..Oh MahaZeeya..Oh MahaZeeya..NakkaMukkaNakka...Oh Shakalakka..Oh Randakka..Samba Sambale..OsoseSayoSayo..HasiliFisili..Ilahi..YappaJippa..(x2)blah blahblablabla.......PRESENTED BY ARVIND KRISHNAA JRECAP OF YESTERDAY
Branch & Bound
Review of Backtracking	1.  Construct the state-space tree• nodes: partial solutions• edges: choices in extending partial solutions2. Explore the state space tree using depth-first search3. “Prune” nonpromising nodes• dfs stops exploring subtrees rooted at nodes that cannotlead to a solution and backtracks to such a node’sparent to continue the search
Branch-and-BoundAn enhancement of backtracking
Applicable to optimization problems
Breadth first search(FIFO B&B) or D-search(LIFO B&B) is performed on the state space tree
For each node (partial solution) of a state-space tree, computes a bound on the value of the objective function for all descendants  of the node (extensions of the partial solution)
Uses the bound for:
ruling out certain nodes as “nonpromising” to prune the tree – if a node’s bound is not better than the best solution seen so far
guiding the search through state-spaceExample: Assignment ProblemSelect one element in each row of the cost matrix C so that:  no two selected elements are in the same column
 the sum is minimizedExampleJob1Job2Job3Job4         Person a	     9	     2	     7	    8         Person b 	     6	     4	     3	    7         Person c	     5	     8	     1	    8         Person d	     7	     6	     9	    4Lower bound: Any solution to this problem will have total cost                         at least: 2 + 3 + 1 + 4 (or 5 + 2 + 1 + 4)‏N people n jobs cost should be small.
Example: First two levels of the state-space tree
ExplanationSelect 1st element from first row i.e9Select minimum from remaining rows 3, 1, 4 not from 1st columnSo 9+3+1+4 = 17.Select 2nd element from first row i.e2Select minimum from remaining rows 3, 1, 4 not from 2nd columnSo 2+3+1+4 = 10.Select 3rd element from first row i.e7Select minimum from remaining rows 3, 1, 4 not from 3rdcolumnSo 7+4+5+4 = 20.Last one it is 8+3+1+6 = 18
Example (cont.)‏
Explanation(contd...)1. Select 2nd element from first row i.e 2Select 1st element from second row i.e 6Select minimum from remaining rows 1, 4 not from 1st columnSo 2+6+1+4 = 13.2. Select 2nd element from first row i.e 2Cannot Select 2nd element from second row 3. Select 2nd element from first row i.e 2Select 3rd element from third row i.e 3Select minimum from remaining rows 5, 4 not from 3rd columnSo 2+3+5+4 = 14.4. 2 + 7 + 1+7 =17Note: Promising node is live node a->2 is live node.
Example: Complete state-space tree
0/1 KNAPSACK PROBLEM
Branch and boundApplicable to optimization problemThe state space tree is generated using best first rule.PRESENTED BY ARVIND KRISHNAA JCOMPARISON OF B&B AND BACKTRACKINGBacktrackingNot constrained but mostly applied to Non-optimization problem
The state space tree is generated using DFSGreedy Algorithm for Knapsack ProblemStep 1: Order the items in decreasing order of relative values:  v1/w1… vn/wnStep 2: Select the items in this order skipping those that don’t              fit into the knapsackExample: The knapsack’s capacity is 15i		Pi		WiPi/Wi	1		$45		3		$15	2		$30		5		$  6	3		$45		9		$  5	4		$10		5		$  2
Branch and Bound Scheme for Knapsack ProblemStep 1: Order the items in decreasing order of relative values:  v1/w1… vn/wnStep 2: For a given integer parameter k, 0 ≤ k ≤ n, generate allsubsets of k items or less and for each of those that fit the knapsack, add the remaining items in decreasingorder of their value to weight ratiosStep 3: Find the most valuable subset among the subsets generated in Step 2 and return it as the algorithm’s output
bound (maximum potential value) = currentValue + value of remaining objects fully placed + (K - totalSize) * (value density of item that is partially placed) PRESENTED BY ARVIND KRISHNAA JSOME THINGS TO NOTEtotalSize = currentSize + size of remaining objects that can be fully placed
k-1bound = currentValue+∑ vj	+ (K - totalSize) * (vk/sk)j=i+1For the root node, currentSize = 0,  currentValue = 0PRESENTED BY ARVIND KRISHNAA JIN FORMULAEk-1totalSize = currentSize + ∑ sjj=i+1
PRESENTED BY ARVIND KRISHNAA JTHE STATE-SPACE TREE(WITH BOUND)[PERFORMING A BFS TRAVERSAL]HENCE THE FINAL ANWER SET WOULD BEX={1,0,1,0}i.e., objects 1 and 3 are chosen...2 and 4 are discarded
WHAT THE PREVIOUS PROBLEM DIDStep 1: We will construct the state space where each node contains the total current value in the knapsack, the total current size of the contents of the knapsack, and maximum potential value that the knapsack can hold.  In the algorithm, we will also keep a record of the maximum value of any node (partially or completely filled knapsack) found so far.Step 2: Perform the breadth first traversal of the state space tree computing the bound and totalsizeStep 3: Discard(prune)those “non-promising nodes” which either have(a) a lower bound than the other nodes at same level		(b) whose size exceeds the total knapsack capacityStep 4: The above method involving the BFS of the state space tree is called FIFO BRANCH & BOUND ALGORITHM
LC ALGORITHM(LEAST COST)This is a generic form/generalization of both the BFS and DFS algorithms
In LC algorithm a traversal is performed on the state space tree
Each node is given a rank based on a minimization rule(also known as best first rule) f(x)(in case of the Knapsack problem the minimization rule can be stated as f(x)=--g(x),where g(x) is the maximization rule for the Knapsack problem)Once all nodes have been ranked eliminate/prune the nodes with the poorest ranks.
Repeat till a feasible solution is obtained(sorry i cant go into too much further detail....its getting too mathematical...)
IntroductionNP-Hard AND NP-Completeness
Polynomial Time: Algorithms whose solution is found in polynomial timeeg., Sorting, searching etc.,Non-polynomial Time: Algorithms which DO NOT take polynomial time to find the solutioneg., Travelling salesperson problem (O(n22n)) PRESENTED BY ARVIND KRISHNAA JTWO KINDS OF ALGORITHMS
Problems for which there is no polynomial time complexity, are computationally relatedThere are two classes of such problems1. NP  HARD AND 2. NP  COMPLETEPRESENTED BY ARVIND KRISHNAA JTWO KINDS OF ALGORITHMS
The problem that is NP complete has the property that it can be solved in polynomial time if and only if all the other NP complete problems can be solved in polynomial timePRESENTED BY ARVIND KRISHNAA JNP  COMPLETE

More Related Content

PPTX
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
PPTX
0 1 knapsack using branch and bound
Abhishek Singh
 
PPTX
Asymptotic Notation
Protap Mondal
 
PPT
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
PPTX
Asymptotic notations
Nikhil Sharma
 
PPTX
Greedy algorithms
sandeep54552
 
PPT
Divide and conquer
Dr Shashikant Athawale
 
PDF
Optimal binary search tree dynamic programming
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
0 1 knapsack using branch and bound
Abhishek Singh
 
Asymptotic Notation
Protap Mondal
 
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
Asymptotic notations
Nikhil Sharma
 
Greedy algorithms
sandeep54552
 
Divide and conquer
Dr Shashikant Athawale
 

What's hot (20)

PPTX
Analysis of algorithm
Rajendra Dangwal
 
PPT
Asymptotic analysis
Soujanya V
 
PDF
Time and Space Complexity
Ashutosh Satapathy
 
PPTX
Strassen's matrix multiplication
Megha V
 
PPT
Binary Search
kunj desai
 
PPT
01 knapsack using backtracking
mandlapure
 
PPT
Dinive conquer algorithm
Mohd Arif
 
PPTX
Semantic net in AI
ShahDhruv21
 
PDF
A* Search Algorithm
vikas dhakane
 
PDF
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
PPT
Unit 1 chapter 1 Design and Analysis of Algorithms
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
PPT
Greedy Algorihm
Muhammad Amjad Rana
 
PPT
5.2 divide and conquer
Krish_ver2
 
PPTX
Deque and its applications
Jsaddam Hussain
 
PPTX
Backtracking
subhradeep mitra
 
PDF
Optimal binary search tree
Kavya P
 
PDF
Master theorem
fika sweety
 
PPTX
Binary Tree Traversal
Dhrumil Panchal
 
PPTX
Gradient descent method
Prof. Neeta Awasthy
 
Analysis of algorithm
Rajendra Dangwal
 
Asymptotic analysis
Soujanya V
 
Time and Space Complexity
Ashutosh Satapathy
 
Strassen's matrix multiplication
Megha V
 
Binary Search
kunj desai
 
01 knapsack using backtracking
mandlapure
 
Dinive conquer algorithm
Mohd Arif
 
Semantic net in AI
ShahDhruv21
 
A* Search Algorithm
vikas dhakane
 
Algorithms Lecture 7: Graph Algorithms
Mohamed Loey
 
Unit 1 chapter 1 Design and Analysis of Algorithms
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
Greedy Algorihm
Muhammad Amjad Rana
 
5.2 divide and conquer
Krish_ver2
 
Deque and its applications
Jsaddam Hussain
 
Backtracking
subhradeep mitra
 
Optimal binary search tree
Kavya P
 
Master theorem
fika sweety
 
Binary Tree Traversal
Dhrumil Panchal
 
Gradient descent method
Prof. Neeta Awasthy
 
Ad

Viewers also liked (17)

PPTX
Linear and Binary Search Algorithms.(Discrete Mathematics)
Shanawaz Ahamed
 
PDF
ADA complete notes
Vinay Kumar C
 
PDF
Algorithm Analysis and Design Class Notes
Kumar Avinash
 
PPT
Application of dfs
Hossain Md Shakhawat
 
PPT
Bfs and dfs in data structure
Ankit Kumar Singh
 
PPT
Breadth first search and depth first search
Hossain Md Shakhawat
 
DOC
Time and space complexity
Ankit Katiyar
 
PPTX
Search algorithms master
Hossam Hassan
 
ODP
Hillclimbing search algorthim #introduction
Mohamed Gad
 
PPTX
Bfs and Dfs
Masud Parvaze
 
PPT
Ch2 3-informed (heuristic) search
chandsek666
 
PPTX
130210107039 2130702
Ketaki_Pattani
 
PPT
Heuristic Search
butest
 
PPTX
DFS and BFS
satya parsana
 
PPT
Hill climbing
Mohammad Faizan
 
PPT
Heuristic Search Techniques {Artificial Intelligence}
FellowBuddy.com
 
PPT
17. Trees and Graphs
Intro C# Book
 
Linear and Binary Search Algorithms.(Discrete Mathematics)
Shanawaz Ahamed
 
ADA complete notes
Vinay Kumar C
 
Algorithm Analysis and Design Class Notes
Kumar Avinash
 
Application of dfs
Hossain Md Shakhawat
 
Bfs and dfs in data structure
Ankit Kumar Singh
 
Breadth first search and depth first search
Hossain Md Shakhawat
 
Time and space complexity
Ankit Katiyar
 
Search algorithms master
Hossam Hassan
 
Hillclimbing search algorthim #introduction
Mohamed Gad
 
Bfs and Dfs
Masud Parvaze
 
Ch2 3-informed (heuristic) search
chandsek666
 
130210107039 2130702
Ketaki_Pattani
 
Heuristic Search
butest
 
DFS and BFS
satya parsana
 
Hill climbing
Mohammad Faizan
 
Heuristic Search Techniques {Artificial Intelligence}
FellowBuddy.com
 
17. Trees and Graphs
Intro C# Book
 
Ad

Similar to Design and Analysis of Algorithms (20)

DOCX
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
whittemorelucilla
 
PPT
Data Structures-Non Linear DataStructures-Graphs
sailaja156145
 
PPT
graph in Data Structures and Algorithm.ppt
RAJASEKARAN G
 
PPTX
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
KUSHDHIRRA2111026030
 
PPT
Dijkstra.ppt
Ruchika Sinha
 
PPT
Review session2
NEEDY12345
 
PPTX
designanalysisalgorithm_unit-v-part2.pptx
arifimad15
 
PPTX
Graphs
KomalPaliwal3
 
PDF
Topological Sort
Dr Sandeep Kumar Poonia
 
PPTX
Boolean Algebra by SUKHDEEP SINGH
Sukhdeep Bisht
 
PPTX
Data Structures and Agorithm: DS 21 Graph Theory.pptx
RashidFaridChishti
 
DOCX
Cs6660 compiler design november december 2016 Answer key
appasami
 
PPTX
Dijkstra
jagdeeparora86
 
PPTX
20101017 program analysis_for_security_livshits_lecture02_compilers
Computer Science Club
 
PDF
Graph in Data Structure
Prof Ansari
 
PPT
Graphs in data structures
Savit Chandra
 
PPT
Spanning trees
Shareb Ismaeel
 
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
whittemorelucilla
 
Data Structures-Non Linear DataStructures-Graphs
sailaja156145
 
graph in Data Structures and Algorithm.ppt
RAJASEKARAN G
 
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
KUSHDHIRRA2111026030
 
Dijkstra.ppt
Ruchika Sinha
 
Review session2
NEEDY12345
 
designanalysisalgorithm_unit-v-part2.pptx
arifimad15
 
Topological Sort
Dr Sandeep Kumar Poonia
 
Boolean Algebra by SUKHDEEP SINGH
Sukhdeep Bisht
 
Data Structures and Agorithm: DS 21 Graph Theory.pptx
RashidFaridChishti
 
Cs6660 compiler design november december 2016 Answer key
appasami
 
Dijkstra
jagdeeparora86
 
20101017 program analysis_for_security_livshits_lecture02_compilers
Computer Science Club
 
Graph in Data Structure
Prof Ansari
 
Graphs in data structures
Savit Chandra
 
Spanning trees
Shareb Ismaeel
 

More from Arvind Krishnaa (18)

PPTX
Twitter Agreement Analysis
Arvind Krishnaa
 
PPTX
Analogical thinking
Arvind Krishnaa
 
PDF
Recognition of unistroke gesture sequences
Arvind Krishnaa
 
PPTX
Human Altruism and Cooperation
Arvind Krishnaa
 
PDF
Chowka bhara
Arvind Krishnaa
 
PDF
Canscape
Arvind Krishnaa
 
PDF
Final review presentation
Arvind Krishnaa
 
PDF
Third review presentation
Arvind Krishnaa
 
PDF
Second review presentation
Arvind Krishnaa
 
PDF
First review presentation
Arvind Krishnaa
 
PDF
Zeroth review presentation - eBay Turmeric / SMC
Arvind Krishnaa
 
PDF
Canvas Based Presentation tool - First Review
Arvind Krishnaa
 
PPTX
Canvas Based Presentation - Zeroth Review
Arvind Krishnaa
 
PDF
Data Binding and Data Grid View Classes
Arvind Krishnaa
 
PPT
Smart camera monitoring system
Arvind Krishnaa
 
ODP
Marine Pollution
Arvind Krishnaa
 
PPTX
Unix Shell and System Boot Process
Arvind Krishnaa
 
ODP
Multithreading Concepts
Arvind Krishnaa
 
Twitter Agreement Analysis
Arvind Krishnaa
 
Analogical thinking
Arvind Krishnaa
 
Recognition of unistroke gesture sequences
Arvind Krishnaa
 
Human Altruism and Cooperation
Arvind Krishnaa
 
Chowka bhara
Arvind Krishnaa
 
Canscape
Arvind Krishnaa
 
Final review presentation
Arvind Krishnaa
 
Third review presentation
Arvind Krishnaa
 
Second review presentation
Arvind Krishnaa
 
First review presentation
Arvind Krishnaa
 
Zeroth review presentation - eBay Turmeric / SMC
Arvind Krishnaa
 
Canvas Based Presentation tool - First Review
Arvind Krishnaa
 
Canvas Based Presentation - Zeroth Review
Arvind Krishnaa
 
Data Binding and Data Grid View Classes
Arvind Krishnaa
 
Smart camera monitoring system
Arvind Krishnaa
 
Marine Pollution
Arvind Krishnaa
 
Unix Shell and System Boot Process
Arvind Krishnaa
 
Multithreading Concepts
Arvind Krishnaa
 

Recently uploaded (20)

PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
Understanding operators in c language.pptx
auteharshil95
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PDF
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
PDF
Wings of Fire Book by Dr. A.P.J Abdul Kalam Full PDF
hetalvaishnav93
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Understanding operators in c language.pptx
auteharshil95
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
Wings of Fire Book by Dr. A.P.J Abdul Kalam Full PDF
hetalvaishnav93
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 

Design and Analysis of Algorithms

  • 1. DESIGN AND ANALYSIS OF ALGORITHMSRemember this: “No problem is too tough if u spend enuf time on it” -A great manQuestion:an+bn=cn find a,b,c Answer: Ethoingayirukku!!an+bn=cn PRESENTED BY ARVIND KRISHNAA J
  • 2. CONTENTS OF THE UNITGRAPH TRAVERSALS
  • 6. BRANCH AND BOUND:GENERAL METHODS(FIFO & LC)
  • 8. INTRODUCTION TO NP-HARD AND NPCOMPLETENESSPRESENTED BY ARVIND KRISHNAA JUNIT –V SYLLABUS
  • 9. AIM:The main aim of any graph traversal algorithm is for a given graph G=(V,E) is to determine whether there exists a path starting from a vertex v to a vertex uPRESENTED BY ARVIND KRISHNAA JGRAPH TRAVERSALS
  • 10. PRESENTED BY ARVIND KRISHNAA JGRAPH TRAVERSALS
  • 11. PRESENTED BY ARVIND KRISHNAA JBREADTH FIRST SEARCHBASIC IDEA:Visits graph vertices by moving across to all the neighbors of last visited vertex b BFS uses a queuea vertex is inserted into queue when it is reached for the first time, and is marked as visited.a vertex is removed from the queue, when it identifies all unvisited vertices that are adjacent to the vertex b
  • 12. PRESENTED BY ARVIND KRISHNAA JALGORITHM FOR BFSvoid BFS(int v){//v being a starting vertexint u=v;Queue q[SIZE];visited[v]=1;do{for all vertices w adjacent to to u{ if(visited[w]==0)//w is unvisited {q.AddQ(w);visited[w]=1; }}if(Q.Empty()) return;q.Delete(u);}while(1);}
  • 13. PRESENTED BY ARVIND KRISHNAA JAN EXAMPLE GRAPH12364578
  • 14. PRESENTED BY ARVIND KRISHNAA JPERFORMING THE BREADTH FIRST TRAVERSALvoid BFT(graph G,int n){int i;boolean visited[SIZE];for(i=1;i<=n;i++)visited[i]=0;for(i=1;i<=n;i++)if(!visited[i]) BFS[i};}
  • 15. PRESENTED BY ARVIND KRISHNAA JDEPTH FIRST SEARCHBASIC IDEAStarting vertex is arbitrarily chosen or determined by the problem.Visits graph’s vertices by always moving away from last visited vertex to unvisited one, backtracks if no adjacent unvisited vertex is available.Uses a stacka vertex is pushed onto the stack when it’s reached for the first timea vertex is popped off the stack when it becomes a dead end, i.e., when there is no adjacent unvisited vertex
  • 16. PRESENTED BY ARVIND KRISHNAA JALGORITHM FOR DFSvoid DFS(int v){visited[v]=1;for each vertex w adjacent to v { if(!visited[w]) DFS[w];}}
  • 17. PRESENTED BY ARVIND KRISHNAA Jfor the graph.....ABDEC
  • 18. PRESENTED BY ARVIND KRISHNAA JAPPLICATIONSBREADTH FIRST SEARCH:Greedy graph algorithmsfinding the minimum spanning tree using PRIM’S ALGORITHMsingle source (or) all pair shortest path using DIJKSTRA’S ALGORITHMNETWORK FLOW PROBLEMTesting for connected componentsDEPTH FIRST SEARCH:Testing for biconnected components(bi-connectivity)for eg., checking for the connectivity of a network
  • 19. PRESENTED BY ARVIND KRISHNAA JCONNECTED COMPONENTSDEFINITION:Two vertices in a graph are in the same connected component if and only if there is a path from one vertex to the otherNOTE:BFS algorithm can be used to test whether a graph is connected or notIf a graph G is connected then only 1 call to the function BFT(G,n) is made
  • 20. The number of calls made to the BFT function can be used to roughly determine the number of “disconnected” componentsPRESENTED BY ARVIND KRISHNAA JDETERMINING A CONNECTED COMPONENTSTRATEGYAll newly visited vertices on a call to BFS represent vertices in a connected component of GTo display the connected components modify BFS to put newly visited vertices into a listConsider for the graph discussed previously.....
  • 21. PRESENTED BY ARVIND KRISHNAA JFOR THE DIRECTED GRAPHABCEDF
  • 22. PRESENTED BY ARVIND KRISHNAA JTHE DFS LIST ISELIST MADE IN THE FIRST CALLLIST MADE DURING THE SECOND CALLAs the number of calls made to the function is 2 it means that the graph is not connectedThere are two sets of connected components represented above
  • 23. PRESENTED BY ARVIND KRISHNAA JSPANNING TREEBFS SPANNING TREE1BFS SPANNING TREE:A spanning tree constructed by performing the Breadth first search of a graph2364578
  • 24. PRESENTED BY ARVIND KRISHNAA JSPANNING TREEDFS SPANNING TREE1DFS SPANNING TREE:A spanning tree constructed by performing the Depth first search of a graph2364578
  • 25. PRESENTED BY ARVIND KRISHNAA JBICONNECTED COMPONENTSNOTE: Henceforth the word “Graph” would be used instead of the term “undirected Graph”ARTICULATION POINT: A vertex v in a connected graph is said to be an articulation point if and only if the the deletion of the vertex v and all its edges incident to it “disconnects” the graph into two or more non-empty components.Biconnected graph: A graph G is said to be biconnected if and only if it contains no articulation pointsLet us see an example....
  • 26. PRESENTED BY ARVIND KRISHNAA JA connected graph156247The articulation points are highlighted...removing them causes disconnection83109
  • 27. PRESENTED BY ARVIND KRISHNAA JPOINTS TO NOTE LEMMA: Two biconnected components can have at most one vertex in common and this vertex is an articulation point.TRANSLATION: The common vertex of two biconnected components is an articulation point.NOTE: No edge can be in two different biconnected components as this would require two common vertices(violation of Lemma!!)
  • 28. PRESENTED BY ARVIND KRISHNAA JMAKING A CONNECTED GRAPH BICONNECTEDTECHNIQUE:Simply add “redundant” edges between the connected components that have the articulation point (say a) in common...for example the previously discussed connected graph can be made biconnected by adding the throbbing links(see next slide...if u r asleep pls continue...)
  • 29. PRESENTED BY ARVIND KRISHNAA JConnected to biconnected...156247The articulation points are highlighted...removing them causes disconnection83109
  • 30. PRESENTED BY ARVIND KRISHNAA JSCHEME TO CONSTRUCT A BICONNECTED COMPONENTfor each articulation point a{let B1,B2,…Bk be the biconnected components containing vertex a; let vi,vi≠a, be a vertex in Bi  , 1≤i≤k;add to G the edges (vi,vi+1),1≤i≤k;} 
  • 31. SIMPLE ALGORITHM:Construct a DFS spanning tree for the given graphHave parameters dfn[u],L[u]Do a preorder traversal of the spanning tree and compute dfn[u] for each node as the ith node that is visitedCompute the value of L[u] asPRESENTED BY ARVIND KRISHNAA JIDENTIFYING ARTICULATION POINTSL[u]=min{ dfn[u],min{L[w]|w is a child of u}, min{ dfn[w] | (u,w) is a back edge}
  • 32. SIMPLE ALGORITHM:Nodes which satisfy L[w]≥dfn[u], w being the children of u are identified as articulation pointsSPECIAL CASE OF ROOT NODENote: The root node is always listed as an articulation pointif root node has exactly one childthen exclude the root node from AP listelseroot node is also an articulation pointPRESENTED BY ARVIND KRISHNAA JIDENTIFYING ARTICULATION POINTS contd...
  • 33. PRESENTED BY ARVIND KRISHNAA JCOMPUTATIONS FOR THE GIVEN GRAPH
  • 34. Oh MahaZeeya..Oh MahaZeeya..NakkaMukkaNakka...Oh Shakalakka..Oh Randakka..(x2)Oh Laahi Oh Laahi..AyakaYahiYahi..Me Hoo..Me Hoo...DailamoDailamo..RahtullaSonali Oh..Oh MahaZeeya..Oh MahaZeeya..NakkaMukkaNakka...Oh Shakalakka..Oh Randakka..Samba Sambale..OsoseSayoSayo..HasiliFisili..Ilahi..YappaJippa..(x2)blah blahblablabla.......PRESENTED BY ARVIND KRISHNAA JRECAP OF YESTERDAY
  • 36. Review of Backtracking 1. Construct the state-space tree• nodes: partial solutions• edges: choices in extending partial solutions2. Explore the state space tree using depth-first search3. “Prune” nonpromising nodes• dfs stops exploring subtrees rooted at nodes that cannotlead to a solution and backtracks to such a node’sparent to continue the search
  • 39. Breadth first search(FIFO B&B) or D-search(LIFO B&B) is performed on the state space tree
  • 40. For each node (partial solution) of a state-space tree, computes a bound on the value of the objective function for all descendants of the node (extensions of the partial solution)
  • 42. ruling out certain nodes as “nonpromising” to prune the tree – if a node’s bound is not better than the best solution seen so far
  • 43. guiding the search through state-spaceExample: Assignment ProblemSelect one element in each row of the cost matrix C so that: no two selected elements are in the same column
  • 44. the sum is minimizedExampleJob1Job2Job3Job4 Person a 9 2 7 8 Person b 6 4 3 7 Person c 5 8 1 8 Person d 7 6 9 4Lower bound: Any solution to this problem will have total cost at least: 2 + 3 + 1 + 4 (or 5 + 2 + 1 + 4)‏N people n jobs cost should be small.
  • 45. Example: First two levels of the state-space tree
  • 46. ExplanationSelect 1st element from first row i.e9Select minimum from remaining rows 3, 1, 4 not from 1st columnSo 9+3+1+4 = 17.Select 2nd element from first row i.e2Select minimum from remaining rows 3, 1, 4 not from 2nd columnSo 2+3+1+4 = 10.Select 3rd element from first row i.e7Select minimum from remaining rows 3, 1, 4 not from 3rdcolumnSo 7+4+5+4 = 20.Last one it is 8+3+1+6 = 18
  • 48. Explanation(contd...)1. Select 2nd element from first row i.e 2Select 1st element from second row i.e 6Select minimum from remaining rows 1, 4 not from 1st columnSo 2+6+1+4 = 13.2. Select 2nd element from first row i.e 2Cannot Select 2nd element from second row 3. Select 2nd element from first row i.e 2Select 3rd element from third row i.e 3Select minimum from remaining rows 5, 4 not from 3rd columnSo 2+3+5+4 = 14.4. 2 + 7 + 1+7 =17Note: Promising node is live node a->2 is live node.
  • 51. Branch and boundApplicable to optimization problemThe state space tree is generated using best first rule.PRESENTED BY ARVIND KRISHNAA JCOMPARISON OF B&B AND BACKTRACKINGBacktrackingNot constrained but mostly applied to Non-optimization problem
  • 52. The state space tree is generated using DFSGreedy Algorithm for Knapsack ProblemStep 1: Order the items in decreasing order of relative values: v1/w1… vn/wnStep 2: Select the items in this order skipping those that don’t fit into the knapsackExample: The knapsack’s capacity is 15i Pi WiPi/Wi 1 $45 3 $15 2 $30 5 $ 6 3 $45 9 $ 5 4 $10 5 $ 2
  • 53. Branch and Bound Scheme for Knapsack ProblemStep 1: Order the items in decreasing order of relative values: v1/w1… vn/wnStep 2: For a given integer parameter k, 0 ≤ k ≤ n, generate allsubsets of k items or less and for each of those that fit the knapsack, add the remaining items in decreasingorder of their value to weight ratiosStep 3: Find the most valuable subset among the subsets generated in Step 2 and return it as the algorithm’s output
  • 54. bound (maximum potential value) = currentValue + value of remaining objects fully placed + (K - totalSize) * (value density of item that is partially placed) PRESENTED BY ARVIND KRISHNAA JSOME THINGS TO NOTEtotalSize = currentSize + size of remaining objects that can be fully placed
  • 55. k-1bound = currentValue+∑ vj + (K - totalSize) * (vk/sk)j=i+1For the root node, currentSize = 0, currentValue = 0PRESENTED BY ARVIND KRISHNAA JIN FORMULAEk-1totalSize = currentSize + ∑ sjj=i+1
  • 56. PRESENTED BY ARVIND KRISHNAA JTHE STATE-SPACE TREE(WITH BOUND)[PERFORMING A BFS TRAVERSAL]HENCE THE FINAL ANWER SET WOULD BEX={1,0,1,0}i.e., objects 1 and 3 are chosen...2 and 4 are discarded
  • 57. WHAT THE PREVIOUS PROBLEM DIDStep 1: We will construct the state space where each node contains the total current value in the knapsack, the total current size of the contents of the knapsack, and maximum potential value that the knapsack can hold. In the algorithm, we will also keep a record of the maximum value of any node (partially or completely filled knapsack) found so far.Step 2: Perform the breadth first traversal of the state space tree computing the bound and totalsizeStep 3: Discard(prune)those “non-promising nodes” which either have(a) a lower bound than the other nodes at same level (b) whose size exceeds the total knapsack capacityStep 4: The above method involving the BFS of the state space tree is called FIFO BRANCH & BOUND ALGORITHM
  • 58. LC ALGORITHM(LEAST COST)This is a generic form/generalization of both the BFS and DFS algorithms
  • 59. In LC algorithm a traversal is performed on the state space tree
  • 60. Each node is given a rank based on a minimization rule(also known as best first rule) f(x)(in case of the Knapsack problem the minimization rule can be stated as f(x)=--g(x),where g(x) is the maximization rule for the Knapsack problem)Once all nodes have been ranked eliminate/prune the nodes with the poorest ranks.
  • 61. Repeat till a feasible solution is obtained(sorry i cant go into too much further detail....its getting too mathematical...)
  • 63. Polynomial Time: Algorithms whose solution is found in polynomial timeeg., Sorting, searching etc.,Non-polynomial Time: Algorithms which DO NOT take polynomial time to find the solutioneg., Travelling salesperson problem (O(n22n)) PRESENTED BY ARVIND KRISHNAA JTWO KINDS OF ALGORITHMS
  • 64. Problems for which there is no polynomial time complexity, are computationally relatedThere are two classes of such problems1. NP HARD AND 2. NP COMPLETEPRESENTED BY ARVIND KRISHNAA JTWO KINDS OF ALGORITHMS
  • 65. The problem that is NP complete has the property that it can be solved in polynomial time if and only if all the other NP complete problems can be solved in polynomial timePRESENTED BY ARVIND KRISHNAA JNP COMPLETE
  • 66. If an NP-hard problem can be solved in ploynomial time, then all NP complete problems can also be solved in polynomial time.PRESENTED BY ARVIND KRISHNAA JNP HARD
  • 67. PRESENTED BY ARVIND KRISHNAA JSET REPRESENTATION OF THE ABOVE STATEMENTSNPNP HARDPNP COMPLETE
  • 68. Deterministic Algorithm: Has the property that result of every operation is uniquely definedNon-Deterministic Algorithm: Outcome of an operation is not uniquely definedPRESENTED BY ARVIND KRISHNAA JNON DETERMINISTIC ALGORITHMS
  • 69. Every non-deterministic algorithm makes use of three functionschoice(S): arbitrarily choosing an element in a s et S for eg., x=choice(1,n) | means x€[1,n]failure(): unsuccessful completionsuccess(): successful completionPRESENTED BY ARVIND KRISHNAA JTHREE NEW FUNCTIONS
  • 70. NON DETERMINISTIC SEARCHINGND SORTINGMAXIMUM CLIQUE PROBLEM0/1 KANPSACK PROBLEMSATISFIABLITYand many, many morePRESENTED BY ARVIND KRISHNAA JSOME EXAMPLES OF NON-DETERMINISTIC ALGORITHMS
  • 72. voidnondeterministic_sort(int A[],int n){int B[SIZE],i,j;for(i=1;i<=n;i++) B[i]=0;for(i=1;i<=n;i++){ j=choice(1,n); if(B[j]) failure(); B[j]=A[i];}for(i=1;i<=n;i++)//verify order if(B[i] > B[i+1]) failure();for(i=1;i<=n;i++)cout<<B[i]<<‘ ‘;success();}PRESENTED BY ARVIND KRISHNAA JNON DETERMINISTIC SORTING
  • 73. void DCK(int G[]{SIZE],intn,int k){S=null;//initially emptyfor(int i=1;i<=k;i++){int t=choice(1,n); if(t is in S) failure(); S=S U {t};}//now S contains k distinct verticesfor(all pairs (i,j) such that i is in S,j is in S and i!=j) if((i,j) is not an edge of G) failure();success();}PRESENTED BY ARVIND KRISHNAA JNON DETERMINISTIC Clique
  • 74. void DKP(int p[],int w[],intn,intm,intr,int x[]){int W=0,P=0;for(int i=1;i<=n;i++){ x[i]=choice(0,1); W+=x[i]*w[i]; P+=x[i]*p[i];}if((W>m) || (P < r)) failure();else success();}PRESENTED BY ARVIND KRISHNAA JNON DETERMINISTIC KNAPSACK
  • 75. void eval(cnfE,int n)//determine whether the prop. formula is satisfiable//variables are x[1],x[2],x[3],...x[n]{int x[SIZE];//choose a truth value assignmentfor(int i=1;i<=n;i++)x[i]=choice(0,1);if(E(x,n))success();else failure();}PRESENTED BY ARVIND KRISHNAA JNON DETERMINISTIC SATISFIABLITY
  • 76. GRAPH PROBLEMS LIKENODE COVERING PROBLEMGRAPH COMPLEMENT PROBLEMSCHEDULING PROBLEMSCODE GENERATION PROBLEMand many morePRESENTED BY ARVIND KRISHNAA JSOME EXAMPLES OF NP HARD PROBLEMS
  • 77. CHECK OUT THE TEXTBOOKPAGE NO571PRESENTED BY ARVIND KRISHNAA JSOME EXAMPLES OF NP complete PROBLEMS
  • 78. APPROXIMATIONRANDOMIZATIONRESTRICTIONPARAMETRIZATIONHEURISTICSPRESENTED BY ARVIND KRISHNAA JBASIC TEHNIQUES INVOLVED IN SOLVING NP COMPLETE PROBLEMSOR IN SHORT PERFORMING A NON-DETERMINISTIC ANALYSIS ON THE PROBLEM
  • 79. ONE FINAL QUESTIONRemember this: “No problem is too tough if u spend enuf time on it” -A great manPRESENTED BY ARVIND KRISHNAA JWHO IS THIS GREAT MAN???
  • 80. THANK YOU!!!!!PRESENTED BY ARVIND KRISHNAA J