Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Analysis and Design of Algorithms - Brute Force Method

Rating
-
Sold
-
Pages
20
Uploaded on
13-06-2022
Written in
2021/2022

This unit defines brute force method and analyzes selection sort and bubble sort with this method. It analyzes and computes sequential search and brute force string matching. It also explains and discusses the exhaustive search.

Institution
Course

Content preview

Unit 5 Brute Force Method
Structure:
5.1 Introduction
Objectives
5.2 Brute Force
Brute force algorithm
5.3 Selection Sort and Bubble Sort
Selection sort
Bubble sort
5.4 Sequential Search and Brute Force String Matching
Sequential search
Brute Force string matching
5.5 Exhaustive Search
Definition
Implementation
Reordering the exhaustive search
Speeding up exhaustive search
Alternatives to the exhaustive search
5.6 Summary
5.7 Glossary
5.8 Terminal Questions
5.9 Answers

5.1 Introduction
In the earlier unit you studied about the mathematical analysis of algorithms.
In this unit you will study about brute force method in detail with algorithms.

Brute force is a problem solving technique wherein we compute a series of
possible answers and test each possible answer for accuracy. It simply tries
all possibilities until a satisfactory solution is found. Once it finds the value
for the best solution it stops. In this unit we will discuss various algorithms
which make use of the brute force method.

Objectives:
After studying this unit, you should be able to:
define brute force method
describe and analyze selection sort and bubble sort

, analyze and compute sequential search and brute force string matching

explain and discuss the exhaustive search

5.2 Brute Force
Let us first define brute force.
Definition - Brute force is defined as a primitive programming technique
where the programmer relies on the processing strength of the computing
system rather than his own intelligence to simplify the problem. Here the
programmer applies appropriate methods to find a series of possible
answers and tests each possible answer for accuracy.

Let us now discuss the brute force algorithm.
5.2.1 Brute force algorithm
Brute force algorithm is a basic algorithm which works through every
possible answer until the correct one is found. We can solve a particular
problem easily using brute force algorithm rather than wasting time on
creating a more elegant solution, especially when the size of the problem is
smal.

A good brute force algorithm should have the following factors in it.
.Smal number of sub solutions
Specific order in the sub solutions
Sub solutions must be evaluated quickly
Let us take an example of counting change.
Consider a cashier who counts some amount of currency with a collection of
notes and coins of different denominations. The cashier must count a
specified sum using the smallest possible number of notes or coins.
Let us now analyze the problem mathematically.
Consider n as number of notes or coins and the set of different
denominations of currency P= ip1. p2,.pn.j.
Let d, denomination of pi
In the Indian system p.= { Rs 1, Rs 2, Rs 5, Rs 10,.) the d = { 1, 2,5, 10.)
If we have to count a given sum of money A we need to find the smallest

subset of P such that d
pie S A.

, Let us represent the subset S withn variables as X =
{*.x2,...
Such that
(1 Pi E S
K n Pi S

For {d1,d2....dn} we have to minimize ass

Xi
i=l

Such that
1

dax = A
i=l



Since each element of X, X={i,x2,..n. is either equal to zero or one,
there will be 2" possible values for any X in an algorithm. The best solution
for brute force algorithm to solve a problem is to compute all the possible
values, given any variable X.

For each possible value of X, we check whether the constraintdai = A
i=l


is satisfied for it or not. A value that satisfies the constraint is called as a
n
feasible solution. An objective function 2 is associated with an

optimization problem determining how good a solution is.

Since there are 2" possible values of X, we assume that the running time of
brute-force solution is Q (2"). The running time needed to determine whether
a possible value of a feasible solution is O(n) and the time required to
compute the objective function is also O(n) is O(n2").

Activity 1
Write a brute force algorithm to compare 25 text characters in an array
and match with one character.

Written for

Institution
Course

Document information

Uploaded on
June 13, 2022
Number of pages
20
Written in
2021/2022
Type
Class notes
Professor(s)
Joseph
Contains
All classes

Subjects

$3.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
nikhilcs

Also available in package deal

Get to know the seller

Seller avatar
nikhilcs Nikhil
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
14
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions