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)

Introduction

Lookup is nothing but checking whether an element is present in a container or finding the corresponding value for a key in the container. In the student database system and the hospital management system examples that we mentioned in the previous chapters, a common operation is to fetch a particular record from the vast amount of data stored in the system. A similar problem also presents itself while getting the meaning of a word from a dictionary, checking whether a person is allowed to enter a certain facility based on a set of records (access control), and many more applications.

For most of these scenarios, just going through all the elements linearly and matching the values would be extremely time-consuming, especially considering the vast amount of records that are stored. Let's take a simple example of looking up a word in a dictionary. There are roughly 170,000 words in the English dictionary. One of the simplest ways to do this is to traverse the dictionary linearly...