Skip to content

Getting Started#

dpvis is designed to assist students studying algorithm design gain a more thorough understanding of the counter-intuitive yet beautiful technique in theoretical computer science known as Dynamic Programming (DP).

Our library turns "standard" Python code into an interactive visualization. For example, consider a dynamic program that computes the \(n\)th Fibonnaci number. With only three lines of changes, you can convert the standard python implementation to leverage the functionalities of dpvis.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from dp import DPArray, display

arr = DPArray(n) # (1)!
arr[0] = 1
arr[1] = 1
for i in range(2, n):
    arr[i] = arr[i-1]+arr[i-2]

display(arr) # (2)!

print(arr[-1]) # prints the last value
  1. Replaces the standard Python list with a DPArray object.
  2. Shows the visualization with display(arr).
1
2
3
4
5
6
7
arr = [0] * n # initialize an length n array
arr[0] = 1
arr[1] = 1
for i in range(2, n):
    arr[i] = arr[i-1] + arr[i-2]

print(arr[-1]) # prints the last value

dpvis supports additional features that enhances the visualization. For a more comprehensive overview, see our tutorials.