SlideShare a Scribd company logo
2
Most read
4
Most read
6
Most read
Finding Min,Max element from array
Using Divide & Conquer
By: S. A. Jaipurkar
Asst. Prof.
MIT, Aurangabad. Maharashtra.
Finding Min,Max element from array
Using Divide & Conquer
Consider a simple problem that can be solved by divide
and conquer technique.
The Max-Min Problem in algorithm analysis:
finding the maximum and minimum value in an array.
Solution : 2 methods :
1. naive method
2. divide and conquer approach
Naïve Method
It is a basic method to solve any problem.
In this method, the maximum and minimum
number can be found separately.
To find the maximum and minimum numbers, the
following straightforward algorithm can be used.
Analysis : The number of comparison in Naive
method is 2n - 2.
The number of comparisons can be reduced
using the divide and conquer approach.
Find Max & Min element
Algorithm: Max-Min-Element (numbers[])
max := number[1]
min := number[1]
for i = 2 to n do
if number[i] > max then
max := number[i]
if number[i] < min then
min := number[i]
return (max, min)
Divide and Conquer Approach

In this approach, the array is divided into two
halves.

Then using recursive approach maximum and
minimum numbers in each halves are found.

Later, return the maximum of two maxima of
each half and the minimum of two minima of
each half.
Function MAXMIN (A, low, high)
if (high − low + 1 = 2) then
if (A[low] < A[high]) then
max = A[high]; min = A[low]
return((max, min))
else
max = A[low]; min = A[high]
return((max, min))
end if
else
mid = low+high/2
(max_l , min_l ) = MAXMIN(A, low, mid)
(max_r , min_r ) =MAXMIN(A, mid + 1, high)
end if
Set max to the larger of max_l and max_r ;
set min to the smaller of min_l and min_r
return((max, min)).
Function MAXMIN (A, low, high)
if (high − low + 1 = 2) then
if (A[low] < A[high]) then
max = A[high]; min = A[low]
return((max, min))
else
max = A[low]; min = A[high]
return((max, min))
end if
else
mid = low+high/2
(max_l , min_l ) = MAXMIN(A, low, mid)
(max_r , min_r ) =MAXMIN(A, mid + 1, high)
end if
Set max to the larger of max_l and max_r ;
set min to the smaller of min_l and min_r
return((max, min)).
Ad

Recommended

Unit 3 daa
Unit 3 daa
Nv Thejaswini
 
Divide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
Lower bound
Lower bound
Rajendran
 
Shortest path algorithm
Shortest path algorithm
Subrata Kumer Paul
 
0/1 knapsack
0/1 knapsack
Amin Omi
 
Unit 3 graph chapter6
Unit 3 graph chapter6
DrkhanchanaR
 
CLOSEST PAIR (Final)
CLOSEST PAIR (Final)
Aruneel Das
 
Data Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Divide and conquer
Divide and conquer
Dr Shashikant Athawale
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventions
saranyatdr
 
Asymptotic notations
Asymptotic notations
Nikhil Sharma
 
Np cooks theorem
Np cooks theorem
Narayana Galla
 
Quick sort
Quick sort
Afaq Mansoor Khan
 
Lecture 14 run time environment
Lecture 14 run time environment
Iffat Anjum
 
Graph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Stressen's matrix multiplication
Stressen's matrix multiplication
Kumar
 
Forms of learning in ai
Forms of learning in ai
Robert Antony
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Divide and Conquer
Divide and Conquer
Melaku Bayih Demessie
 
Binary Search
Binary Search
kunj desai
 
Sum of subset problem.pptx
Sum of subset problem.pptx
V.V.Vanniaperumal College for Women
 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
vikas dhakane
 
Divide and Conquer
Divide and Conquer
Dr Shashikant Athawale
 
Binary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
search strategies in artificial intelligence
search strategies in artificial intelligence
Hanif Ullah (Gold Medalist)
 
Red black tree
Red black tree
Rajendran
 
Report 01(MaxMin)
Report 01(MaxMin)
Md. Bashartullah (Rabby)
 
median and order statistics
median and order statistics
Shashank Singh
 

More Related Content

What's hot (20)

Divide and conquer
Divide and conquer
Dr Shashikant Athawale
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventions
saranyatdr
 
Asymptotic notations
Asymptotic notations
Nikhil Sharma
 
Np cooks theorem
Np cooks theorem
Narayana Galla
 
Quick sort
Quick sort
Afaq Mansoor Khan
 
Lecture 14 run time environment
Lecture 14 run time environment
Iffat Anjum
 
Graph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Stressen's matrix multiplication
Stressen's matrix multiplication
Kumar
 
Forms of learning in ai
Forms of learning in ai
Robert Antony
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Divide and Conquer
Divide and Conquer
Melaku Bayih Demessie
 
Binary Search
Binary Search
kunj desai
 
Sum of subset problem.pptx
Sum of subset problem.pptx
V.V.Vanniaperumal College for Women
 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
vikas dhakane
 
Divide and Conquer
Divide and Conquer
Dr Shashikant Athawale
 
Binary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
search strategies in artificial intelligence
search strategies in artificial intelligence
Hanif Ullah (Gold Medalist)
 
Red black tree
Red black tree
Rajendran
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventions
saranyatdr
 
Asymptotic notations
Asymptotic notations
Nikhil Sharma
 
Lecture 14 run time environment
Lecture 14 run time environment
Iffat Anjum
 
Stressen's matrix multiplication
Stressen's matrix multiplication
Kumar
 
Forms of learning in ai
Forms of learning in ai
Robert Antony
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
vikas dhakane
 
Binary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Red black tree
Red black tree
Rajendran
 

Similar to finding Min and max element from given array using divide & conquer (20)

Report 01(MaxMin)
Report 01(MaxMin)
Md. Bashartullah (Rabby)
 
median and order statistics
median and order statistics
Shashank Singh
 
Divide and conquer
Divide and conquer
ramya marichamy
 
Lec34
Lec34
Nikhil Chilwant
 
algorithm Unit 2
algorithm Unit 2
Monika Choudhery
 
Unit 2 in daa
Unit 2 in daa
Nv Thejaswini
 
Minimax Algorithm
Minimax Algorithm
sulaiman_karim
 
Project management
Project management
Avay Minni
 
Algorithm in computer science
Algorithm in computer science
Riazul Islam
 
270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docx
270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docx
eugeniadean34240
 
Lecture 8 dynamic programming
Lecture 8 dynamic programming
Oye Tu
 
Matlab tutorial 2
Matlab tutorial 2
Norhan Abdalla
 
Operations Research - The Big M Method
Operations Research - The Big M Method
Hisham Al Kurdi, EAVA, DMC-D-4K, HCCA-P, HCAA-D
 
9 Multi criteria Operation Decision Making - Nov 16 2020. pptx (ver2).pptx
9 Multi criteria Operation Decision Making - Nov 16 2020. pptx (ver2).pptx
dnbtraniemyu
 
Min and max search
Min and max search
Kumar
 
Dynamic_methods_Greedy_algorithms_11.ppt
Dynamic_methods_Greedy_algorithms_11.ppt
Gautam873893
 
Gauss Elimination (With Partial Pivot)
Gauss Elimination (With Partial Pivot)
Saloni Singhal
 
Lop1
Lop1
devendragiitk
 
Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)
asghar123456
 
14-dynamic-programming-work-methods.pptx
14-dynamic-programming-work-methods.pptx
r6s0069
 
median and order statistics
median and order statistics
Shashank Singh
 
Project management
Project management
Avay Minni
 
Algorithm in computer science
Algorithm in computer science
Riazul Islam
 
270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docx
270-102-divide-and-conquer_handout.pdfCS 270Algorithm.docx
eugeniadean34240
 
Lecture 8 dynamic programming
Lecture 8 dynamic programming
Oye Tu
 
9 Multi criteria Operation Decision Making - Nov 16 2020. pptx (ver2).pptx
9 Multi criteria Operation Decision Making - Nov 16 2020. pptx (ver2).pptx
dnbtraniemyu
 
Min and max search
Min and max search
Kumar
 
Dynamic_methods_Greedy_algorithms_11.ppt
Dynamic_methods_Greedy_algorithms_11.ppt
Gautam873893
 
Gauss Elimination (With Partial Pivot)
Gauss Elimination (With Partial Pivot)
Saloni Singhal
 
Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)
asghar123456
 
14-dynamic-programming-work-methods.pptx
14-dynamic-programming-work-methods.pptx
r6s0069
 
Ad

Recently uploaded (20)

Fundamentals of Digital Design_Class_12th April.pptx
Fundamentals of Digital Design_Class_12th April.pptx
drdebarshi1993
 
Solar thermal – Flat plate and concentrating collectors .pptx
Solar thermal – Flat plate and concentrating collectors .pptx
jdaniabraham1
 
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
resming1
 
Cadastral Maps
Cadastral Maps
Google
 
Complete guidance book of Asp.Net Web API
Complete guidance book of Asp.Net Web API
Shabista Imam
 
Stay Safe Women Security Android App Project Report.pdf
Stay Safe Women Security Android App Project Report.pdf
Kamal Acharya
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
Mechanical Vibration_MIC 202_iit roorkee.pdf
Mechanical Vibration_MIC 202_iit roorkee.pdf
isahiliitr
 
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...
João Esperancinha
 
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
resming1
 
How to Un-Obsolete Your Legacy Keypad Design
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
KhadijaKhadijaAouadi
 
machine learning is a advance technology
machine learning is a advance technology
ynancy893
 
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
Shabista Imam
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
nnnnnnnnnnnn7777777777777777777777777777777.pptx
nnnnnnnnnnnn7777777777777777777777777777777.pptx
gayathri venkataramani
 
Proposal for folders structure division in projects.pdf
Proposal for folders structure division in projects.pdf
Mohamed Ahmed
 
(Continuous Integration and Continuous Deployment/Delivery) is a fundamental ...
(Continuous Integration and Continuous Deployment/Delivery) is a fundamental ...
ketan09101
 
Fundamentals of Digital Design_Class_12th April.pptx
Fundamentals of Digital Design_Class_12th April.pptx
drdebarshi1993
 
Solar thermal – Flat plate and concentrating collectors .pptx
Solar thermal – Flat plate and concentrating collectors .pptx
jdaniabraham1
 
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
resming1
 
Cadastral Maps
Cadastral Maps
Google
 
Complete guidance book of Asp.Net Web API
Complete guidance book of Asp.Net Web API
Shabista Imam
 
Stay Safe Women Security Android App Project Report.pdf
Stay Safe Women Security Android App Project Report.pdf
Kamal Acharya
 
Industry 4.o the fourth revolutionWeek-2.pptx
Industry 4.o the fourth revolutionWeek-2.pptx
KNaveenKumarECE
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
Mechanical Vibration_MIC 202_iit roorkee.pdf
Mechanical Vibration_MIC 202_iit roorkee.pdf
isahiliitr
 
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...
João Esperancinha
 
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
Deep Learning for Image Processing on 16 June 2025 MITS.pptx
resming1
 
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
IPL_Logic_Flow.pdf Mainframe IPLMainframe IPL
KhadijaKhadijaAouadi
 
machine learning is a advance technology
machine learning is a advance technology
ynancy893
 
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
FUNDAMENTALS OF COMPUTER ORGANIZATION AND ARCHITECTURE
Shabista Imam
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
nnnnnnnnnnnn7777777777777777777777777777777.pptx
nnnnnnnnnnnn7777777777777777777777777777777.pptx
gayathri venkataramani
 
Proposal for folders structure division in projects.pdf
Proposal for folders structure division in projects.pdf
Mohamed Ahmed
 
(Continuous Integration and Continuous Deployment/Delivery) is a fundamental ...
(Continuous Integration and Continuous Deployment/Delivery) is a fundamental ...
ketan09101
 
Ad

finding Min and max element from given array using divide & conquer

  • 1. Finding Min,Max element from array Using Divide & Conquer By: S. A. Jaipurkar Asst. Prof. MIT, Aurangabad. Maharashtra.
  • 2. Finding Min,Max element from array Using Divide & Conquer Consider a simple problem that can be solved by divide and conquer technique. The Max-Min Problem in algorithm analysis: finding the maximum and minimum value in an array. Solution : 2 methods : 1. naive method 2. divide and conquer approach
  • 3. Naïve Method It is a basic method to solve any problem. In this method, the maximum and minimum number can be found separately. To find the maximum and minimum numbers, the following straightforward algorithm can be used. Analysis : The number of comparison in Naive method is 2n - 2. The number of comparisons can be reduced using the divide and conquer approach.
  • 4. Find Max & Min element Algorithm: Max-Min-Element (numbers[]) max := number[1] min := number[1] for i = 2 to n do if number[i] > max then max := number[i] if number[i] < min then min := number[i] return (max, min)
  • 5. Divide and Conquer Approach  In this approach, the array is divided into two halves.  Then using recursive approach maximum and minimum numbers in each halves are found.  Later, return the maximum of two maxima of each half and the minimum of two minima of each half.
  • 6. Function MAXMIN (A, low, high) if (high − low + 1 = 2) then if (A[low] < A[high]) then max = A[high]; min = A[low] return((max, min)) else max = A[low]; min = A[high] return((max, min)) end if else mid = low+high/2 (max_l , min_l ) = MAXMIN(A, low, mid) (max_r , min_r ) =MAXMIN(A, mid + 1, high) end if Set max to the larger of max_l and max_r ; set min to the smaller of min_l and min_r return((max, min)).
  • 7. Function MAXMIN (A, low, high) if (high − low + 1 = 2) then if (A[low] < A[high]) then max = A[high]; min = A[low] return((max, min)) else max = A[low]; min = A[high] return((max, min)) end if else mid = low+high/2 (max_l , min_l ) = MAXMIN(A, low, mid) (max_r , min_r ) =MAXMIN(A, mid + 1, high) end if Set max to the larger of max_l and max_r ; set min to the smaller of min_l and min_r return((max, min)).