Sitemap
Towards AI

We train AI Engineers. We deploy Enterprise AI. Join 100K+ AI practitioners at Towards AI Academy or reach out for help making your company AI native. towardsai.com

Member-only story

Understanding Backtracking using Python: Beginners Guide

--

Backtracking is an algorithm used to search for all possible solutions to a problem. In this technique, we find a solution to a problem by incrementally building a solution and undoing it when it is not correct or when all the possibilities are explored. It is commonly used in problems where there is a chance of one or more valid solutions to a problem. Backtracking is often implemented using recursion.

Press enter or click to view image in full size
Backtracking

Types of Backtracking:

While backtracking can be used to solve problems such as Decision problems, optimization problems, and Enumeration problems, there are different types of Backtracking —

  • Recursive Backtracking: Backtracking is often implemented using recursive functions, with each recursive call representing a decision. In a few cases, iterative backtracking is used, using stacks and queues to keep track of decisions.
  • Optimization Backtracking: In a few problems, Backtracking is used not only to find all possible solutions but also to find the best solution among the possibilities. This involves pruning techniques to eliminate calls that cannot lead to optimal solutions. Sometimes, Backtracking can also be coupled with memoization and tabulation in Dynamic Programming.
  • Heuristic Backtracking: This kind of backtracking is mostly…

--

--

Muttineni Sai Rohith
Muttineni Sai Rohith

Written by Muttineni Sai Rohith

Senior Data Engineer with experience in Python, Pyspark and SQL! Reach me at sairohith.muttineni@gmail.com

Towards AI
Towards AI

Published in Towards AI

We train AI Engineers. We deploy Enterprise AI. Join 100K+ AI practitioners at Towards AI Academy or reach out for help making your company AI native. towardsai.com