Backtracking with Examples
Introduction
•Overview
•Explain with a diagram that has dead-ends
•Examples chosen:
•N-queens problem
•Subset sum problem
•Hamiltonian cycle problem
3
N-queens Problem
• Define the problem
• If two queens are placed at positions (i, j) and (k, l)
• Then, they are on the same diagonal iff i – j = k – l or i+j = k+l
• Here, first equation implies that j – l = i – k
• The second equation implies that j – l = k - i
• Combining the two, we get |j – l |= |i – k|
Illustration with 4-queens
Algorithm for N-queens Problem
Subset Sum Problem
• Problem definition: Find a subset of a given set A = {a1, . . . , an} of n
positive integers whose sum is equal to a given positive integer d.
• For example, for A = {1, 2, 5, 6, 8} and d = 9, there are two solutions:
{1, 2, 6} and {1, 8}.
• Of course, some instances of this problem may have no solutions.
• It is convenient to sort the set’s elements in increasing order. So, we
will assume that
a1< a2< . . . < an.
• The state-space tree can be constructed as a binary tree like that in
Figure shown below for the instance A = {3, 5, 6, 7} and d = 15.
State-space tree
Hamiltonian Cycle Problem
• Informal Definition
• Formal Definition
• Examples
Algorithm
Subroutine

More Related Content

PDF
2016--04-07-NCUR-JON (1)
PPTX
it is a ppt discussing important topic of daa such as branch and bound.pptx
PPT
G9 Math Q1- Week 1 Intro of Quadratic Equation.ppt
DOC
Unit 4 jwfiles
PPTX
Maths Assignment Help
PPTX
Maths Assignment Help
PDF
Partial midterm set7 soln linear algebra
PPTX
Linear Algebra Assignment help
2016--04-07-NCUR-JON (1)
it is a ppt discussing important topic of daa such as branch and bound.pptx
G9 Math Q1- Week 1 Intro of Quadratic Equation.ppt
Unit 4 jwfiles
Maths Assignment Help
Maths Assignment Help
Partial midterm set7 soln linear algebra
Linear Algebra Assignment help

Similar to A-Backtracking with examples.pptxA-Backtracking with examples.pptx (20)

PDF
Algorithm Performance For Chessboard Separation Problems
PPSX
Chapter 4- Learning Outcome 2_Mathematics for Technologists
PPT
G9-Math-Q1-Week-1-Intro-of-Quadratic-Equation.ppt
DOC
algorithm Unit 4
PPTX
Diagonalization of matrix
PPT
Hprec2 4
PPT
Lecture 01 - Linear Equations.ppt
PDF
unit 4 of Unit 4 of design and analysis of algorithms
PPTX
Fundamental Problems in Number Theory.pptx
PPT
1560 mathematics for economists
PPTX
Class IX- Linear Equation in Two Variables-IX.pptx
PPTX
811109685-CS3401-Algorithms-Unit-IV.pptx
PPTX
Maths-->>Eigenvalues and eigenvectors
PPTX
Graph of a linear equation vertical lines
PDF
matrix-algebra-for-engineers (1).pdf
PPTX
Class IX- Linear Equation in Two Variables-IX.pptx
PPTX
Backtracking
PPT
Grade mathematics: Quadratic Inequalities
PDF
Lecture_note2.pdf
PDF
IMT, col space again
Algorithm Performance For Chessboard Separation Problems
Chapter 4- Learning Outcome 2_Mathematics for Technologists
G9-Math-Q1-Week-1-Intro-of-Quadratic-Equation.ppt
algorithm Unit 4
Diagonalization of matrix
Hprec2 4
Lecture 01 - Linear Equations.ppt
unit 4 of Unit 4 of design and analysis of algorithms
Fundamental Problems in Number Theory.pptx
1560 mathematics for economists
Class IX- Linear Equation in Two Variables-IX.pptx
811109685-CS3401-Algorithms-Unit-IV.pptx
Maths-->>Eigenvalues and eigenvectors
Graph of a linear equation vertical lines
matrix-algebra-for-engineers (1).pdf
Class IX- Linear Equation in Two Variables-IX.pptx
Backtracking
Grade mathematics: Quadratic Inequalities
Lecture_note2.pdf
IMT, col space again
Ad

Recently uploaded (20)

PPTX
Fundamentals of Mechanical Engineering.pptx
PPTX
Software Engineering and software moduleing
PDF
Abrasive, erosive and cavitation wear.pdf
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PPTX
Feature types and data preprocessing steps
PPTX
communication and presentation skills 01
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PPTX
introduction to high performance computing
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PPTX
Current and future trends in Computer Vision.pptx
PPTX
Module 8- Technological and Communication Skills.pptx
Fundamentals of Mechanical Engineering.pptx
Software Engineering and software moduleing
Abrasive, erosive and cavitation wear.pdf
Information Storage and Retrieval Techniques Unit III
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
"Array and Linked List in Data Structures with Types, Operations, Implementat...
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Feature types and data preprocessing steps
communication and presentation skills 01
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
introduction to high performance computing
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
August 2025 - Top 10 Read Articles in Network Security & Its Applications
August -2025_Top10 Read_Articles_ijait.pdf
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
Current and future trends in Computer Vision.pptx
Module 8- Technological and Communication Skills.pptx
Ad

A-Backtracking with examples.pptxA-Backtracking with examples.pptx

  • 2. Introduction •Overview •Explain with a diagram that has dead-ends •Examples chosen: •N-queens problem •Subset sum problem •Hamiltonian cycle problem
  • 3. 3 N-queens Problem • Define the problem • If two queens are placed at positions (i, j) and (k, l) • Then, they are on the same diagonal iff i – j = k – l or i+j = k+l • Here, first equation implies that j – l = i – k • The second equation implies that j – l = k - i • Combining the two, we get |j – l |= |i – k|
  • 6. Subset Sum Problem • Problem definition: Find a subset of a given set A = {a1, . . . , an} of n positive integers whose sum is equal to a given positive integer d. • For example, for A = {1, 2, 5, 6, 8} and d = 9, there are two solutions: {1, 2, 6} and {1, 8}. • Of course, some instances of this problem may have no solutions. • It is convenient to sort the set’s elements in increasing order. So, we will assume that a1< a2< . . . < an. • The state-space tree can be constructed as a binary tree like that in Figure shown below for the instance A = {3, 5, 6, 7} and d = 15.
  • 8. Hamiltonian Cycle Problem • Informal Definition • Formal Definition • Examples