Picture above is Figure 188a predecessorx k x points to a no

(Picture above is Figure 18.8(a))

predecessor(x, k): x points to a node containing a key k. The function returns the predecessor key of k; it returns Nil if the predecessor of k does not exist in the tree. For example, in the B-tree in Figure 18.8 (a), the predecessor of P is O and the predecessor of Q is P.

Note that the predecessor of k is interpreted as the key immediately preceding k in the implicit ordering in the tree. So the predecessor of k may be equal to k if the tree has multiple occurrences of k. In case the predecessor of k is interpreted as the largest key less than k, the above algorithm needs to be modified to skip the multiple occurrences of k, please resolve this

Solution

predecessor(x, k) { let k = x.keyi; if ( !x.leaf ){ // x is not a leaf s: let temp= largestKey(x.ci); // return the largest key in the subtree pointed to by ci if(temp<=x){ x=x.ci; goto s; } else return temp; else // x is a leaf { if ( i 2 ) return x.keyi1 else predecessorInParent(x, x.parent); // attempt to find the predecessor in the parent of x } } Here the modified code in the if block will take care if the predecessor is less than or equal then it will call back the function by moving to right...
(Picture above is Figure 18.8(a)) predecessor(x, k): x points to a node containing a key k. The function returns the predecessor key of k; it returns Nil if the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site