Divide And Conquer
Minimum Spanning Tree
What is Backtracking?
It is an algorithmic technique that considers searching every possible combination in order to solve a computational problem. It is the method of building the solution one piece at a time recursively and incrementally. The method keeps removing all those choices that do not contribute to the solution. Backtracking is considered to be best fit for only specific categorized problems, i.e., decision making problems, optimization problems and enumeration problems.
Decision making problem :To find the path from given source to destination point in a maze
Optimization problem :Queens's problem
Enumeration problem : Knapsack problem
What is Recursive Maze Algorithm?
It is one of the best implementation of Backtracking technique. In terms of programming language, a maze can be represented by a 2D array. In general, a maze can be defined as collection of both successful and unsuccessful paths between two points namely source and destination. The recursive maze algorithm is the algorithm designed to solve the maze-type problems where the base concept of algorithm is backtracking.
Example: Consider the following-
The concept of recursive maze problems goes as follows:
1 (START) 1 1 1
1 0 0 0
1 1 1 0
1 0 1 1 (END)
Consider the above maze where 0 means there could be no possibility to pass through that particular cell, and 1 is allowed to go through that particular cell.
Out of all the ways of successfully reaching END point from the START, we find only 1 particular way being possible which allows reaching the end (destination) successful. (As marked above)
These types of problems are called as recursive maze problem.
Explain Hamiltonian Circuit Problems?
Hamiltonian circuit problems are the ones which have a condition that each and every node of the given graph must be visited for exactly one time.
Real life examples include electrical connections in a household, a complete route from a source location to destination and back to source in a different route.
Explain Subset-Sum Problem?
A set can be defined as a collection of homogeneous elements. Array is considered to be the basic data structure where as even other data structures can also are considered for a set.
Sets in java are more popularly considered as the data structure to represent set than an array.
Subset is considered to be a portion of sets. A subset may be of length zero to a complete set length.
The subset problem deals with the extraction of a subset from a set upon the given condition.
Explain N-Queens Problem?
N Queens's problem deal with the placement of N number of queens on a square maze where distance between two queens should be greater than one unit in any dimension, i.e., either of row, column or diagonal.
Explain m-color Problem?
m-color problem deals with coloring of nodes for given graph with the condition that no two adjacent nodes should have same color.
The minimum number of colors possible with the above condition for a given graph/cycle is called as chromatic number.
The m-color problem is also popularly called as vertex-coloring problem.
Explain with example the implementation of Backtracking in Knapsack problem.
Knapsack problem deals with finding the maximum possible value against least possible sum of weights for the given set of pairs of weights and values.
As already discussed backtracking is the mechanism which implements multiple recursions to find the optimal possibility.
As Knapsack being one such target problem of backtracking, thus, backtracking is also considered to be one of the solution approaches to solve knapsack.
Example: Consider the following example,
Give an example of back tracking in daily life.
The real life examples of back tracking in day to day life are as follows:
Solving a Sudoku puzzle
Finding the shortest path in the graph between two nodes. (In GPS tracking)
Finding the safer ways for a coin to move in a chess board.