33_ Read this in other languages:_
44[ _ Português_ ] ( README.pt-BR.md )
55
6- In computer science, ** binary search trees** (BST), sometimes called
7- ordered or sorted binary trees, are a particular type of container:
8- data structures that store "items" (such as numbers, names etc.)
9- in memory. They allow fast lookup, addition and removal of
10- items, and can be used to implement either dynamic sets of
11- items, or lookup tables that allow finding an item by its key
6+ In computer science, ** binary search trees** (BST), sometimes called
7+ ordered or sorted binary trees, are a particular type of container:
8+ data structures that store "items" (such as numbers, names etc.)
9+ in memory. They allow fast lookup, addition and removal of
10+ items, and can be used to implement either dynamic sets of
11+ items, or lookup tables that allow finding an item by its key
1212(e.g., finding the phone number of a person by name).
1313
14- Binary search trees keep their keys in sorted order, so that lookup
15- and other operations can use the principle of binary search:
16- when looking for a key in a tree (or a place to insert a new key),
17- they traverse the tree from root to leaf, making comparisons to
18- keys stored in the nodes of the tree and deciding, on the basis
19- of the comparison, to continue searching in the left or right
20- subtrees. On average, this means that each comparison allows
21- the operations to skip about half of the tree, so that each
22- lookup, insertion or deletion takes time proportional to the
23- logarithm of the number of items stored in the tree. This is
24- much better than the linear time required to find items by key
25- in an (unsorted) array, but slower than the corresponding
14+ Binary search trees keep their keys in sorted order, so that lookup
15+ and other operations can use the principle of binary search:
16+ when looking for a key in a tree (or a place to insert a new key),
17+ they traverse the tree from root to leaf, making comparisons to
18+ keys stored in the nodes of the tree and deciding, on the basis
19+ of the comparison, to continue searching in the left or right
20+ subtrees. On average, this means that each comparison allows
21+ the operations to skip about half of the tree, so that each
22+ lookup, insertion or deletion takes time proportional to the
23+ logarithm of the number of items stored in the tree. This is
24+ much better than the linear time required to find items by key
25+ in an (unsorted) array, but slower than the corresponding
2626operations on hash tables.
2727
2828A binary search tree of size 9 and depth 3, with 8 at the root.
2929The leaves are not drawn.
3030
31- ![ Binary Search Tree] ( https://upload.wikimedia.org/wikipedia/commons/d/da/Binary_search_tree.svg )
31+ ![ Trie] ( ./images/binary-search-tree.jpg )
32+ 33+ * Made with [ okso.app] ( https://okso.app ) *
3234
3335## Pseudocode for Basic Operations
3436
@@ -45,7 +47,7 @@ insert(value)
4547 end if
4648end insert
4749```
48-
50+ 4951``` text
5052insertNode(current, value)
5153 Pre: current is the node to start from
@@ -84,8 +86,8 @@ contains(root, value)
8486 end if
8587end contains
8688```
87-
88-
89+ 90+ 8991### Deletion
9092
9193``` text
@@ -186,7 +188,7 @@ findNode(root, value)
186188 end if
187189end findNode
188190```
189-
191+ 190192### Find Minimum
191193
192194``` text
@@ -200,7 +202,7 @@ findMin(root)
200202 findMin(root.left)
201203end findMin
202204```
203-
205+ 204206### Find Maximum
205207
206208``` text
@@ -214,7 +216,7 @@ findMax(root)
214216 findMax(root.right)
215217end findMax
216218```
217-
219+ 218220### Traversal
219221
220222#### InOrder Traversal
@@ -244,7 +246,7 @@ preorder(root)
244246 end if
245247end preorder
246248```
247-
249+ 248250#### PostOrder Traversal
249251
250252``` text
@@ -258,7 +260,7 @@ postorder(root)
258260 end if
259261end postorder
260262```
261-
263+ 262264## Complexities
263265
264266### Time Complexity
0 commit comments