Knight’s Tour in C++: Warnsdorff’s Rule, Backtracking and a Tour Checker
A tested C++17 knight’s tour: Warnsdorff’s rule, backtracking for the cases it misses, and a checker that would have caught the old program’s bug.
Computer science is the intellectual foundation beneath every line of code you write. While programming teaches you how to instruct a computer, computer science teaches you why certain approaches work better than others — why one algorithm processes a million records in seconds while another takes hours, why the right data structure makes the difference between elegant and unworkable code, and why the principles of object-oriented design produce software that survives contact with the real world.
MYCPLUS has been publishing computer science tutorials and practical programming guides since 2004, building a comprehensive resource covering the core theoretical and applied topics that every serious programmer needs to understand. This Computer Science hub brings together four interconnected areas of study — Algorithms, Data Structures, Object-Oriented Programming and Programming Styles — each with its own dedicated section of in-depth tutorials, practical examples and working source code.
Tis section gives you the theoretical understanding and hands-on programming experience to write better software, solve harder problems and think more clearly about how programs work. Whether you are studying for exams, preparing for technical interviews or simply becoming a stronger programmer — start here.
Explore the four core areas covered in this section:
→ Algorithms — sorting, searching, graph traversal and optimisation
→ Data Structures — arrays, linked lists, trees, stacks and graphs
→ Object-Oriented Programming — classes, inheritance and polymorphism
→ Programming Styles — procedural, functional and declarative paradigms
Why MYCPLUS: Trusted by programmers and computer science students since 2004 — MYCPLUS covers all four core computer science disciplines in one place, with practical implementations in C, C++ and Java designed for both academic study and real-world software development.
A tested C++17 knight’s tour: Warnsdorff’s rule, backtracking for the cases it misses, and a checker that would have caught the old program’s bug.
How one call runs different code for different objects: overloading, overriding, virtual functions, generics and duck typing in C++, Java and Python.
How OOP differs from procedural code, what its four pillars mean, and the techniques that keep object-oriented code easy to change, in three languages.
Why q = p1 copies an object in C++ but shares it in Java and Python, how equality differs from identity, and how each language ends an object’s life.
How abstract classes, interfaces and Python protocols separate what code does from how, with a testable clock example in C++, Java and Python.
One base class and two subclasses written in C++, Java and Python, the five types of inheritance, and why a subclass counted six tags when three were added.
How private state and checking methods keep an object valid, why a getter can leak it, and how Python gets encapsulation from properties and convention.
One Temperature class written in C++, Java and Python, what a class stores once versus per object, and why a Python list in a class body was shared.
Why the puzzle takes 2ⁿ − 1 moves, a timed 30-disk run, five tested implementations, and an iterative solver that computes any move directly.
On 5,000 sorted values a last-element pivot makes 12.5 million comparisons instead of 67,000. Quicksort, measured — with code in five languages.
Shell Sort improves insertion sort by sorting far-apart elements first. See how it works, why gap sequences matter, and tested code in five languages.
Merge sort is stable and O(n log n) on every input. Code in five languages, measured comparisons and allocations, and four mistakes that compile.