Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
C++ Data Structures and Algorithm Design Principles

You're reading from   C++ Data Structures and Algorithm Design Principles Leverage the power of modern C++ to build robust and scalable applications

Arrow left icon
Product type Paperback
Published in Oct 2019
Publisher
ISBN-13 9781838828844
Length 626 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (4):
Arrow left icon
Anil Achary Anil Achary
Author Profile Icon Anil Achary
Anil Achary
John Carey John Carey
Author Profile Icon John Carey
John Carey
Payas Rajan Payas Rajan
Author Profile Icon Payas Rajan
Payas Rajan
Shreyans Doshi Shreyans Doshi
Author Profile Icon Shreyans Doshi
Shreyans Doshi
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

About the Book 1. Lists, Stacks, and Queues FREE CHAPTER 2. Trees, Heaps, and Graphs 3. Hash Tables and Bloom Filters 4. Divide and Conquer 5. Greedy Algorithms 6. Graph Algorithms I 7. Graph Algorithms II 8. Dynamic Programming I 9. Dynamic Programming II 1. Appendix

What Is Dynamic Programming?

The best way to answer this question is by example. To illustrate the purpose of dynamic programming, let's consider the Fibonacci sequence:

{ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … }

By observing the preceding sequence, we can see that, beginning with the third element, each term is equal to the sum of the two preceding terms. This can be simply expressed with the following formula:

F(0) = 0

F(1) = 1

…

F(n) = F(n-1) + F(n-2)

As we can clearly see, the terms of this sequence have a recursive relationship – the current term, F(n), is based on the results of previous terms, F(n-1) and F(n-2), and thus the preceding equation, that is, F(n) = F(n-1) + F(n-2), is described as the recurrence relation of the sequence. The initial terms, F(0) and F(1), are described as the base cases, or the points in which a solution is produced without the need to recurse further. These operations are shown in the following figure:

Figure 8.1: Computing the nth term in the Fibonacci sequence
Figure 8.1:...
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 $19.99/month. Cancel anytime
Banner background image