Not Yet Answered # Binary Search Tree

verruckt24 438

0

Yes, the information on this URL describes the BST in detail. To add further lets explain what the BST *is* actually. The BST or a Tree in general in the context of Data Structures, is a collection of Nodes. Where a Node has the following properties:

- Each Node has a data element (sometimes also called as the key)

- Each Node has a left Node which can also be called as a left child or the left sub tree.

- Each Node has a right Node aka right child or the right sub tree.

From this information, following the OO design principles you can create a Node class as follows:

```
class Node{
int data;
Node leftNode; // left sub tree is itself a Node very much like this.
Node rightNode; // right sub tree is also a Node very much like this.
}
```

Addition in a BST is the process of finding the right place for an element/key. According to the definition of a BST - all keys in the left sub tree of a node should be smaller than that at the current node and all keys in the right sub tree should be larger than (or equal) to the key in the current node. When you are about to add an element in the tree, you make comparisons that help you decide the correct position of the key in the tree. This process should be carried out something like this:

- Starting with the root of the tree, compare the key to be added, lets say K, to the key in each node, we call the node that we currently are in as the current node.

- If K < key at the current node, move to left else move to right.

- Repeat the above step as long as you keep encountering nodes, when there are no more nodes, say for e.g. that you are about to move to the left but you find that there is no left sub-tree for the current node, you know you have reached the correct position for the key K.

I guess this much is fine for you to get started.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

```
from turtle import *
import random
def allTriMedian (w=300):
speed (0)
vertices = []
point = turtle.Point(x,y)
for i in range (3):
x = random.randint(0,300)
y = random.randint(0,300)
vertices.append(trutle.Point(x,y))
point = turtle.Point(x,y)
triangle = turtle.Polygon(vertices)
a = triangle.side()
b = triangle.side()
c = triangle.side()
m1 = tirangle.median
m2 = triangle.median ...
```

Hi!

I have two tables, I will call them first-half and second-half (of the year)

```
Table: first
id jan feb mar apr
-----------------------
2 80 90 70 60
3 50 40 60 30
Table: second
id jan feb mar apr
-----------------------
2 50 70 60 90
3 80 60 50 ...
```

I'm trying to figure out how do i print a distinct enum value by using a conditional statement in my construction of array.

I have a enum declaration

`enum Animal {Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Sheep, Monkey, Rooster, Dog, Pig};`

And i construct my array using a voidptr ...