SlideShare a Scribd company logo
3
Most read
7
Most read
Backtracking Algorithm
Objectives
• Backtracking Programming Technique
• Applications
• N-Queens Problem
• Complexity of N-Queens Problem
• Backtracking vs Dynamic Programming
Algorithms
Backtracking Programming Technique
A backtracking algorithm tries to build a solution
to a computational problem incrementally.
Whenever the algorithm needs to decide
between multiple alternatives to the next
component of the solution, it simply tries all
possible options recursively.
Applications
• N-Queens Problem
• Subset sum Problem
• Rat in a Maze Problem
• Sudoku
• Hamiltonian Cycle
• Longest Common Subsequence
N-Queen Problem
• Goal: position n queens on a n x n board such
that no two queens threaten each other
• No two queens may be in the same row,
column, or diagonal
• Sequence: n positions where queens are
placed
• Set: n2 positions on the board
• Criterion: no two queens threaten each other
4-Queen Problem Solution
• 4-Queen Problem Assign each queen a
different row
• Check which column combinations yield
solutions
• Each queen can be in any one of four columns:
4 x 4 x 4 x 4 = 256
Q
Q
Q
Q
Complexity of N-Queens Problem
Theta(n^n)
For example- 4-Queens problem the complexity
is-
Theta(4^4)
Algorithm
1) Start in the leftmost column
2) 2) If all queens are placed return true
3) 3) Try all rows in the current column. Do following for every tried
row.
a) If the queen can be placed safely in this row then mark this [row,
column] as part of the solution and recursively check if placing queen
here leads to a solution.
b) If placing the queen in [row, column] leads to a solution then return
true.
c) If placing queen doesn't lead to a solution then unmark this [row,
column] (Backtrack) and go to step (a) to try other rows.
4) If all rows have been tried and nothing worked, return false to trigger
backtracking.
Backtracking Algorithm.pptx
Backtracking vs Dynamic Programming
• Dynamic Programming – subsets of a solution
are generated
• Backtracking – Technique for deciding that
some subsets need not be generated
• Efficient for many large instances of a problem
(but not all)

More Related Content

PDF
Artificial Intelligence - Hill climbing.
PPTX
8 queens problem.pptx
PPTX
Brute force method
PPT
Problems, Problem spaces and Search
PDF
DAA Notes.pdf
PPTX
8 QUEENS PROBLEM.pptx
PPTX
Heap Sort in Design and Analysis of algorithms
PDF
I. Hill climbing algorithm II. Steepest hill climbing algorithm
Artificial Intelligence - Hill climbing.
8 queens problem.pptx
Brute force method
Problems, Problem spaces and Search
DAA Notes.pdf
8 QUEENS PROBLEM.pptx
Heap Sort in Design and Analysis of algorithms
I. Hill climbing algorithm II. Steepest hill climbing algorithm

What's hot (20)

PPTX
Fuzzy set and its application
PDF
Convolutional Neural Network Models - Deep Learning
PPTX
Convolutional neural network
PPT
3 problem-solving-
PPTX
Cluster computing
PPTX
Load Balancing In Distributed Computing
PPTX
expertsystem.pptx email
PPTX
Lecture optimal binary search tree
PPTX
Art network
PPTX
data structures- back tracking
PPTX
Backtracking
PPTX
AI_ppt.pptx
PPTX
Resolution method in AI.pptx
PPTX
Unit 2 ai
PDF
DATA STRUCTURE.pdf
PPTX
N queen problem
PDF
N Queens problem
PPTX
implementation of travelling salesman problem with complexity ppt
PPTX
Problem solving in Artificial Intelligence.pptx
PPTX
Greedy Algorithm - Knapsack Problem
Fuzzy set and its application
Convolutional Neural Network Models - Deep Learning
Convolutional neural network
3 problem-solving-
Cluster computing
Load Balancing In Distributed Computing
expertsystem.pptx email
Lecture optimal binary search tree
Art network
data structures- back tracking
Backtracking
AI_ppt.pptx
Resolution method in AI.pptx
Unit 2 ai
DATA STRUCTURE.pdf
N queen problem
N Queens problem
implementation of travelling salesman problem with complexity ppt
Problem solving in Artificial Intelligence.pptx
Greedy Algorithm - Knapsack Problem
Ad

Similar to Backtracking Algorithm.pptx (20)

PPTX
N queens using backtracking
PPTX
8queensproblemusingbacktracking-120903114053-phpapp01.pptx
PPTX
proficiency presenattion on topic of backtracking algo
PPTX
N-queens.pptx
PPT
Backtracking Algorithm.ppt
PPTX
Backtracking Basics.pptx
PPTX
N Queen Algorithm
PDF
Ai lecture 10(unit02)
PPTX
The n Queen Problem
PPTX
Design Algorithms - - Backtracking.pptx
PDF
N Queen Problem
PPT
BackTracking Algorithm: Technique and Examples
PPTX
Backtrack-search-algorithm (2).pptx
PPTX
Branch and bound
PDF
module5_backtrackingnbranchnbound_2022.pdf
PPTX
it is a ppt discussing important topic of daa such as branch and bound.pptx
PDF
Genetic Algorithm Artificial Intelligence
PDF
unit 4 of Unit 4 of design and analysis of algorithms
PPTX
Backtrack search-algorithm
N queens using backtracking
8queensproblemusingbacktracking-120903114053-phpapp01.pptx
proficiency presenattion on topic of backtracking algo
N-queens.pptx
Backtracking Algorithm.ppt
Backtracking Basics.pptx
N Queen Algorithm
Ai lecture 10(unit02)
The n Queen Problem
Design Algorithms - - Backtracking.pptx
N Queen Problem
BackTracking Algorithm: Technique and Examples
Backtrack-search-algorithm (2).pptx
Branch and bound
module5_backtrackingnbranchnbound_2022.pdf
it is a ppt discussing important topic of daa such as branch and bound.pptx
Genetic Algorithm Artificial Intelligence
unit 4 of Unit 4 of design and analysis of algorithms
Backtrack search-algorithm
Ad

Recently uploaded (20)

PPTX
Information Storage and Retrieval Techniques Unit III
PDF
86236642-Electric-Loco-Shed.pdf jfkduklg
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPTX
introduction to high performance computing
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPT
Total quality management ppt for engineering students
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Information Storage and Retrieval Techniques Unit III
86236642-Electric-Loco-Shed.pdf jfkduklg
Visual Aids for Exploratory Data Analysis.pdf
introduction to high performance computing
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
R24 SURVEYING LAB MANUAL for civil enggi
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
Safety Seminar civil to be ensured for safe working.
Fundamentals of Mechanical Engineering.pptx
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Total quality management ppt for engineering students
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Fundamentals of safety and accident prevention -final (1).pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Automation-in-Manufacturing-Chapter-Introduction.pdf
UNIT 4 Total Quality Management .pptx
Categorization of Factors Affecting Classification Algorithms Selection
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS

Backtracking Algorithm.pptx

  • 2. Objectives • Backtracking Programming Technique • Applications • N-Queens Problem • Complexity of N-Queens Problem • Backtracking vs Dynamic Programming Algorithms
  • 3. Backtracking Programming Technique A backtracking algorithm tries to build a solution to a computational problem incrementally. Whenever the algorithm needs to decide between multiple alternatives to the next component of the solution, it simply tries all possible options recursively.
  • 4. Applications • N-Queens Problem • Subset sum Problem • Rat in a Maze Problem • Sudoku • Hamiltonian Cycle • Longest Common Subsequence
  • 5. N-Queen Problem • Goal: position n queens on a n x n board such that no two queens threaten each other • No two queens may be in the same row, column, or diagonal • Sequence: n positions where queens are placed • Set: n2 positions on the board • Criterion: no two queens threaten each other
  • 6. 4-Queen Problem Solution • 4-Queen Problem Assign each queen a different row • Check which column combinations yield solutions • Each queen can be in any one of four columns: 4 x 4 x 4 x 4 = 256 Q Q Q Q
  • 7. Complexity of N-Queens Problem Theta(n^n) For example- 4-Queens problem the complexity is- Theta(4^4)
  • 8. Algorithm 1) Start in the leftmost column 2) 2) If all queens are placed return true 3) 3) Try all rows in the current column. Do following for every tried row. a) If the queen can be placed safely in this row then mark this [row, column] as part of the solution and recursively check if placing queen here leads to a solution. b) If placing the queen in [row, column] leads to a solution then return true. c) If placing queen doesn't lead to a solution then unmark this [row, column] (Backtrack) and go to step (a) to try other rows. 4) If all rows have been tried and nothing worked, return false to trigger backtracking.
  • 10. Backtracking vs Dynamic Programming • Dynamic Programming – subsets of a solution are generated • Backtracking – Technique for deciding that some subsets need not be generated • Efficient for many large instances of a problem (but not all)