What does this pseudo code mean? - Binary Search Tree Successor Function

if right[x] != NIL then return TREE-MINIMUM(right[x]) y<-p[x] while y!= NIL and x = right[y] do x<-y y<-p[y] return y 

I know that "if right [x]! = NIL, then return tree-min" and I translated it into:

 if(p->RChild) return fMinValue(p->RChild);//returns the min value of the sub-tree starting at the right child node of p 

Otherwise, I have problems with understanding.

0
binary-search-tree
source share
2 answers

<- most likely is an assignment operator. p I would suggest that this is a parent. What else confuses you?

+2
source share

Here p[] almost certainly means "parent node of". You are working on node x , so p[x] means "the parent of the current node" (just like right[x] means "the right child of the current node").

The designation <- is the designation. Like = in c-like languages.

The second part of the algorithm presented here goes up the tree, looking for the first time that you went to the left link instead of the right one. But I'm not sure that I would describe this as a successor function.

+2
source share

All Articles