SlideShare a Scribd company logo
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

More Related Content

What's hot

I. Mini-Max Algorithm in AI
I. Mini-Max Algorithm in AII. Mini-Max Algorithm in AI
I. Mini-Max Algorithm in AI
vikas dhakane
 
I. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in aiI. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in ai
vikas dhakane
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Merge Sort
Merge SortMerge Sort
Merge Sort
Nikhil Sonkamble
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Presentation of daa on approximation algorithm and vertex cover problem
Presentation of daa on approximation algorithm and vertex cover problem Presentation of daa on approximation algorithm and vertex cover problem
Presentation of daa on approximation algorithm and vertex cover problem
sumit gyawali
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
Abhimanyu Mishra
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
Lec 5 uncertainty
Lec 5 uncertaintyLec 5 uncertainty
Lec 5 uncertainty
Eyob Sisay
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Dr Shashikant Athawale
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
Sahil Kumar
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
Mahmoud Hussein
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
GovindUpadhyay25
 
Arithmetic coding
Arithmetic codingArithmetic coding
Arithmetic coding
Vikas Goyal
 
Backtracking
BacktrackingBacktracking
Backtracking
Pranay Meshram
 
Elements of Dynamic Programming
Elements of Dynamic ProgrammingElements of Dynamic Programming
Elements of Dynamic Programming
Vishwajeet Shabadi
 
Backtracking
BacktrackingBacktracking
Backtracking
Dr. Jaydeep Patil
 

What's hot (20)

I. Mini-Max Algorithm in AI
I. Mini-Max Algorithm in AII. Mini-Max Algorithm in AI
I. Mini-Max Algorithm in AI
 
I. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in aiI. Alpha-Beta Pruning in ai
I. Alpha-Beta Pruning in ai
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Presentation of daa on approximation algorithm and vertex cover problem
Presentation of daa on approximation algorithm and vertex cover problem Presentation of daa on approximation algorithm and vertex cover problem
Presentation of daa on approximation algorithm and vertex cover problem
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
Lec 5 uncertainty
Lec 5 uncertaintyLec 5 uncertainty
Lec 5 uncertainty
 
Array Processor
Array ProcessorArray Processor
Array Processor
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
 
Arithmetic coding
Arithmetic codingArithmetic coding
Arithmetic coding
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Fibonacci Heap
Fibonacci HeapFibonacci Heap
Fibonacci Heap
 
Elements of Dynamic Programming
Elements of Dynamic ProgrammingElements of Dynamic Programming
Elements of Dynamic Programming
 
Backtracking
BacktrackingBacktracking
Backtracking
 

Similar to Algorithms Design Patterns

Divide and Conquer Case Study
Divide and Conquer Case StudyDivide and Conquer Case Study
Divide and Conquer Case Study
KushagraChadha1
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programming
Amisha Narsingani
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
Nirmalavenkatachalam
 
Unit V.pdf
Unit V.pdfUnit 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
rajesshs31r
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And Conquer
UrviBhalani2
 
Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
jinalgoti
 
Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
snehajiyani
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
Amrinder Arora
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Yıldırım Tam
 
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
Laguna State Polytechnic University
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
Bulbul 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 method
JyoReddy9
 
CH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptxCH-1.1 Introduction (1).pptx
CH-1.1 Introduction (1).pptx
satvikkushwaha1
 
Types of Algorithms.ppt
Types of Algorithms.pptTypes of Algorithms.ppt
Types of Algorithms.ppt
ALIZAIB KHAN
 
Algorithm and Complexity-Lesson 1.pptx
Algorithm and Complexity-Lesson 1.pptxAlgorithm and Complexity-Lesson 1.pptx
Algorithm and Complexity-Lesson 1.pptx
Apasra R
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
Ruchika Sinha
 
Comparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesComparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategies
Talha Shaikh
 

Similar to 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
 

Recently uploaded

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

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