(a) Construct a 2 - 3 tree for the list f,l,o,w,c,h,a,r,t,i,n,g.
Use the alphabetical order of the letters to compare them and
insert them successively starting with the empty tree.
(b) Assuming that the probabilities of searching for each of the
keys (i.e., the letters) are the same, find the largest number and
the average number of key comparisons for successful searches in
this tree.
a) since it is a 2-3 tree, a node can have upto 2 elements. When the elements reach 3, we have to split it as root and child nodes. Repeat this procedure till all the elements have been listed.
b) The largest number of key comparison in the successful search will be in the search for 'c': which will be equal to 5.
The average number of key comparisons is given by the following expressions:
= (1/12)C(f)+ (1/12)C(l)+ (1/12)C(o)+ (1/12)C(w)+ (1/12)C(c)+ (1/12)C(h)+ (1/12)C(a)+ (1/12)C(r)+ (1/12)C(t)+ (1/12)C(i)+ (1/12)C(n)+ (1/12)C(g)
= (1/12) [2+1+4+4+5+3+4+2+3+4+3+4]
= (1/12) 39
=39/12.
Get Answers For Free
Most questions answered within 1 hours.