Ajeng Savitri P, M.Kom
Analysis & Strategy
of Algorithm
Pertemuan 4
OBJECTIVE
 To learn the definition of brute force
 To learn the characteristic of brute force
 To learn how brute force can solve the problem
DEFINITION
“Brute force is a straight-forward approach to solving a problem,
usually directly based on the problem statement and definitions of the
concepts involved.”
“This algorithm solves problems very simply,
directly and in obvious way”
CHARACTERISTIC
 Brute force algorithms are generally not "smart" and not fast, becaus
e they require many steps in progress
 The word "force" indicates “power" rather than "brain“
 Sometimes called by naïve algorithm
 Suit for small problem because of its simplicity and easy to implemen
t
CHARACTERISTIC (cont.. )
 Brute-force algorithms are often used as comparative bases with faste
r algorithms
 Although not a fast method, almost every problem can be solved with
this algorithm
 It’s difficult to show problem that can not be solved by the brute force
method. In fact, there are problems that can only be solved by the brut
e force
EXAMPLE (1)
• Computing an (a > 0, n a non-negative integer)
an = a x a x … x a (n times) , if n > 0
= 1 , if n = 0
Algorithm : multiplying 1 by a as much as n times
Complexity : O(n)
EXAMPLE (2)
• Computing n!
n! = 1 × 2 × 3 × … × n , jika n > 0
= 1 , jika n = 0
Algorithm : multiplying n number (1,2,3. . .,n) together
Complexity : O(n)
EXAMPLE (3)
• Multiplying two matrices, A and B
For example :
C = A x B and matrix elements are expressed as cij, aij, and bij
Algorithm : calculate each element, multiplication one by one, by
multiplying two vectors of length n.


n
k
kjiknjinjijiij babababac
1
2211 
SORTING PROBLEM
 What is the most straightforward approach to solving a sorting
problem ??
Bubble sort and selection sort
These algorithm show the use of brute force obviously
CONTOH PENDEKATAN BRUTE FORCE
Jika diberikan sekumpulan data angka sebanyak 30 buah (misal 8, 4, 67, 20 48, 0, dst),
kemudian diminta untuk mengurutkan secara ascending, bagaimana pendekatan Brute Fo
rce melakukannya?
Pendekatan Brute Force mengusulkan algoritma yang membandingkan isi list data angka p
ertama dengan kedua, yang lebih kecil akan diletakkan pada susunan pertama. Berikutnya d
ata kedua dibandingkan dengan data ketiga, yang lebih kecil diletakkan disusunan kedua, d
st. Dibandingkan satu persatu, kemudian ditukar, diualng sampai urutan sesuai.
Bubble Sort adalah algoritma tersebut.
BUBBLE SORT
• Compare adjacent elements of the list and exchange them if they are
out of order
• Do it repeatedly, we end up “bubbling up” the largest element to the
last position on the list
Example : https://www.youtube.com/watch?v=Vpvgxm4hlGM
SELECTION SORT
• Scan the array to find its smallest element and swap it with the first
element.
• Then, starting with the second element, scan the elements to the righ
t of it to find the smallest among them and swap it with the second
elements.
• Generally, on pass i (0  i  n-2), find the smallest element in A[
i..n-1] and swap it with A[i]:
Example : https://www.youtube.com/watch?v=R_f3PJtRqUQ
SEARCHING PROBLEM
 What is the most straightforward approach to solving a sorting
problem ??
CONTOH PENDEKATAN BRUTE FORCE
Jika diberikan sekumpulan data nama mahasiswa sebanyak 1000 buah (missal Udin, Marn
i, Kirana, dll), kemudian diminta untuk mencari nama “Budi”, bagaimana pendekatan Brute
Force melakukannya?
Pendekatan Brute Force mengusulkan algoritma yang mencari kata “Budi” dengan
membandingkan isi list nama mulai dari data pertama, kedua, ketiga dan seterusnya. Di
bandingkan satu persatu, sampai dengan ditemukan kata yang dicari. Pencarian berurutan a
tau Sequential search adalah algoritma tersebut.
Apakah ada pendekatan pencarian lain selain dicari satu persatu? Binary Search
STRING MATCHING
• Pattern: a string of (m) characters to search for
• Text: a long string of (n) characters to search in
• Brute force algorithm:
1. Align pattern at beginning of text
2. Moving from left to right, compare each character of pattern to the correspondin
g character in text until
a. All characters are found to match (successful search); or
b. A mismatch is detected
3. While pattern is not found and the text is not yet exhausted, realign pattern one
position to the right and repeat step 2.
• Example : https://www.youtube.com/watch?v=i2XBayzzkao
STRING MATCHING (example)
Pattern: GATTTCG (length = m = 7)
Text:
GATTTCG
GATTTCATCAGATTTCGATACAGAT
GATTTCGGATTTCGGATTTCGGATTTCGGATTTCGGATTTCGGATTTCGGATTTCGGATTTCGGATTTCG
Text length = n = 25
Best Case: ?
Worst Case: ?
BRUTE FORCE - STRING MATCHING
• Pattern length = m;
• Text length = n;
• Best Case:
GATTTCATCAGATTTCGATACAGAT
GATTTCA
O(m) The pattern is found right away, but you still have to do
m comparison to verify that is was found.
TRY BY YOUR SELF
• Solve this string matching problem
• Pattern : 001011
• Text : 10010101101001100101111010
• How many step to solve this problem ?
1. Pattern length = m;
2. Text length = n;
3. Average Case:
4. Observation: If the number of symbols is relatively large (26 for e
xample) then 
Most shifts will happen after very few comparisons.
5. In fact, there are very few pattern-text combinations that will cau
se (m) comparisons for each shift.
6. Note: There are always (n) shifts if the pattern is not found
BRUTE FORCE - STRING MATCHING
KEKUATAN
 Metode brute force dapat digunakan untuk memecahkan hampir
sebagian besar masalah (wide applicability).
 Metode brute force sederhana dan mudah dimengerti.
 Metode brute force menghasilkan algoritma yang layak untuk
beberapa masalah penting seperti pencarian, pengurutan, pencocoka
n string, perkalian matriks.
 Metode brute force menghasilkan algoritma baku (standard) untuk
tugas-tugas komputasi seperti penjumlahan/perkalian n buah bilanga
n, menentukan elemen minimum atau maksimum di dalam tabel (list)
.
KELEMAHAN
 Metode brute force jarang menghasilkan algoritma yang mangkus.
 Beberapa algoritma brute force lambat sehingga tidak dapat diterima.
 Tidak sekonstruktif/sekreatif teknik pemecahan masalah lainnya.
 Ken Thompson (salah seorang penemu Unix) mengatakan: “When in
doubt, use brute force”, faktanya kernel Unix yang asli lebih menyukai
algoritma yang sederhana dan kuat (robust) daripada algoritma yang
cerdas tapi rapuh.
REFFERENCE
 Munir, Rinaldi. Diktat Kuliah “Kompleksitas Algoritma”, Departemen T
eknik Informatika ITB
 Levitin, Anany. 2012. Introduction to the Design and Analysis of A
lgorithms, 3rd Edition.Addison Wesley
Terima Kasih
ajeng.savitri@teknokrat.ac.id
https://teknokrat.ac.id/en/
https://spada.teknokrat.ac.id/

More Related Content

PPTX
Boyer moore algorithm
PPT
Boyre Moore Algorithm | Computer Science
PPTX
Brute force technic
PPTX
Boyer more algorithm
PDF
String matching, naive,
PPTX
Brute force method
PPTX
Naive string matching
PPT
String matching algorithms
Boyer moore algorithm
Boyre Moore Algorithm | Computer Science
Brute force technic
Boyer more algorithm
String matching, naive,
Brute force method
Naive string matching
String matching algorithms

What's hot (12)

PPTX
String Match | Computer Science
PPT
Naive String Matching Algorithm | Computer Science
PPT
Pattern matching
PDF
Pattern matching programs
PPTX
Boyer more algorithm
PPTX
String matching algorithms-pattern matching.
PDF
Introduction to recommender systems
PPT
Lecture 1 maximum likelihood
PDF
Sufficiency
PDF
Advances in composite integer factorization
PDF
The transportation problem in an intuitionistic fuzzy environment
PPTX
Learning deep structured semantic models for web search
String Match | Computer Science
Naive String Matching Algorithm | Computer Science
Pattern matching
Pattern matching programs
Boyer more algorithm
String matching algorithms-pattern matching.
Introduction to recommender systems
Lecture 1 maximum likelihood
Sufficiency
Advances in composite integer factorization
The transportation problem in an intuitionistic fuzzy environment
Learning deep structured semantic models for web search
Ad

Similar to Brute Force (20)

PPT
04 brute force
PPT
Design and Analysis of Algorithm Brute Force 1.ppt
PPTX
Bruteforce algorithm
PPT
Perform brute force
 
PPT
BCA Chapter 5 The Greedy Method Notes.ppt
PPTX
ch03-2018.02.02.pptx
PPTX
Design of Algorithms Using Brute Force Approach Advance Algo Anum Rehman.pptx
PPTX
Unit 2 algorithm
PPT
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PDF
whhhhhhhhhhhhhhhhhhhhhhhhhhhhheek 8 Cc.pdf
PPTX
Arif hussain algo prestention
PDF
module6_stringmatchingalgorithm_2022.pdf
PPTX
Chapter 1 - Algorithm Analysis & Design 2021
PPT
Chpt9 patternmatching
PPTX
Design and Analysis of Algorithm for II year Computer science and Engineering...
PPTX
ALGORITHM.pptx
PPTX
DAA 1 ppt.pptx
04 brute force
Design and Analysis of Algorithm Brute Force 1.ppt
Bruteforce algorithm
Perform brute force
 
BCA Chapter 5 The Greedy Method Notes.ppt
ch03-2018.02.02.pptx
Design of Algorithms Using Brute Force Approach Advance Algo Anum Rehman.pptx
Unit 2 algorithm
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
whhhhhhhhhhhhhhhhhhhhhhhhhhhhheek 8 Cc.pdf
Arif hussain algo prestention
module6_stringmatchingalgorithm_2022.pdf
Chapter 1 - Algorithm Analysis & Design 2021
Chpt9 patternmatching
Design and Analysis of Algorithm for II year Computer science and Engineering...
ALGORITHM.pptx
DAA 1 ppt.pptx
Ad

More from Ajeng Savitri (20)

PPTX
Software Testing Documentation
PPTX
Software Productivity Measurement
PPTX
Debugging (Part 2)
PPTX
Debugging
PPTX
Software Testing Strategy (Part 2)
PPTX
Software Testing Strategy
PPTX
Object Oriented Testing
PPTX
Testing Technique (Part 2)
PPTX
Testing Technique
PPTX
Testing Plan
PPTX
Methodology Selection Strategy
PPTX
Software Testing - Software Quality (Part 2)
PPTX
Software Testing - Software Quality
PPTX
Computer Evolution and Performance
PPTX
Software Testing - Introduction
PPTX
Sequence Diagram
PPTX
Activity Diagram
PPTX
Use Case Diagram
PPTX
Requirement Gathering
PPTX
Business Value
Software Testing Documentation
Software Productivity Measurement
Debugging (Part 2)
Debugging
Software Testing Strategy (Part 2)
Software Testing Strategy
Object Oriented Testing
Testing Technique (Part 2)
Testing Technique
Testing Plan
Methodology Selection Strategy
Software Testing - Software Quality (Part 2)
Software Testing - Software Quality
Computer Evolution and Performance
Software Testing - Introduction
Sequence Diagram
Activity Diagram
Use Case Diagram
Requirement Gathering
Business Value

Recently uploaded (20)

PDF
CapCut PRO for PC Crack New Download (Fully Activated 2025)
PDF
Sun and Bloombase Spitfire StoreSafe End-to-end Storage Security Solution
PPTX
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
PDF
Crypto Loss And Recovery Guide By Expert Recovery Agency.
PPTX
Chapter 1 - Transaction Processing and Mgt.pptx
PDF
Mobile App Backend Development with WordPress REST API: The Complete eBook
PDF
Lumion Pro Crack New latest version Download 2025
PPTX
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
PDF
Internet Download Manager IDM Crack powerful download accelerator New Version...
PPTX
DevOpsDays Halifax 2025 - Building 10x Organizations Using Modern Productivit...
PPTX
Chapter_05_System Modeling for software engineering
PPTX
Folder Lock 10.1.9 Crack With Serial Key
PDF
Practical Indispensable Project Management Tips for Delivering Successful Exp...
PDF
MAGIX Sound Forge Pro CrackSerial Key Keygen
PDF
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
PPTX
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
PPTX
Odoo ERP for Injection Molding Industry – Optimize Production & Reduce Scrap
PPTX
ROI from Efficient Content & Campaign Management in the Digital Media Industry
PPTX
ROI Analysis for Newspaper Industry with Odoo ERP
PDF
Top 10 Project Management Software for Small Teams in 2025.pdf
CapCut PRO for PC Crack New Download (Fully Activated 2025)
Sun and Bloombase Spitfire StoreSafe End-to-end Storage Security Solution
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
Crypto Loss And Recovery Guide By Expert Recovery Agency.
Chapter 1 - Transaction Processing and Mgt.pptx
Mobile App Backend Development with WordPress REST API: The Complete eBook
Lumion Pro Crack New latest version Download 2025
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
Internet Download Manager IDM Crack powerful download accelerator New Version...
DevOpsDays Halifax 2025 - Building 10x Organizations Using Modern Productivit...
Chapter_05_System Modeling for software engineering
Folder Lock 10.1.9 Crack With Serial Key
Practical Indispensable Project Management Tips for Delivering Successful Exp...
MAGIX Sound Forge Pro CrackSerial Key Keygen
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
Odoo ERP for Injection Molding Industry – Optimize Production & Reduce Scrap
ROI from Efficient Content & Campaign Management in the Digital Media Industry
ROI Analysis for Newspaper Industry with Odoo ERP
Top 10 Project Management Software for Small Teams in 2025.pdf

Brute Force

  • 1. Ajeng Savitri P, M.Kom Analysis & Strategy of Algorithm Pertemuan 4
  • 2. OBJECTIVE  To learn the definition of brute force  To learn the characteristic of brute force  To learn how brute force can solve the problem
  • 3. DEFINITION “Brute force is a straight-forward approach to solving a problem, usually directly based on the problem statement and definitions of the concepts involved.” “This algorithm solves problems very simply, directly and in obvious way”
  • 4. CHARACTERISTIC  Brute force algorithms are generally not "smart" and not fast, becaus e they require many steps in progress  The word "force" indicates “power" rather than "brain“  Sometimes called by naïve algorithm  Suit for small problem because of its simplicity and easy to implemen t
  • 5. CHARACTERISTIC (cont.. )  Brute-force algorithms are often used as comparative bases with faste r algorithms  Although not a fast method, almost every problem can be solved with this algorithm  It’s difficult to show problem that can not be solved by the brute force method. In fact, there are problems that can only be solved by the brut e force
  • 6. EXAMPLE (1) • Computing an (a > 0, n a non-negative integer) an = a x a x … x a (n times) , if n > 0 = 1 , if n = 0 Algorithm : multiplying 1 by a as much as n times Complexity : O(n)
  • 7. EXAMPLE (2) • Computing n! n! = 1 × 2 × 3 × … × n , jika n > 0 = 1 , jika n = 0 Algorithm : multiplying n number (1,2,3. . .,n) together Complexity : O(n)
  • 8. EXAMPLE (3) • Multiplying two matrices, A and B For example : C = A x B and matrix elements are expressed as cij, aij, and bij Algorithm : calculate each element, multiplication one by one, by multiplying two vectors of length n.   n k kjiknjinjijiij babababac 1 2211 
  • 9. SORTING PROBLEM  What is the most straightforward approach to solving a sorting problem ?? Bubble sort and selection sort These algorithm show the use of brute force obviously
  • 10. CONTOH PENDEKATAN BRUTE FORCE Jika diberikan sekumpulan data angka sebanyak 30 buah (misal 8, 4, 67, 20 48, 0, dst), kemudian diminta untuk mengurutkan secara ascending, bagaimana pendekatan Brute Fo rce melakukannya? Pendekatan Brute Force mengusulkan algoritma yang membandingkan isi list data angka p ertama dengan kedua, yang lebih kecil akan diletakkan pada susunan pertama. Berikutnya d ata kedua dibandingkan dengan data ketiga, yang lebih kecil diletakkan disusunan kedua, d st. Dibandingkan satu persatu, kemudian ditukar, diualng sampai urutan sesuai. Bubble Sort adalah algoritma tersebut.
  • 11. BUBBLE SORT • Compare adjacent elements of the list and exchange them if they are out of order • Do it repeatedly, we end up “bubbling up” the largest element to the last position on the list Example : https://www.youtube.com/watch?v=Vpvgxm4hlGM
  • 12. SELECTION SORT • Scan the array to find its smallest element and swap it with the first element. • Then, starting with the second element, scan the elements to the righ t of it to find the smallest among them and swap it with the second elements. • Generally, on pass i (0  i  n-2), find the smallest element in A[ i..n-1] and swap it with A[i]: Example : https://www.youtube.com/watch?v=R_f3PJtRqUQ
  • 13. SEARCHING PROBLEM  What is the most straightforward approach to solving a sorting problem ??
  • 14. CONTOH PENDEKATAN BRUTE FORCE Jika diberikan sekumpulan data nama mahasiswa sebanyak 1000 buah (missal Udin, Marn i, Kirana, dll), kemudian diminta untuk mencari nama “Budi”, bagaimana pendekatan Brute Force melakukannya? Pendekatan Brute Force mengusulkan algoritma yang mencari kata “Budi” dengan membandingkan isi list nama mulai dari data pertama, kedua, ketiga dan seterusnya. Di bandingkan satu persatu, sampai dengan ditemukan kata yang dicari. Pencarian berurutan a tau Sequential search adalah algoritma tersebut. Apakah ada pendekatan pencarian lain selain dicari satu persatu? Binary Search
  • 15. STRING MATCHING • Pattern: a string of (m) characters to search for • Text: a long string of (n) characters to search in • Brute force algorithm: 1. Align pattern at beginning of text 2. Moving from left to right, compare each character of pattern to the correspondin g character in text until a. All characters are found to match (successful search); or b. A mismatch is detected 3. While pattern is not found and the text is not yet exhausted, realign pattern one position to the right and repeat step 2. • Example : https://www.youtube.com/watch?v=i2XBayzzkao
  • 16. STRING MATCHING (example) Pattern: GATTTCG (length = m = 7) Text: GATTTCG GATTTCATCAGATTTCGATACAGAT GATTTCGGATTTCGGATTTCGGATTTCGGATTTCGGATTTCGGATTTCGGATTTCGGATTTCGGATTTCG Text length = n = 25 Best Case: ? Worst Case: ?
  • 17. BRUTE FORCE - STRING MATCHING • Pattern length = m; • Text length = n; • Best Case: GATTTCATCAGATTTCGATACAGAT GATTTCA O(m) The pattern is found right away, but you still have to do m comparison to verify that is was found.
  • 18. TRY BY YOUR SELF • Solve this string matching problem • Pattern : 001011 • Text : 10010101101001100101111010 • How many step to solve this problem ?
  • 19. 1. Pattern length = m; 2. Text length = n; 3. Average Case: 4. Observation: If the number of symbols is relatively large (26 for e xample) then  Most shifts will happen after very few comparisons. 5. In fact, there are very few pattern-text combinations that will cau se (m) comparisons for each shift. 6. Note: There are always (n) shifts if the pattern is not found BRUTE FORCE - STRING MATCHING
  • 20. KEKUATAN  Metode brute force dapat digunakan untuk memecahkan hampir sebagian besar masalah (wide applicability).  Metode brute force sederhana dan mudah dimengerti.  Metode brute force menghasilkan algoritma yang layak untuk beberapa masalah penting seperti pencarian, pengurutan, pencocoka n string, perkalian matriks.  Metode brute force menghasilkan algoritma baku (standard) untuk tugas-tugas komputasi seperti penjumlahan/perkalian n buah bilanga n, menentukan elemen minimum atau maksimum di dalam tabel (list) .
  • 21. KELEMAHAN  Metode brute force jarang menghasilkan algoritma yang mangkus.  Beberapa algoritma brute force lambat sehingga tidak dapat diterima.  Tidak sekonstruktif/sekreatif teknik pemecahan masalah lainnya.  Ken Thompson (salah seorang penemu Unix) mengatakan: “When in doubt, use brute force”, faktanya kernel Unix yang asli lebih menyukai algoritma yang sederhana dan kuat (robust) daripada algoritma yang cerdas tapi rapuh.
  • 22. REFFERENCE  Munir, Rinaldi. Diktat Kuliah “Kompleksitas Algoritma”, Departemen T eknik Informatika ITB  Levitin, Anany. 2012. Introduction to the Design and Analysis of A lgorithms, 3rd Edition.Addison Wesley

Editor's Notes

  • #4: Brute force adalah sebuah pendekatan yang langsung (straightforward) untuk memecahkan suatu masalah, biasanya didasarkan pada pernyataan masalah (problem statement) dan definisi konsep yang dilibatkan. Algoritma ini menyelesaikan masalah dengan sangat sederhana, langsung dan dengan cara yang jelas
  • #5: Algoritma brute force umumnya tidak“cerdas” dan tidak cepat, karena ia membutuhkan jumlah langkah yang besar dalam penyelesaiannya. Kata“force” mengindikasikan“tenaga” ketimbang“otak” Kadang-kadang algoritma brute force disebut juga algoritma naif (naïve algorithm). Algoritma brute force lebih cocok untuk masalah yang berukuran kecil karena kesederhanaan dan kemudahan dalam implementasinya
  • #6: Algoritma brute force sering digunakan sebagai basis pembanding dengan algoritma yang lebih cepat. Meskipun bukan metode yang cepat, hampir semua masalah dapat diselesaikan dengan algoritma brute force Sukar menunjukkan masalah yang tidak dapat diselesaikan dengan metode brute force. Bahkan, ada masalah yang hanya dapat diselesaikan dengan metode brute force