Monday, March 16, 2020

Binary tree & Hash table

Binary tree & Hash table

Binary tree

In simple term, each node have 1 branch atleast and maximum of 2 branches. The "father" is the first node, and continuing on the branch is the next node which contains either more or less value in either ascending or descending order. If ascending order, the bigger value will go to the right branch and in descending order vice versa. After each node, it will repeat for each branch to have another branch and it will keep repeating until its over.
BINARY TREE VISUALIZED
2 is the "father" and it will keep branching out

Hash table

Datas are kept in array format, every value have their own assigned index value. If we have the index value we can find the data more easily.
HASH TABLE VISUALIZED

STACK AND QUEUE

Stack

Imagine a tube, you fill it with coins. You insert 10 different coins, you want to reach the first coin you inserted but you need to remove the coins before it.

Stack follows the rule of last in first out which means the last one you inserted is the first one to go out.

It contains two functions which is:
1)To add/ Push()

2)To delete/Pop()

Stack visualized


QUEUE

The name is self explainatory, imagine a supermarket queue, then first one to reach is served first.
Same thing here queue means to lineup in sequential order.

It contains 5 function:
1) To add/Enqueue
2)To delete/Dequeue
3)To clear/Clear
4)To check if empty/IsEmpty
5)To check if full/IsFull
QUEUE VISUALIZED
steam- http://steamcommunity.com/id/michaelhxd/
 

Linked List GSLC1

Linked List II

 Doubly Linked List

Doubly linked list is basically each node is linked to the "next-node" node and the "previous-node"node which means that they are able to to back and forward until they meet NULL

Example shown below


Next topic is

Circular Single Linked List 

Imagine a train with a circle track the station is the first node, it can only go one way but it will reach the same place again after one rotation.

There is no NULL but only the next node.

Example as below


Circular Doubly Linked List

Imagine the same train as before, but this time the train can go two ways but can only change direction at the station(first node).

Example as below
@michaelhakki-ig