This preview shows pages 1–7. Sign up to view the full content.
Computer Science Department
University of Central Florida
Backtracking
COP 3502 – Computer Science I
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document Backtracking
page 2
Preliminaries
Exhaustive Search
What is an exhaustive search?
a trivial but very general problemsolving technique that
consists of:
1)
systematically enumerating all possible
candidates
for
the solution, and
2)
checking whether each candidate satisfies the
problem's statement
aka “bruteforce” search
Bruteforce is simple to implement
And given enough time, it will always find a
solution
Backtracking
page 3
Preliminaries
Exhaustive Search
Example:
Let’s say you want to find all the possible divisors of
some natural number, n.
The exhaustive, bruteforce approach would be to
enumerate ALL integers from 1 to n
and then check whether each of them divides n without
any remainder
Think of bruteforce as searching without a brain
Example 2:
A bruteforce search of a node in a BST would ignore the
ordering property and, instead, would search EACH and
every single node
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document Backtracking
page 4
Preliminaries
Exhaustive Search
Benefit of BruteForce:
You are guaranteed to find a solution
Since your algorithm will ultimately try EACH AND
EVERY possible
candidate
solution, you will find the real
solution
Negative of BruteForce:
It takes a LOOOOOOOONG time.
Sure, your algorithm, in theory, will produce a solution
But most likely not in your lifetime!
Even for average size values of n, the running time is
often computationally prohibitive.
Backtracking
page 5
Backtracking
What is backtracking?
Often no more than a clever implementation of an
exhaustive search
BUT, the savings over a brute force algorithm can
be significant
Backtracking could degenerate, in a worst case, to
a brute force, exhaustive search
But in most cases, better cases,
backtracking
only checks a subset of possibilities within the
search
.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document Backtracking
page 6
Backtracking
Simple example:
Arrange furniture in the house
An exhaustive search:
Would find ALL POSSIBLE furniture arrangements and
check to see if one fits in the house
This is WAAAAAAY crazy
Computationally prohibitive!!!
Backtracking:
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 09/21/2011 for the course COP 3330 taught by Professor Staff during the Spring '08 term at University of Central Florida.
 Spring '08
 Staff
 Computer Science

Click to edit the document details