Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
2–3 tree
(section)
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!
===Searching=== Searching for an item in a 2–3 tree is similar to searching for an item in a [[binary search tree]]. Since the data elements in each node are ordered, a search function will be directed to the correct subtree and eventually to the correct node which contains the item. # Let {{mvar|T}} be a 2–3 tree and {{mvar|d}} be the data element we want to find. If {{mvar|T}} is empty, then {{mvar|d}} is not in {{mvar|T}} and we're done. # Let {{mvar|t}} be the root of {{mvar|T}}. # Suppose {{mvar|t}} is a leaf. #* If {{mvar|d}} is not in {{mvar|t}}, then {{mvar|d}} is not in {{mvar|T}}. Otherwise, {{mvar|d}} is in {{mvar|T}}. We need no further steps and we're done. # Suppose {{mvar|t}} is a 2-node with left child {{mvar|p}} and right child {{mvar|q}}. Let {{mvar|a}} be the data element in {{mvar|t}}. There are three cases: #* If {{mvar|d}} is equal to {{mvar|a}}, then we've found {{mvar|d}} in {{mvar|T}} and we're done. #* If <math>d < a</math>, then set {{mvar|T}} to {{mvar|p}}, which by definition is a 2–3 tree, and go back to step 2. #* If <math>d > a</math>, then set {{mvar|T}} to {{mvar|q}} and go back to step 2. # Suppose {{mvar|t}} is a 3-node with left child {{mvar|p}}, middle child {{mvar|q}}, and right child {{mvar|r}}. Let {{mvar|a}} and {{mvar|b}} be the two data elements of {{mvar|t}}, where <math>a < b</math>. There are four cases: #* If {{mvar|d}} is equal to {{mvar|a}} or {{mvar|b}}, then {{mvar|d}} is in {{mvar|T}} and we're done. #* If <math>d < a</math>, then set {{mvar|T}} to {{mvar|p}} and go back to step 2. #* If <math>a < d < b</math>, then set {{mvar|T}} to {{mvar|q}} and go back to step 2. #* If <math>d > b</math>, then set {{mvar|T}} to {{mvar|r}} and go back to step 2.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)