Data structure algorithm
presented by
NIBIYA.G
I-MSC(INFORMATION TECHNOLOGY)
NADAR SARASWATHI COLLEGE OF ARTS
AND SCIENCE
VADAPUTHUPATTI, THENI – 625531
DYNAMIC PROGRAMMING
 Optimal binary search Tree
 string editing
 0/1 knapsack problem
OPTIMAL BINARY SEARCH
TREE
 A binary search tree is one of the most important data
structures which contain a set of element with the operation
of searching, insertion, and deletion.
 An optimal binary search tree is the one for which the
average number of comparisons in a search is the smallest
possible, if the probability of searching each element is given.
 Consider four keys A,B,C, and D to be searched for with
probabilities 0.1, 0.2, 0.4 and 0.3 respectively.
 The below figure depicts two out of 14 possible binary search
trees containing these keys.
 The average number of comparisons in a successful search in
the first of these tree
0.1, 1+0.2, 2+0.4, 3+0.3, 4 = 2.9.
and for the second one it is
0.1, 2+0.2, 1+0.4, 2+0.3, 3 = 2.1.
 Neither of these two trees is, in fact, optimal.
 The total number of binary search trees with n keys is equal
to the nth catalan number.
 Let a1,………, aa be distinct keys ordered from smallest to the
largest and let p1,…….pa be the probabilities of searching for
them.
 Let C( I , j ) be the smallest average number of comparisons made
in a successful search in a binary search tree T1j.
 Suppose the root contains key ak, the left subtree Tik-1 contains keys
ai,…….ak-1 optimally arranged, and the right sutree tjk+1 contain keys
ak+1….aj also optimally arranged
 The recurrence relation
 Here C(i,i-1) = 0 for 1
Figure 5.12 two possible binary search tree
Figure 5.13 binary search tree of figure 5.12 with external
nodes added
Optimal binary search tree(*)
Optimal binary search tree(*)
Figure 5.16 computation of c(0,4), w(0,4), and
r(0,4)
string editing
string editing
string editing FORMULA
string editing
(example)
0/1 knapsack problem
0/1 knapsack problem
0/1 knapsack problem
(recursive formula sub-program)
0/1 knapsack algorithm
Example -1
Example -2
Example -3
Example -4
Example -5
Example -6
Example -7
Example -8
Example -9
Example -10
Example -11
Example -12
Example -13
Example -14
Example -15
Example -16
Example -17
Example -18
Data Structure Algorithm

Data Structure Algorithm