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

What's hot

Naive String Matching Algorithm | Computer Science
Naive String Matching Algorithm | Computer ScienceNaive String Matching Algorithm | Computer Science
Naive String Matching Algorithm | Computer ScienceTransweb Global Inc
 
Pattern matching
Pattern matchingPattern matching
Pattern matchingshravs_188
 
Pattern matching programs
Pattern matching programsPattern matching programs
Pattern matching programsakruthi k
 
String matching algorithms-pattern matching.
String matching algorithms-pattern matching.String matching algorithms-pattern matching.
String matching algorithms-pattern matching.Swapan Shakhari
 
Introduction to recommender systems
Introduction to recommender systemsIntroduction to recommender systems
Introduction to recommender systemsArnaud de Myttenaere
 
Lecture 1 maximum likelihood
Lecture 1 maximum likelihoodLecture 1 maximum likelihood
Lecture 1 maximum likelihoodAnant Dashpute
 
Advances in composite integer factorization
Advances in composite integer factorizationAdvances in composite integer factorization
Advances in composite integer factorizationAlexander Decker
 
The transportation problem in an intuitionistic fuzzy environment
The transportation problem in an intuitionistic fuzzy environmentThe transportation problem in an intuitionistic fuzzy environment
The transportation problem in an intuitionistic fuzzy environmentNavodaya Institute of Technology
 
Learning deep structured semantic models for web search
Learning deep structured semantic models for web searchLearning deep structured semantic models for web search
Learning deep structured semantic models for web searchhyunsung lee
 

What's hot (12)

String Match | Computer Science
String Match | Computer ScienceString Match | Computer Science
String Match | Computer Science
 
Naive String Matching Algorithm | Computer Science
Naive String Matching Algorithm | Computer ScienceNaive String Matching Algorithm | Computer Science
Naive String Matching Algorithm | Computer Science
 
Pattern matching
Pattern matchingPattern matching
Pattern matching
 
Pattern matching programs
Pattern matching programsPattern matching programs
Pattern matching programs
 
Boyer more algorithm
Boyer more algorithmBoyer more algorithm
Boyer more algorithm
 
String matching algorithms-pattern matching.
String matching algorithms-pattern matching.String matching algorithms-pattern matching.
String matching algorithms-pattern matching.
 
Introduction to recommender systems
Introduction to recommender systemsIntroduction to recommender systems
Introduction to recommender systems
 
Lecture 1 maximum likelihood
Lecture 1 maximum likelihoodLecture 1 maximum likelihood
Lecture 1 maximum likelihood
 
Sufficiency
SufficiencySufficiency
Sufficiency
 
Advances in composite integer factorization
Advances in composite integer factorizationAdvances in composite integer factorization
Advances in composite integer factorization
 
The transportation problem in an intuitionistic fuzzy environment
The transportation problem in an intuitionistic fuzzy environmentThe transportation problem in an intuitionistic fuzzy environment
The transportation problem in an intuitionistic fuzzy environment
 
Learning deep structured semantic models for web search
Learning deep structured semantic models for web searchLearning deep structured semantic models for web search
Learning deep structured semantic models for web search
 

Similar to Brute Force

Discrete structure ch 3 short question's
Discrete structure ch 3 short question'sDiscrete structure ch 3 short question's
Discrete structure ch 3 short question'shammad463061
 
Perform brute force
Perform brute forcePerform brute force
Perform brute forceSHC
 
Systems in the small - Introduction to Algorithms
Systems in the small - Introduction to AlgorithmsSystems in the small - Introduction to Algorithms
Systems in the small - Introduction to AlgorithmsDavid Millard
 
Efficient Sparse Coding Algorithms
Efficient Sparse Coding AlgorithmsEfficient Sparse Coding Algorithms
Efficient Sparse Coding AlgorithmsAnshu Dipit
 
A New Method Based on MDA to Enhance the Face Recognition Performance
A New Method Based on MDA to Enhance the Face Recognition PerformanceA New Method Based on MDA to Enhance the Face Recognition Performance
A New Method Based on MDA to Enhance the Face Recognition PerformanceCSCJournals
 
An Application of Pattern matching for Motif Identification
An Application of Pattern matching for Motif IdentificationAn Application of Pattern matching for Motif Identification
An Application of Pattern matching for Motif IdentificationCSCJournals
 
notes as .ppt
notes as .pptnotes as .ppt
notes as .pptbutest
 
Introduction.doc
Introduction.docIntroduction.doc
Introduction.docbutest
 
An Automatic Medical Image Segmentation using Teaching Learning Based Optimiz...
An Automatic Medical Image Segmentation using Teaching Learning Based Optimiz...An Automatic Medical Image Segmentation using Teaching Learning Based Optimiz...
An Automatic Medical Image Segmentation using Teaching Learning Based Optimiz...idescitation
 
ch03-2018.02.02.pptx
ch03-2018.02.02.pptxch03-2018.02.02.pptx
ch03-2018.02.02.pptxSYAMDAVULURI
 
Unit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxUnit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxDr.M.Karthika parthasarathy
 
Basic Foundations of Automata Theory
Basic Foundations of Automata TheoryBasic Foundations of Automata Theory
Basic Foundations of Automata Theorysaugat86
 
Machine learning (5)
Machine learning (5)Machine learning (5)
Machine learning (5)NYversity
 

Similar to Brute Force (20)

Discrete structure ch 3 short question's
Discrete structure ch 3 short question'sDiscrete structure ch 3 short question's
Discrete structure ch 3 short question's
 
DAA UNIT 3
DAA UNIT 3DAA UNIT 3
DAA UNIT 3
 
Perform brute force
Perform brute forcePerform brute force
Perform brute force
 
Systems in the small - Introduction to Algorithms
Systems in the small - Introduction to AlgorithmsSystems in the small - Introduction to Algorithms
Systems in the small - Introduction to Algorithms
 
Efficient Sparse Coding Algorithms
Efficient Sparse Coding AlgorithmsEfficient Sparse Coding Algorithms
Efficient Sparse Coding Algorithms
 
A New Method Based on MDA to Enhance the Face Recognition Performance
A New Method Based on MDA to Enhance the Face Recognition PerformanceA New Method Based on MDA to Enhance the Face Recognition Performance
A New Method Based on MDA to Enhance the Face Recognition Performance
 
An Application of Pattern matching for Motif Identification
An Application of Pattern matching for Motif IdentificationAn Application of Pattern matching for Motif Identification
An Application of Pattern matching for Motif Identification
 
notes as .ppt
notes as .pptnotes as .ppt
notes as .ppt
 
syllabus-CBR.pdf
syllabus-CBR.pdfsyllabus-CBR.pdf
syllabus-CBR.pdf
 
4 report format
4 report format4 report format
4 report format
 
4 report format
4 report format4 report format
4 report format
 
ML Lec 1 (1).pptx
ML Lec 1 (1).pptxML Lec 1 (1).pptx
ML Lec 1 (1).pptx
 
Introduction.doc
Introduction.docIntroduction.doc
Introduction.doc
 
An Automatic Medical Image Segmentation using Teaching Learning Based Optimiz...
An Automatic Medical Image Segmentation using Teaching Learning Based Optimiz...An Automatic Medical Image Segmentation using Teaching Learning Based Optimiz...
An Automatic Medical Image Segmentation using Teaching Learning Based Optimiz...
 
IMPLEMENTATION OF DIFFERENT PATTERN RECOGNITION ALGORITHM
IMPLEMENTATION OF DIFFERENT PATTERN RECOGNITION  ALGORITHM  IMPLEMENTATION OF DIFFERENT PATTERN RECOGNITION  ALGORITHM
IMPLEMENTATION OF DIFFERENT PATTERN RECOGNITION ALGORITHM
 
ch03-2018.02.02.pptx
ch03-2018.02.02.pptxch03-2018.02.02.pptx
ch03-2018.02.02.pptx
 
Unit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxUnit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptx
 
Basic Foundations of Automata Theory
Basic Foundations of Automata TheoryBasic Foundations of Automata Theory
Basic Foundations of Automata Theory
 
Machine learning (5)
Machine learning (5)Machine learning (5)
Machine learning (5)
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 

More from Ajeng Savitri

Software Testing Documentation
Software Testing DocumentationSoftware Testing Documentation
Software Testing DocumentationAjeng Savitri
 
Software Productivity Measurement
Software Productivity MeasurementSoftware Productivity Measurement
Software Productivity MeasurementAjeng Savitri
 
Software Testing Strategy (Part 2)
Software Testing Strategy (Part 2)Software Testing Strategy (Part 2)
Software Testing Strategy (Part 2)Ajeng Savitri
 
Software Testing Strategy
Software Testing StrategySoftware Testing Strategy
Software Testing StrategyAjeng Savitri
 
Object Oriented Testing
Object Oriented TestingObject Oriented Testing
Object Oriented TestingAjeng Savitri
 
Testing Technique (Part 2)
Testing Technique (Part 2)Testing Technique (Part 2)
Testing Technique (Part 2)Ajeng Savitri
 
Methodology Selection Strategy
Methodology Selection Strategy Methodology Selection Strategy
Methodology Selection Strategy Ajeng Savitri
 
Software Testing - Software Quality (Part 2)
Software Testing - Software Quality (Part 2)Software Testing - Software Quality (Part 2)
Software Testing - Software Quality (Part 2)Ajeng Savitri
 
Software Testing - Software Quality
Software Testing - Software QualitySoftware Testing - Software Quality
Software Testing - Software QualityAjeng Savitri
 
Computer Evolution and Performance
Computer Evolution and PerformanceComputer Evolution and Performance
Computer Evolution and PerformanceAjeng Savitri
 
Software Testing - Introduction
Software Testing - IntroductionSoftware Testing - Introduction
Software Testing - IntroductionAjeng Savitri
 
Requirement Gathering
Requirement GatheringRequirement Gathering
Requirement GatheringAjeng Savitri
 

More from Ajeng Savitri (20)

Software Testing Documentation
Software Testing DocumentationSoftware Testing Documentation
Software Testing Documentation
 
Software Productivity Measurement
Software Productivity MeasurementSoftware Productivity Measurement
Software Productivity Measurement
 
Debugging (Part 2)
Debugging (Part 2)Debugging (Part 2)
Debugging (Part 2)
 
Debugging
DebuggingDebugging
Debugging
 
Software Testing Strategy (Part 2)
Software Testing Strategy (Part 2)Software Testing Strategy (Part 2)
Software Testing Strategy (Part 2)
 
Software Testing Strategy
Software Testing StrategySoftware Testing Strategy
Software Testing Strategy
 
Object Oriented Testing
Object Oriented TestingObject Oriented Testing
Object Oriented Testing
 
Testing Technique (Part 2)
Testing Technique (Part 2)Testing Technique (Part 2)
Testing Technique (Part 2)
 
Testing Technique
Testing TechniqueTesting Technique
Testing Technique
 
Testing Plan
Testing PlanTesting Plan
Testing Plan
 
Methodology Selection Strategy
Methodology Selection Strategy Methodology Selection Strategy
Methodology Selection Strategy
 
Software Testing - Software Quality (Part 2)
Software Testing - Software Quality (Part 2)Software Testing - Software Quality (Part 2)
Software Testing - Software Quality (Part 2)
 
Software Testing - Software Quality
Software Testing - Software QualitySoftware Testing - Software Quality
Software Testing - Software Quality
 
Computer Evolution and Performance
Computer Evolution and PerformanceComputer Evolution and Performance
Computer Evolution and Performance
 
Software Testing - Introduction
Software Testing - IntroductionSoftware Testing - Introduction
Software Testing - Introduction
 
Sequence Diagram
Sequence DiagramSequence Diagram
Sequence Diagram
 
Activity Diagram
Activity DiagramActivity Diagram
Activity Diagram
 
Use Case Diagram
Use Case DiagramUse Case Diagram
Use Case Diagram
 
Requirement Gathering
Requirement GatheringRequirement Gathering
Requirement Gathering
 
Business Value
Business ValueBusiness Value
Business Value
 

Recently uploaded

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 

Recently uploaded (20)

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 

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

  1. 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
  2. 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
  3. 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