SlideShare une entreprise Scribd logo
1  sur  31
Algorithms Design Approach/Patterns
1. DIVIDE AND CONQUER
2. Greedy Algorithms
3. Dynamic programing
4. BackTracking
5. Branch and Bound By
Name: Ashwin Shiv
Roll No:181210013
CSE 2nd Year
NIT Delhi
DIVIDE AND CONQUER
DIVIDE AND CONQUER -3 Part TOP
DOWN APPROCH
 TOP down Approach to design Algorithms
1) Divide : Divide the problem into sub problem that is similar to original problem
2) Conquer Solve the problem recursively
3) Combine : Combine the solution of sub problem to create the solution of
original problem
APPLICATION OF D&C ALOGORATHIM
 Binary Search
 Finding Max and Min
 Merge Sort
 Quick Sort
 Strassen Matrix Multiplication
 Convex hull
DIVIDE and CONQUER – APPROCH
ALGO DANDC (P)
{
if small (p) then return S(p)
else
{
divide P in smaller p1, p2...pk where k >=1
apply DANDC to each sub problem Recursively
return combine ( DANDC(p1), DANDC(p1) ……………… DANDC(pk))
}
}
Greedy Algorithms
Greedy Algorithms
 A greedy algorithm is an algorithm that constructs an object X one step at a time,
at each step choosing the locally best option.
 In some cases, greedy algorithms construct the globally best object by repeatedly
choosing the locally best option.
Greedy Algorithms – Advantages
Greedy algorithms have several advantages over other algorithmic approaches:
● Simplicity: Greedy algorithms are often easier to describe and code up than other
algorithms.
● Efficiency: Greedy algorithms can often be implemented more efficiently than other
algorithms.
Greedy Algorithms – DIS Advantages
Greedy algorithms have several drawbacks:
● Hard to design: Once you have found the right greedy approach, designing greedy
algorithms can be easy. However, finding the right approach can be hard.
● Hard to verify: Showing a greedy algorithm is correct often requires a nuanced
argument.
Greedy Algorithms – APPROCH
ALGO GREDDY ( a, n)
{
solution = 0;
for i to n do
{
x = select (a) ;
if feasible (solution , x ) ;
then solution Union (solution , x) ;
}
return solution;
}
Applications OF Greedy Algorithms
 Activity Selection
 Huffman coding
 Job Sequencing
 Knap Snap
 Minimum Spanning tree
 Single Source shortest Path
 Bellman ford Algorithm
 Dijkstra’s Algorithm
Dynamic Programming
Dynamic Programming
 Used to solve optimization problems.
1. Breaks down the complex problems into simpler subproblems.
2. Find optimal solution to these subproblems.
3. Store the results of these subproblems so that it can be reused later.
4. Finally Calculates the result of complex sub-problem.
Dynamic Programming– Advantages
 Time Complexity will be always less because it reduces the line code
 It speeds up the processing as we use previously calculated intermediate values.
Dynamic Programming– Disadvantages
 Space Complexity would be more as dividing problem in sub problem and storing
intermediate results in consuming memory.
APPLICATION OF Dynamic Programming
 Cutting a rod into pieces to Maximize Profit
 Matrix Chain Multiplication
 Longest Common Subsequence
 Optimal Binary Search Tree
 Travelling Salesman Problem
 0/1 Knapsack Problem
BackTracking
BackTracking
 Backtracing uses bruit force approach to solve the problem.
 The Algorithmic Approach – Backtracking systematically try and search
possibilities to find the solution.
 Brute force approach say for any given problem generate all possible solution and
pick a desire solution.
 Generate depth first search to generate state space tree.
BackTracking– Advantages
 Comparison with the Dynamic Programming, Backtracking Approach is more effective
in some cases.
 Backtracking Algorithm is the best option for solving tactical problem.
 Also Backtracking is effective for constraint satisfaction problem.
 In greedy Algorithm, getting the Global Optimal Solution is a long procedure and
depends on user statements but in Backtracking It Can Easily getable.
 Backtracking technique is simple to implement and easy to code.
 Different states are stored into stack so that the data or Info can be usable anytime.
 The accuracy is granted.
BackTracking– DisAdvantages
– Backtracking Approach is not efficient for solving strategic Problem.
– The overall runtime of Backtracking Algorithm is normally slow
– To solve Large Problem Sometime it needs to take the help of other techniques like
Branch and bound.
– Need Large amount of memory space for storing different state function in the
stack for big problem.
– Thrashing is one of the main problem of Backtracking. – The Basic Approach
Detects the conflicts too late.
BackTracking– APPROCH
Backtrack (v1,Vi)
{
If (V1,……., Vi) is a Solution Then
Return (V1,…, Vi)
For each v DO
If (V1,…….,Vi) is acceptable vector THEN
Solution = try (V1,…,Vi, V);
If Solution != () Then
RETURN Solution ;
}
}
}
APPLICATION OF BackTracking
 N Queen Problem
 Sum of subset problem
 Graph Coloring problem
 Hamiltonian Circuit Problem
 Maze Problem
Branch and Bound
Branch and Bound
 Branch and bound is an algorithm design paradigm which is generally used for solving
combinatorial optimization problems.
 These problems are typically exponential in terms of time complexity and may require exploring all
possible permutations in worst case.
 The Branch and Bound Algorithm technique solves these problems relatively quickly.
 BFS (Brute-Force)We can perform a Breadth-first search on the state space tree. This always
finds a goal state nearest to the root. But no matter what the initial state is, the algorithm attempts
the same sequence of moves like Depth-first-search DFS.
 Branch and Bound. The search for an answer node can often be speeded by using an “intelligent”
ranking function, also called an approximate cost function to avoid searching in sub-trees that do
not contain an answer node. It is similar to the backtracking technique but uses BFS-like search
Branch and Bound– APPROCH
 FIFO Branch Bound ( First IN First OUT)
 LIFO Branch Bound ( Last IN First OUT)
 LC Branch Bound ( Least Cost )
APPLICATION OF Branch and Bound
 0/1 Knapsack Problem using Least Cost Branch and Bound Algorithm
 Travelling Salesman Problem using Branch and Bound
0/1 Knapsack Problem using Dynamic
Programming
• In these kinds of problems,we are given some items with weights and profits.
• The 0/1 denotes that either you will not pick the item(0) or you can pick the item completely(1).
• Cannot take a fractional amount of an item taken or take an item more than once.
• It cannot be solved by the Greedy Approach because it is enable to fill the knapsack to capacity.
• In simple words,0/1 Knapsack Problem means that we want to pack n items in a bag(knapsack):
1. The ith item is worth pi(profit) and weight wi kg.
2. Take as valuable a load as possible, but cannot exceed W pounds.
3. pi,wi,W are integers.
Why Dynamic Programming to solve 0/1
Knapsack Problem?
 It is a very helpful problem in combinatorics.
 Recomputation is avoided as it stores the result of previous subproblem so that it
can be used again in solving another subproblem.
Algorithm
Knapsack(n,cw)
1. int M[][] = new int[n + 1][cw + 1];//Build a memoization matrix in bottom up manner.
2. for i<-0 to n
3. for w<-0 to cw
4. if (i == 0 || w == 0) then
5. M[i][w] = 0;
6. else if(gwt[i - 1]<= w) then
7. M[i][w] = max(pro[i - 1] + M[i - 1][w - gwt[i - 1]], M[i - 1][w])
8. else
9. M[i][w] = M[i - 1][w]
10. return M[n][cw]
Code in Java to solve 0-1 Knapsack problem Solution
using Dynamic Programming to get Maximum Profit
My Java
Program
0/1 Knapsack Problem using Dynamic Programming
Algorithms Design Patterns

Contenu connexe

Tendances

Minmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slidesMinmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slidesSamiaAziz4
 
Computing Environments.pptx
Computing Environments.pptxComputing Environments.pptx
Computing Environments.pptxMSivani
 
Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Bhatt Balkrishna
 
Go back-n protocol
Go back-n protocolGo back-n protocol
Go back-n protocolSTEFFY D
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using BacktrackingAbhishek Singh
 
Data Encryption Standard (DES)
Data Encryption Standard (DES)Data Encryption Standard (DES)
Data Encryption Standard (DES)Haris Ahmed
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and boundAbhishek Singh
 
Distance Vector Routing Protocols
Distance Vector Routing ProtocolsDistance Vector Routing Protocols
Distance Vector Routing ProtocolsKABILESH RAMAR
 
MPI message passing interface
MPI message passing interfaceMPI message passing interface
MPI message passing interfaceMohit Raghuvanshi
 
Diffie hellman key exchange algorithm
Diffie hellman key exchange algorithmDiffie hellman key exchange algorithm
Diffie hellman key exchange algorithmSunita Kharayat
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating SystemsRitu Ranjan Shrivastwa
 
program flow mechanisms, advanced computer architecture
program flow mechanisms, advanced computer architectureprogram flow mechanisms, advanced computer architecture
program flow mechanisms, advanced computer architecturePankaj Kumar Jain
 
Introduction to parallel processing
Introduction to parallel processingIntroduction to parallel processing
Introduction to parallel processingPage Maker
 

Tendances (20)

Minmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slidesMinmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slides
 
Computing Environments.pptx
Computing Environments.pptxComputing Environments.pptx
Computing Environments.pptx
 
Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming
 
Telnet
TelnetTelnet
Telnet
 
Assemblers
AssemblersAssemblers
Assemblers
 
Go back-n protocol
Go back-n protocolGo back-n protocol
Go back-n protocol
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Data Encryption Standard (DES)
Data Encryption Standard (DES)Data Encryption Standard (DES)
Data Encryption Standard (DES)
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Iterations and Recursions
Iterations and RecursionsIterations and Recursions
Iterations and Recursions
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
Distance Vector Routing Protocols
Distance Vector Routing ProtocolsDistance Vector Routing Protocols
Distance Vector Routing Protocols
 
Multi Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing MachineMulti Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing Machine
 
MPI message passing interface
MPI message passing interfaceMPI message passing interface
MPI message passing interface
 
Diffie hellman key exchange algorithm
Diffie hellman key exchange algorithmDiffie hellman key exchange algorithm
Diffie hellman key exchange algorithm
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
program flow mechanisms, advanced computer architecture
program flow mechanisms, advanced computer architectureprogram flow mechanisms, advanced computer architecture
program flow mechanisms, advanced computer architecture
 
Semaphores
SemaphoresSemaphores
Semaphores
 
Introduction to parallel processing
Introduction to parallel processingIntroduction to parallel processing
Introduction to parallel processing
 

Similaire à Algorithms Design Patterns

Divide and Conquer Case Study
Divide and Conquer Case StudyDivide and Conquer Case Study
Divide and Conquer Case StudyKushagraChadha1
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programmingAmisha Narsingani
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesNirmalavenkatachalam
 
Analysis of Algorithm II Unit version .pptx
Analysis of Algorithm  II Unit version .pptxAnalysis of Algorithm  II Unit version .pptx
Analysis of Algorithm II Unit version .pptxrajesshs31r
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And ConquerUrviBhalani2
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchAmrinder Arora
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of AlgorithmsBulbul Agrawal
 
Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodModule 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodJyoReddy9
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxsatvikkushwaha1
 
Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.pptALIZAIB KHAN
 
Algorithm and Complexity-Lesson 1.pptx
Algorithm and Complexity-Lesson 1.pptxAlgorithm and Complexity-Lesson 1.pptx
Algorithm and Complexity-Lesson 1.pptxApasra R
 
Optimization problems
Optimization problemsOptimization problems
Optimization problemsRuchika Sinha
 
Comparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesComparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesTalha Shaikh
 

Similaire à Algorithms Design Patterns (20)

Divide and Conquer Case Study
Divide and Conquer Case StudyDivide and Conquer Case Study
Divide and Conquer Case Study
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programming
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
 
Unit V.pdf
Unit V.pdfUnit V.pdf
Unit V.pdf
 
Analysis of Algorithm II Unit version .pptx
Analysis of Algorithm  II Unit version .pptxAnalysis of Algorithm  II Unit version .pptx
Analysis of Algorithm II Unit version .pptx
 
DAA UNIT 3
DAA UNIT 3DAA UNIT 3
DAA UNIT 3
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And Conquer
 
Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
 
Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Data Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and ConquerData Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and Conquer
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
 
Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodModule 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
 
Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.ppt
 
Algorithm and Complexity-Lesson 1.pptx
Algorithm and Complexity-Lesson 1.pptxAlgorithm and Complexity-Lesson 1.pptx
Algorithm and Complexity-Lesson 1.pptx
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
 
Comparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesComparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategies
 

Dernier

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 

Dernier (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 

Algorithms Design Patterns

  • 1. Algorithms Design Approach/Patterns 1. DIVIDE AND CONQUER 2. Greedy Algorithms 3. Dynamic programing 4. BackTracking 5. Branch and Bound By Name: Ashwin Shiv Roll No:181210013 CSE 2nd Year NIT Delhi
  • 3. DIVIDE AND CONQUER -3 Part TOP DOWN APPROCH  TOP down Approach to design Algorithms 1) Divide : Divide the problem into sub problem that is similar to original problem 2) Conquer Solve the problem recursively 3) Combine : Combine the solution of sub problem to create the solution of original problem
  • 4. APPLICATION OF D&C ALOGORATHIM  Binary Search  Finding Max and Min  Merge Sort  Quick Sort  Strassen Matrix Multiplication  Convex hull
  • 5. DIVIDE and CONQUER – APPROCH ALGO DANDC (P) { if small (p) then return S(p) else { divide P in smaller p1, p2...pk where k >=1 apply DANDC to each sub problem Recursively return combine ( DANDC(p1), DANDC(p1) ……………… DANDC(pk)) } }
  • 7. Greedy Algorithms  A greedy algorithm is an algorithm that constructs an object X one step at a time, at each step choosing the locally best option.  In some cases, greedy algorithms construct the globally best object by repeatedly choosing the locally best option.
  • 8. Greedy Algorithms – Advantages Greedy algorithms have several advantages over other algorithmic approaches: ● Simplicity: Greedy algorithms are often easier to describe and code up than other algorithms. ● Efficiency: Greedy algorithms can often be implemented more efficiently than other algorithms.
  • 9. Greedy Algorithms – DIS Advantages Greedy algorithms have several drawbacks: ● Hard to design: Once you have found the right greedy approach, designing greedy algorithms can be easy. However, finding the right approach can be hard. ● Hard to verify: Showing a greedy algorithm is correct often requires a nuanced argument.
  • 10. Greedy Algorithms – APPROCH ALGO GREDDY ( a, n) { solution = 0; for i to n do { x = select (a) ; if feasible (solution , x ) ; then solution Union (solution , x) ; } return solution; }
  • 11. Applications OF Greedy Algorithms  Activity Selection  Huffman coding  Job Sequencing  Knap Snap  Minimum Spanning tree  Single Source shortest Path  Bellman ford Algorithm  Dijkstra’s Algorithm
  • 13. Dynamic Programming  Used to solve optimization problems. 1. Breaks down the complex problems into simpler subproblems. 2. Find optimal solution to these subproblems. 3. Store the results of these subproblems so that it can be reused later. 4. Finally Calculates the result of complex sub-problem.
  • 14. Dynamic Programming– Advantages  Time Complexity will be always less because it reduces the line code  It speeds up the processing as we use previously calculated intermediate values.
  • 15. Dynamic Programming– Disadvantages  Space Complexity would be more as dividing problem in sub problem and storing intermediate results in consuming memory.
  • 16. APPLICATION OF Dynamic Programming  Cutting a rod into pieces to Maximize Profit  Matrix Chain Multiplication  Longest Common Subsequence  Optimal Binary Search Tree  Travelling Salesman Problem  0/1 Knapsack Problem
  • 18. BackTracking  Backtracing uses bruit force approach to solve the problem.  The Algorithmic Approach – Backtracking systematically try and search possibilities to find the solution.  Brute force approach say for any given problem generate all possible solution and pick a desire solution.  Generate depth first search to generate state space tree.
  • 19. BackTracking– Advantages  Comparison with the Dynamic Programming, Backtracking Approach is more effective in some cases.  Backtracking Algorithm is the best option for solving tactical problem.  Also Backtracking is effective for constraint satisfaction problem.  In greedy Algorithm, getting the Global Optimal Solution is a long procedure and depends on user statements but in Backtracking It Can Easily getable.  Backtracking technique is simple to implement and easy to code.  Different states are stored into stack so that the data or Info can be usable anytime.  The accuracy is granted.
  • 20. BackTracking– DisAdvantages – Backtracking Approach is not efficient for solving strategic Problem. – The overall runtime of Backtracking Algorithm is normally slow – To solve Large Problem Sometime it needs to take the help of other techniques like Branch and bound. – Need Large amount of memory space for storing different state function in the stack for big problem. – Thrashing is one of the main problem of Backtracking. – The Basic Approach Detects the conflicts too late.
  • 21. BackTracking– APPROCH Backtrack (v1,Vi) { If (V1,……., Vi) is a Solution Then Return (V1,…, Vi) For each v DO If (V1,…….,Vi) is acceptable vector THEN Solution = try (V1,…,Vi, V); If Solution != () Then RETURN Solution ; } } }
  • 22. APPLICATION OF BackTracking  N Queen Problem  Sum of subset problem  Graph Coloring problem  Hamiltonian Circuit Problem  Maze Problem
  • 24. Branch and Bound  Branch and bound is an algorithm design paradigm which is generally used for solving combinatorial optimization problems.  These problems are typically exponential in terms of time complexity and may require exploring all possible permutations in worst case.  The Branch and Bound Algorithm technique solves these problems relatively quickly.  BFS (Brute-Force)We can perform a Breadth-first search on the state space tree. This always finds a goal state nearest to the root. But no matter what the initial state is, the algorithm attempts the same sequence of moves like Depth-first-search DFS.  Branch and Bound. The search for an answer node can often be speeded by using an “intelligent” ranking function, also called an approximate cost function to avoid searching in sub-trees that do not contain an answer node. It is similar to the backtracking technique but uses BFS-like search
  • 25. Branch and Bound– APPROCH  FIFO Branch Bound ( First IN First OUT)  LIFO Branch Bound ( Last IN First OUT)  LC Branch Bound ( Least Cost )
  • 26. APPLICATION OF Branch and Bound  0/1 Knapsack Problem using Least Cost Branch and Bound Algorithm  Travelling Salesman Problem using Branch and Bound
  • 27. 0/1 Knapsack Problem using Dynamic Programming • In these kinds of problems,we are given some items with weights and profits. • The 0/1 denotes that either you will not pick the item(0) or you can pick the item completely(1). • Cannot take a fractional amount of an item taken or take an item more than once. • It cannot be solved by the Greedy Approach because it is enable to fill the knapsack to capacity. • In simple words,0/1 Knapsack Problem means that we want to pack n items in a bag(knapsack): 1. The ith item is worth pi(profit) and weight wi kg. 2. Take as valuable a load as possible, but cannot exceed W pounds. 3. pi,wi,W are integers.
  • 28. Why Dynamic Programming to solve 0/1 Knapsack Problem?  It is a very helpful problem in combinatorics.  Recomputation is avoided as it stores the result of previous subproblem so that it can be used again in solving another subproblem.
  • 29. Algorithm Knapsack(n,cw) 1. int M[][] = new int[n + 1][cw + 1];//Build a memoization matrix in bottom up manner. 2. for i<-0 to n 3. for w<-0 to cw 4. if (i == 0 || w == 0) then 5. M[i][w] = 0; 6. else if(gwt[i - 1]<= w) then 7. M[i][w] = max(pro[i - 1] + M[i - 1][w - gwt[i - 1]], M[i - 1][w]) 8. else 9. M[i][w] = M[i - 1][w] 10. return M[n][cw]
  • 30. Code in Java to solve 0-1 Knapsack problem Solution using Dynamic Programming to get Maximum Profit My Java Program 0/1 Knapsack Problem using Dynamic Programming