Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
PHP 7 Data Structures and Algorithms

You're reading from  PHP 7 Data Structures and Algorithms

Product type Book
Published in May 2017
Publisher Packt
ISBN-13 9781786463890
Pages 340 pages
Edition 1st Edition
Languages
Author (1):
Mizanur Rahman Mizanur Rahman
Profile icon Mizanur Rahman

Table of Contents (14) Chapters

Preface Introduction to Data Structures and Algorithms Understanding PHP Arrays Using Linked Lists Constructing Stacks and Queues Applying Recursive Algorithms - Recursion Understanding and Implementing Trees Using Sorting Algorithms Exploring Search Options Putting Graphs into Action Understanding and Using Heaps Solving Problems with Advanced Techniques PHP Built-In Support for Data Structures and Algorithms Functional Data Structures with PHP

Backtracking to solve puzzle problem

Backtracking is a recursive algorithm strategy where we backtrack when a result is not found and continue search for solution in other possible ways. Backtracking is a popular way to solve many famous problems, especially chess, Sudoku, crosswords, and so on. Since recursion is the key component of backtracking, we need to ensure that our problem can be divided into sub problems, and we apply recursion into those sub problems. In this section, we will solve one of the most popular games, Sudoku, using backtracking.

In Sudoku, we have a partially filled box with nice boxes of size 3X3. The rule of the game is to place a number 1 to 9 in each cell, where the same number cannot exist in the same row or column. So, in the 9X9 cell, each number 1 to 9 will be present only once for each row and each column:

...

7

3

8

2

5

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}