Book Image

C++ Data Structures and Algorithm Design Principles

By : John Carey, Anil Achary, Shreyans Doshi, Payas Rajan
Book Image

C++ Data Structures and Algorithm Design Principles

By: John Carey, Anil Achary, Shreyans Doshi, Payas Rajan

Overview of this book

C++ is a mature multi-paradigm programming language that enables you to write high-level code with a high degree of control over the hardware. Today, significant parts of software infrastructure, including databases, browsers, multimedia frameworks, and GUI toolkits, are written in C++. This book starts by introducing C++ data structures and how to store data using linked lists, arrays, stacks, and queues. In later chapters, the book explains the basic algorithm design paradigms, such as the greedy approach and the divide-and-conquer approach, which are used to solve a large variety of computational problems. Finally, you will learn the advanced technique of dynamic programming to develop optimized implementations of several algorithms discussed in the book. By the end of this book, you will have learned how to implement standard data structures and algorithms in efficient and scalable C++ 14 code.
Table of Contents (11 chapters)

Understanding the Divide-and-Conquer Approach

At the core of the divide-and-conquer approach is a simple and intuitive idea: if you don't know how to solve a large instance of a problem, find a small part of the problem that you can solve, and then solve it. Then, iterate for more such parts, and once you have solved all the parts, combine the results into a large coherent solution to the original problem. There are three steps to solving a problem using the divide-and-conquer approach:

  1. Divide: Take the original problem and divide it into parts so that the same problem needs to be solved for each part.
  2. Conquer: Solve the problem for each part.
  3. Combine: Take the solutions for the different parts and combine them into a solution for the original problem.

In the previous section, we looked at an example of using divide and conquer to search within a sequence. At each step, binary search tries to search in only a part of the sequence, which is marked as the range. The search...