Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Binary search tree
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Successor and predecessor==== For certain operations, given a node <math>\text{x}</math>, finding the successor or predecessor of <math>\text{x}</math> is crucial. Assuming all the keys of a BST are distinct, the successor of a node <math>\text{x}</math> in a BST is the node with the smallest key greater than <math>\text{x}</math>'s key. On the other hand, the predecessor of a node <math>\text{x}</math> in a BST is the node with the largest key smaller than <math>\text{x}</math>'s key. The following pseudocode finds the successor and predecessor of a node <math>\text{x}</math> in a BST.<ref>{{cite web|url=https://ranger.uta.edu/~huang/teaching/CSE5311/CSE5311_Lecture10.pdf|archive-url=https://web.archive.org/web/20210413045057/http://ranger.uta.edu/~huang/teaching/CSE5311/CSE5311_Lecture10.pdf|archive-date=13 April 2021|page=12|publisher=[[University of Texas at Arlington]]|access-date=17 May 2021|url-status=live|title=Design and Analysis of Algorithms|author=Junzhou Huang}}</ref><ref>{{cite web |author=Ray |first=Ray |title=Binary Search Tree |url=https://cs.lmu.edu/~ray/notes/binarysearchtrees/ |access-date=17 May 2022 |publisher=[[Loyola Marymount University]], Department of Computer Science}}</ref><ref name="algo_cormen" />{{rp|292β293}} {| |- style="vertical-align:top" | BST-Successor(x) '''if''' x.right ≠ NIL '''then''' '''return''' BST-Minimum(x.right) '''end if''' y := x.parent '''while''' y ≠ NIL '''and''' x = y.right '''do''' x := y y := y.parent '''repeat''' '''return''' y | BST-Predecessor(x) '''if''' x.left ≠ NIL '''then''' '''return''' BST-Maximum(x.left) '''end if''' y := x.parent '''while''' y ≠ NIL '''and''' x = y.left '''do''' x := y y := y.parent '''repeat''' '''return''' y |} Operations such as finding a node in a BST whose key is the maximum or minimum are critical in certain operations, such as determining the successor and predecessor of nodes. Following is the pseudocode for the operations.<ref name="algo_cormen" />{{rp|291β292}} {| |- style="vertical-align:top" | BST-Maximum(x) '''while''' x.right ≠ NIL '''do''' x := x.right '''repeat''' '''return''' x | BST-Minimum(x) '''while''' x.left ≠ NIL '''do''' x := x.left '''repeat''' '''return''' x |}
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Binary search tree
(section)
Add topic