Posts

Showing posts from May, 2020

Heap

Image
In today’s topic, I will be talking about HEAP . Just like AVL Tree and B-Tree, Heaps is also part of the Binary Search Tree. So what makes heap different? If in AVL Tree , every time we input something they will be sorted in a way that the left child will always have less value than the parent and the right child will have greater value than the parent and each node will be assigned to a height, in Heap the data will be inserted based on their arrival from the most left whether it satisfies the Binary Search Tree rules or not but we have to keep in mind that the parent node should be greater or equal to the key value of the child node for when it’s Max-Heap and less or equal to the key value of the child node for when it’s Min-Heap and each node will be assigned to a key based on their place on the tree.  To understand more about the difference, here’s an example of insertion for AVL Tree and Max-Heap. Say that the inserted data queue are, 35, 33, 42, 10, 14, 19, 27,...

AVL Tree

Image
In today’s topic, I will be talking about  AVL Tree . So what is AVL Tree? AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be greater than one for all nodes in which we usually call  balance factor , maintaining an O(log N) search time. AVL Tree was made to prevent BST worst-case scenario in which the performance is closest to linear search algorithms like in skewed BST. For example,  if the input to BST comes in a sorted (ascending or descending) manner. AVL trees has the following guarantees: 1.        Each tree has a root node (at the top). 2.        The root node has zero, one, or two child nodes. 3.        Each child node has zero, one or two child nodes, and so on. 4.        Each node has up to two children. 5.      ...