SlideShare a Scribd company logo
1 of 12
Prepared By:
Dr. Chandan Kumar
Assistant Professor, Computer Science & Engineering Department
Invertis University, Bareilly
Introduction
Algorithm
Divide &
Conquer
Greedy Brute Force
Dynamic
Programming
Backtracking Recursive
Branch &
Bound
Randomized
Divide and Conquer
 It is an algorithm design paradigm which is based on
multi branch recursion.
 The divide-and-conquer paradigm is often used to find
an optimal solution to a problem.
 It is a technique to break a problem recursively into
sub-problems of the same or related type.
 Sub-programs have to be simple enough to be solved
directly.
 The solutions to these sub-problems are then
combined to solve the original problem
Divide and Conquer
 D&C follow following three steps
 Divide/Break- Break original problem into sub-
problems
 Conquer/Solve - Solve every individual sub-problem,
recursively
 Combine/Merge- Place the solutions to the sub-
problems together to solve the entire problem
Divide and Conquer
 In short, D&C is a approach in which the entire
problem (i.e. too large to comprehend or overcome at
once) is divided into smaller pieces, the pieces are
solved separately, and all the pieces are combined
together.
Example
Implementation
 Program to calculate pow(x,n) in C language
#include<stdio.h>
#include<conio.h>
/* Function to calculate x raised to the power y */
int power(int x, unsigned int y)
{
if (y == 0)
return 1;
else if (y%2 == 0)
return power(x, y/2)*power(x, y/2);
Implementation
else
return x*power(x, y/2)*power(x, y/2);
}
/* Program to test function power */
int main()
{
int x = 2;
unsigned int y = 3;
printf("%d", power(x, y));
return 0;
}
Application
 Following computer algorithms are based on divide
and conquer programming approach
 Bineary Search
 Merge Sort
 Quick Sort
 Maximum and Minimum Problem
 Tower of Hanoi
 Strassen's Matrix multiplication
 Karatsuba Algorithm
Complexity
 The complexity of the divide-and-conquer algorithm is
calculated using the master theorem.
T(n) = aT(n/b) + f(n), where
n = size of input
a = number of sub-problems in the recursion
n/b = size of each sub-problem. All sub-problems are
assumed to have the same size
f(n) = cost of the work done outside the recursive call,
which includes the cost of dividing the problem and
cost of merging the solutions
Advantages
 The complexity for the multiplication of two matrices
using the naive method is O(n3), whereas using the
divide and conquer approach (ie. Strassen's matrix
multiplication) is O(n2.8074).
 This strategy also simplifies other issues such as the
Tower of Hanoi.
 Suitable for multiprocessing systems.
 It does use memory caches effectively.
Divide and Conquer Algorithm Guide

More Related Content

What's hot

Algorithm Design Presentation
Algorithm Design PresentationAlgorithm Design Presentation
Algorithm Design PresentationKawsar Ahmed
 
Linear programming: A Geometric Approach
Linear programming: A Geometric ApproachLinear programming: A Geometric Approach
Linear programming: A Geometric ApproachEFREN ARCHIDE
 
Linear programming
Linear programmingLinear programming
Linear programmingKarnav Rana
 
LINEAR PROGRAMMING Assignment help
LINEAR PROGRAMMING Assignment helpLINEAR PROGRAMMING Assignment help
LINEAR PROGRAMMING Assignment helpjohn mayer
 
Notion of an algorithm
Notion of an algorithmNotion of an algorithm
Notion of an algorithmNisha Soms
 
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...Simplilearn
 
Mat 540 week 9 quiz 5
Mat 540 week 9  quiz 5  Mat 540 week 9  quiz 5
Mat 540 week 9 quiz 5 getwisdom
 
Introduction to linear programming
Introduction to linear programmingIntroduction to linear programming
Introduction to linear programmingn_cool001
 
Ds03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhaniDs03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhanijyoti_lakhani
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesFellowBuddy.com
 
Ms 51 operations research
Ms 51 operations researchMs 51 operations research
Ms 51 operations researchsmumbahelp
 
Fundamental Programming Lect 4
Fundamental Programming Lect 4Fundamental Programming Lect 4
Fundamental Programming Lect 4Namrah Erum
 
Algorithm and Data Structures - Basic of IT Problem Solving
Algorithm and Data Structures - Basic of IT Problem SolvingAlgorithm and Data Structures - Basic of IT Problem Solving
Algorithm and Data Structures - Basic of IT Problem Solvingcoolpie
 

What's hot (19)

Algorithm Design
Algorithm DesignAlgorithm Design
Algorithm Design
 
Algorithm Design Presentation
Algorithm Design PresentationAlgorithm Design Presentation
Algorithm Design Presentation
 
Linear programming: A Geometric Approach
Linear programming: A Geometric ApproachLinear programming: A Geometric Approach
Linear programming: A Geometric Approach
 
Linear programing
Linear programingLinear programing
Linear programing
 
Dynamic Programming | Economics
Dynamic Programming | EconomicsDynamic Programming | Economics
Dynamic Programming | Economics
 
Linear programming
Linear programmingLinear programming
Linear programming
 
ADA complete notes
ADA complete notesADA complete notes
ADA complete notes
 
LINEAR PROGRAMMING Assignment help
LINEAR PROGRAMMING Assignment helpLINEAR PROGRAMMING Assignment help
LINEAR PROGRAMMING Assignment help
 
Problem solving
Problem solvingProblem solving
Problem solving
 
Notion of an algorithm
Notion of an algorithmNotion of an algorithm
Notion of an algorithm
 
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
 
Mat 540 week 9 quiz 5
Mat 540 week 9  quiz 5  Mat 540 week 9  quiz 5
Mat 540 week 9 quiz 5
 
Introduction to linear programming
Introduction to linear programmingIntroduction to linear programming
Introduction to linear programming
 
Ds03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhaniDs03 algorithms jyoti lakhani
Ds03 algorithms jyoti lakhani
 
Empirical analysis
Empirical analysisEmpirical analysis
Empirical analysis
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
 
Ms 51 operations research
Ms 51 operations researchMs 51 operations research
Ms 51 operations research
 
Fundamental Programming Lect 4
Fundamental Programming Lect 4Fundamental Programming Lect 4
Fundamental Programming Lect 4
 
Algorithm and Data Structures - Basic of IT Problem Solving
Algorithm and Data Structures - Basic of IT Problem SolvingAlgorithm and Data Structures - Basic of IT Problem Solving
Algorithm and Data Structures - Basic of IT Problem Solving
 

Similar to Divide and Conquer Algorithm Guide

Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design PatternsAshwin Shiv
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesNirmalavenkatachalam
 
Merge sort data structures
Merge sort data structuresMerge sort data structures
Merge sort data structureschauhankapil
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)Mumtaz Ali
 
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
 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdfpasinduneshan
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And ConquerUrviBhalani2
 
Chapter 6-INTEGER PROGRAMMING note.pdf
Chapter 6-INTEGER PROGRAMMING  note.pdfChapter 6-INTEGER PROGRAMMING  note.pdf
Chapter 6-INTEGER PROGRAMMING note.pdfTsegay Berhe
 
Dynamic programming prasintation eaisy
Dynamic programming prasintation eaisyDynamic programming prasintation eaisy
Dynamic programming prasintation eaisyahmed51236
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdfishan743441
 
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
 
Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1 Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1 To Sum It Up
 
Divide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic ProgrammingDivide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic ProgrammingGuillaume Guérard
 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptxMuktarHossain13
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithmNikitagupta123
 

Similar to Divide and Conquer Algorithm Guide (20)

Algorithms Design Patterns
Algorithms Design PatternsAlgorithms Design Patterns
Algorithms Design Patterns
 
Divide and Conquer / Greedy Techniques
Divide and Conquer / Greedy TechniquesDivide and Conquer / Greedy Techniques
Divide and Conquer / Greedy Techniques
 
Merge sort data structures
Merge sort data structuresMerge sort data structures
Merge sort data structures
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
 
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
 
complexity analysis.pdf
complexity analysis.pdfcomplexity analysis.pdf
complexity analysis.pdf
 
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
 
Chapter 6-INTEGER PROGRAMMING note.pdf
Chapter 6-INTEGER PROGRAMMING  note.pdfChapter 6-INTEGER PROGRAMMING  note.pdf
Chapter 6-INTEGER PROGRAMMING note.pdf
 
Dynamic programming prasintation eaisy
Dynamic programming prasintation eaisyDynamic programming prasintation eaisy
Dynamic programming prasintation eaisy
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.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
 
Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1 Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1
 
ADA Unit 2.pptx
ADA Unit 2.pptxADA Unit 2.pptx
ADA Unit 2.pptx
 
Divide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic ProgrammingDivide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic Programming
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptx
 
Recursion in Java
Recursion in JavaRecursion in Java
Recursion in Java
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithm
 

More from CHANDAN KUMAR

Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language CHANDAN KUMAR
 
Searching in c language
Searching in c languageSearching in c language
Searching in c languageCHANDAN KUMAR
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programmingCHANDAN KUMAR
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programmingCHANDAN KUMAR
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statementCHANDAN KUMAR
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm ""A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "CHANDAN KUMAR
 

More from CHANDAN KUMAR (12)

Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language
 
Raid technology
Raid technologyRaid technology
Raid technology
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Searching in c language
Searching in c languageSearching in c language
Searching in c language
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
 
Linked List
Linked ListLinked List
Linked List
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programming
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm ""A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

Divide and Conquer Algorithm Guide

  • 1. Prepared By: Dr. Chandan Kumar Assistant Professor, Computer Science & Engineering Department Invertis University, Bareilly
  • 2. Introduction Algorithm Divide & Conquer Greedy Brute Force Dynamic Programming Backtracking Recursive Branch & Bound Randomized
  • 3. Divide and Conquer  It is an algorithm design paradigm which is based on multi branch recursion.  The divide-and-conquer paradigm is often used to find an optimal solution to a problem.  It is a technique to break a problem recursively into sub-problems of the same or related type.  Sub-programs have to be simple enough to be solved directly.  The solutions to these sub-problems are then combined to solve the original problem
  • 4. Divide and Conquer  D&C follow following three steps  Divide/Break- Break original problem into sub- problems  Conquer/Solve - Solve every individual sub-problem, recursively  Combine/Merge- Place the solutions to the sub- problems together to solve the entire problem
  • 5. Divide and Conquer  In short, D&C is a approach in which the entire problem (i.e. too large to comprehend or overcome at once) is divided into smaller pieces, the pieces are solved separately, and all the pieces are combined together.
  • 7. Implementation  Program to calculate pow(x,n) in C language #include<stdio.h> #include<conio.h> /* Function to calculate x raised to the power y */ int power(int x, unsigned int y) { if (y == 0) return 1; else if (y%2 == 0) return power(x, y/2)*power(x, y/2);
  • 8. Implementation else return x*power(x, y/2)*power(x, y/2); } /* Program to test function power */ int main() { int x = 2; unsigned int y = 3; printf("%d", power(x, y)); return 0; }
  • 9. Application  Following computer algorithms are based on divide and conquer programming approach  Bineary Search  Merge Sort  Quick Sort  Maximum and Minimum Problem  Tower of Hanoi  Strassen's Matrix multiplication  Karatsuba Algorithm
  • 10. Complexity  The complexity of the divide-and-conquer algorithm is calculated using the master theorem. T(n) = aT(n/b) + f(n), where n = size of input a = number of sub-problems in the recursion n/b = size of each sub-problem. All sub-problems are assumed to have the same size f(n) = cost of the work done outside the recursive call, which includes the cost of dividing the problem and cost of merging the solutions
  • 11. Advantages  The complexity for the multiplication of two matrices using the naive method is O(n3), whereas using the divide and conquer approach (ie. Strassen's matrix multiplication) is O(n2.8074).  This strategy also simplifies other issues such as the Tower of Hanoi.  Suitable for multiprocessing systems.  It does use memory caches effectively.