Skip to content

Algorithmic solution of Optimal Binary Search Tree in Quadratic Time. Reduces time complexity from O(n^3) to O(n^2).

Notifications You must be signed in to change notification settings

yugantarjain/Optimal-BST-quadratic-time

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 

Repository files navigation

Optimal BST (Quadratic-Time implementation)

Special implementation of Dynamic Programming based Optimal Binary Search Tree algorithm. Uses Knuth's Theorem to achieve Quadratic Time complexity.

Time complexity chart:

This Implementation(Highy Efficient) Usual DP based implementation Naive Implementation
Theta(n^2) Theta(n^3) Theta(n^4)

Knuth's Theorem:

There are always roots of optimal subtrees such that root[i,j-1] <= root[i,j] <= root[i+1,j] for all 1<=i<j<=n.

Sample Input/Output

Input

Keys Probability = 0.15, 0.10, 0.05, 0.10, 0.20
Dummy Keys Probablity = 0.05, 0.10, 0.05, 0.05, 0.05, 0.10

Output

Output

Reference

Introduction to Algorithms
by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein

About

Algorithmic solution of Optimal Binary Search Tree in Quadratic Time. Reduces time complexity from O(n^3) to O(n^2).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages