SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
BRUTE-FORCE-ALGORITHM
INTRODUCTION
The Maximum sub-array problem is the task of finding the contiguous sub-array
within a one dimensional array.
For Example:
Brute force algorithm is a step by step procedure for solving a problem so it is
consider as a straight forward approach usually based on the problem statement.
1 -3 2 -5 7 6 -1 -4 11 -23
0 1 2 3 4 5 6 7 8 9
PSEUDO CODE
Max-Sub-array-Brute-Force (A)
n = A.length
max-so-far = -∞
For l = 1 to n
sum = 0
for h = l to n
sum = sum + A[h]
if sum > max-so-far
max-so-far = sum
low = l
high = h
Return (low , high)
IMPLEMENTATION
3 -2 5 -1
0 1 2 3
FOR EXAMPLE
:
1.
3
SUM:
-2 5 -1
3 -2 -15
MAX_SO_FA
R
3 3 5 5
2.
3 -2 -2 5 5 -1
SUM: 1
MAX_SO_FA
R
5
3
5 5
4
Taking one at a
time :
Taking two at a
time :
3.
3 -2 -2 5
SUM: 6
MAX_SO_FA
R
6
2
6
Taking three at a
time :
IMPLEMENTATION
5 -1
3 -2
SUM: 5
MAX_SO_FA
R
6
5
4. Taking four at a time
:
-1
IMPLEMENTATION
3 -2 5 -1
0 1 2 3
Maximum Sub-Array
Max-Sub-array-Brute-Force (A)
n = A.length
max-so-far = -∞
For l = 1 to n
sum = 0
for h = l to n
sum = sum + A[h]
if sum > max-so-far
max-so-far = sum
low = l
high = h
Return (low , high)
O(n)
O(n)
Time
Time Complexity
Overall time complexity :
O(n2)
CONCLUSION
 Brute force is a straight forward approach to problem solving , It is applicable to very wide variety of
problem.
 Brute force algorithm is useful for solving small size instance of problem.
 A brute force algorithm can serve an important theoretical or educational purpose.
 A brute force algorithm is often easier to implement than a more sophisticated one and , because of this
simplicity, sometime it can be more efficient.
 Brute force algorithm is used when the simplicity of implementation is more important than speed.
 Brute force algorithm can be applied only to problems where input size is small , otherwise it will be
not efficient .

More Related Content

PDF
Formal Languages and Automata Theory Unit 1
PPTX
Binary search
PPTX
Bruteforce algorithm
PPTX
Analysis of algorithm
PPTX
Greedy method
PPTX
Context free grammar
PPT
Asymptotic analysis
PDF
Daa notes 1
Formal Languages and Automata Theory Unit 1
Binary search
Bruteforce algorithm
Analysis of algorithm
Greedy method
Context free grammar
Asymptotic analysis
Daa notes 1

What's hot (20)

PPT
Presentation on binary search, quick sort, merge sort and problems
PPTX
Asymptotic Notation
PPTX
Asymptotic Notations
PPTX
daa-unit-3-greedy method
PPTX
Asymptotic notations
PPTX
Synchronization hardware
PPT
Complexity of Algorithm
PPTX
Insertion Sorting
PPT
Graphs
PPTX
Quick sort
PDF
Algorithms Lecture 2: Analysis of Algorithms I
PPTX
Greedy Algorithm - Knapsack Problem
PPT
Divide and conquer
PPTX
Top down parsing
PPTX
Analysis and Design of Algorithms
PPTX
stack & queue
PPTX
8 queens problem using back tracking
PPTX
Cache coherence ppt
PPTX
Code Optimization
PPTX
Activity selection problem
Presentation on binary search, quick sort, merge sort and problems
Asymptotic Notation
Asymptotic Notations
daa-unit-3-greedy method
Asymptotic notations
Synchronization hardware
Complexity of Algorithm
Insertion Sorting
Graphs
Quick sort
Algorithms Lecture 2: Analysis of Algorithms I
Greedy Algorithm - Knapsack Problem
Divide and conquer
Top down parsing
Analysis and Design of Algorithms
stack & queue
8 queens problem using back tracking
Cache coherence ppt
Code Optimization
Activity selection problem
Ad

Similar to Brute force-algorithm (20)

PPTX
Design of Algorithms Using Brute Force Approach Advance Algo Anum Rehman.pptx
PDF
Daa chapter 2
PDF
whhhhhhhhhhhhhhhhhhhhhhhhhhhhheek 8 Cc.pdf
PPT
Perform brute force
 
PPT
BCA Chapter 5 The Greedy Method Notes.ppt
PPT
Design and Analysis of Algorithm Brute Force 1.ppt
PPT
Introduction to Algorithms
PDF
3 chapter2 algorithm_analysispart2
PDF
Maximum Subarray Sum in Python
PPTX
Maximum Sum Interval
PPTX
The Maximum Subarray Problem
DOCX
M269 Data Structures And Computability.docx
PDF
A* and Min-Max Searching Algorithms in AI , DSA.pdf
PPTX
Chapter 5.pptx
PPTX
TRAVELING SALESMAN PROBLEM, Divide and Conquer
PPTX
ch03-2018.02.02.pptx
PPTX
Rat_in_a_maze((Dynamic programming-tabulation))
PPTX
Brute force method
PPTX
Design & Analysis of Algorithms Techniques
PPTX
Applied Algorithms Introduction to Algorithms.pptx
Design of Algorithms Using Brute Force Approach Advance Algo Anum Rehman.pptx
Daa chapter 2
whhhhhhhhhhhhhhhhhhhhhhhhhhhhheek 8 Cc.pdf
Perform brute force
 
BCA Chapter 5 The Greedy Method Notes.ppt
Design and Analysis of Algorithm Brute Force 1.ppt
Introduction to Algorithms
3 chapter2 algorithm_analysispart2
Maximum Subarray Sum in Python
Maximum Sum Interval
The Maximum Subarray Problem
M269 Data Structures And Computability.docx
A* and Min-Max Searching Algorithms in AI , DSA.pdf
Chapter 5.pptx
TRAVELING SALESMAN PROBLEM, Divide and Conquer
ch03-2018.02.02.pptx
Rat_in_a_maze((Dynamic programming-tabulation))
Brute force method
Design & Analysis of Algorithms Techniques
Applied Algorithms Introduction to Algorithms.pptx
Ad

Recently uploaded (20)

PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Lesson notes of climatology university.
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Cell Types and Its function , kingdom of life
PPTX
Final Presentation General Medicine 03-08-2024.pptx
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
O5-L3 Freight Transport Ops (International) V1.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Lesson notes of climatology university.
A systematic review of self-coping strategies used by university students to ...
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
RMMM.pdf make it easy to upload and study
STATICS OF THE RIGID BODIES Hibbelers.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Yogi Goddess Pres Conference Studio Updates
Weekly quiz Compilation Jan -July 25.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Final Presentation General Medicine 03-08-2024.pptx
VCE English Exam - Section C Student Revision Booklet
Cell Types and Its function , kingdom of life
Final Presentation General Medicine 03-08-2024.pptx

Brute force-algorithm

  • 2. INTRODUCTION The Maximum sub-array problem is the task of finding the contiguous sub-array within a one dimensional array. For Example: Brute force algorithm is a step by step procedure for solving a problem so it is consider as a straight forward approach usually based on the problem statement. 1 -3 2 -5 7 6 -1 -4 11 -23 0 1 2 3 4 5 6 7 8 9
  • 3. PSEUDO CODE Max-Sub-array-Brute-Force (A) n = A.length max-so-far = -∞ For l = 1 to n sum = 0 for h = l to n sum = sum + A[h] if sum > max-so-far max-so-far = sum low = l high = h Return (low , high)
  • 4. IMPLEMENTATION 3 -2 5 -1 0 1 2 3 FOR EXAMPLE : 1. 3 SUM: -2 5 -1 3 -2 -15 MAX_SO_FA R 3 3 5 5 2. 3 -2 -2 5 5 -1 SUM: 1 MAX_SO_FA R 5 3 5 5 4 Taking one at a time : Taking two at a time :
  • 5. 3. 3 -2 -2 5 SUM: 6 MAX_SO_FA R 6 2 6 Taking three at a time : IMPLEMENTATION 5 -1 3 -2 SUM: 5 MAX_SO_FA R 6 5 4. Taking four at a time : -1
  • 6. IMPLEMENTATION 3 -2 5 -1 0 1 2 3 Maximum Sub-Array
  • 7. Max-Sub-array-Brute-Force (A) n = A.length max-so-far = -∞ For l = 1 to n sum = 0 for h = l to n sum = sum + A[h] if sum > max-so-far max-so-far = sum low = l high = h Return (low , high) O(n) O(n) Time Time Complexity Overall time complexity : O(n2)
  • 8. CONCLUSION  Brute force is a straight forward approach to problem solving , It is applicable to very wide variety of problem.  Brute force algorithm is useful for solving small size instance of problem.  A brute force algorithm can serve an important theoretical or educational purpose.  A brute force algorithm is often easier to implement than a more sophisticated one and , because of this simplicity, sometime it can be more efficient.  Brute force algorithm is used when the simplicity of implementation is more important than speed.  Brute force algorithm can be applied only to problems where input size is small , otherwise it will be not efficient .