0% found this document useful (0 votes)
11 views

Backtracking

Uploaded by

Duc Le
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Backtracking

Uploaded by

Duc Le
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Backtracking Algorithm

Properad By

Salm Ibrahim

2021 Supervised By

Mr. Arsalan R .Mirza


1
Content
 Backtracking History.
 What is Backtracking?
 Who is using Backtracking?
 How does Working?
 Advantage
 Disadvantage
 Time complexity

2
Backtracking History

 ‘Backtrack’ the Word was first introduced by Dr. D.H Lehmer in 1950s.
 R.J Walker Was the First man who gave algorithmic description in 1960.
 Later developed by S. Golamb and L. Baumert.

3
Backtracking Algorithm
Backtracking is methodical way of trying out various sequences of
decisions, until you find one that works.
Backtracking allows us to systematically try all available
Avenues from a certain point after some of them lead to nowhere.

4
Who is using Backtracking?
Using Backtracking always return to a position which offers other
possibilities for successfully solving the problem.

Example:
• n-queen problem
• graph coloring problem
• hamilton cycle
• subset sum problem

5
Backtracking (Working)
dead end
?
dead end
dead end

?
start ? ?
dead end

dead end

success!

6
N-Queens Backtracking Algorithm
•N queens problem is one of the
most common examples of
backtracking. Our goal is to
arrange N queens on an NxN
chessboard such that no queen
can strike down any other queen.
A queen can attack horizontally,
vertically, or diagonally.

7
4-queen problem

8
we will start by placing the first queen in the first row.

9
Now, the second step is to place the second queen in a safe position. Also, we can't
place the queen in the first row, so we will try putting the queen in the second row
this time.

10
Let's place the third queen in a safe position, somewhere in the third
row.

11
Backtrack to second row change the
location queen.

12
And now we will place the third queen again in a safe position
other than the previously placed position in the third row.

13
Solution

14
Advantage
1. Comparison with the Dynamic Programming, Backtracking
Approach is more effective in some cases.
2. Backtracking Algorithm is the best option for solving tactical
problem.
3. In greedy Algorithm, getting the Global Optimal Solution is a
long procedure and depends on user statements but in
Backtracking It Can Easily getable.
4. Backtracking technique is simple to implement and easy to code.
5. The accuracy is granted.

15
Disadvantages
1. Backtracking Approach is not efficient for solving strategic
Problem.
2. The overall runtime of Backtracking Algorithm is normally slow
3. To solve Large Problem Sometime it needs to take the help of
other techniques like Branch and bound.
4. Need Large amount of memory space for storing different state
function in the stack for big problem.

16
Pseudo Code
boolean findSolutions(n, other params) :
if (found a solution) :
displaySolution();
return true;

for (val = first to last) :


if (isValid(val, n)) :
applyValue(val, n);
if (findSolutions(n+1, other params))
return true;
removeValue(val, n);
return false;

17
Time Complexity
The time complexity of the algorithm will be a measure specific to
what problem we are trying to solve.
1. n-queen problem: O(n!)
2. subset sum problem:O(nW)

18
Any Question?

19
Reference
• http://jeffe.cs.illinois.edu/teaching/algorithms/book/02-
backtracking.pdf
• https://www.sharjah.ac.ae/en/Media/Conferences/ME-
GPC/Documents/Chapter%208%20-%20Backtracking.pdf

20

You might also like