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)

An Overview of P versus NP

In Chapter 8, Dynamic Programming I, we demonstrated the significant gains in efficiency that dynamic programming can offer over other approaches, but it may not yet be clear how dramatic the difference can be. It is important to appreciate the extent to which the complexity of certain problems will scale as the input bounds increase because then we can understand the situations in which DP is not just preferable, but necessary.

Consider the following problem:

"Given the terms and operators of a Boolean formula, determine whether or not it evaluates to TRUE."

Take a look at the following example:

(0 OR 1)  —> TRUE

(1 AND 0) —> FALSE

(1 NOT 1) —> FALSE

(1 NOT 0) AND (0 NOT 1) —> TRUE

This problem is conceptually very simple to solve. All that is required to get the correct result is a linear evaluation of the given formula. However, imagine that, instead, the problem was stated this way:

"Given the variables...