The category contains posts related to the Trees data structure. This category is a child category in the Data Structures category,

Build Balanced Binary Search Tree from Array

Introduction This post describes the algorithm to build binary search tree from array of sorted elements. However, this technique can be used to build balanced binary search tree from array. A balanced binary tree is a binary tree which has minimum height. To know more about various aspects of a binary search tree, please visit my previous posts. What does balanced means? In this post as we are trying to build a BST, we will assume the input to be a sorted array. In case, we are just building a binary tree, we can take any array as an input. Let me explain the process with the help of a ...
Read More

Splitting and Merging B Tree Nodes

This post is to be read in conjunction with another post Introduction to B Trees. Here we learn that in certain operations the B Tree properties might get disturbed and it will need a fix. Splitting and Merging B Tree Nodes are the only operations which can re-establish the properties of the B Tree. How does a B Tree get unbalanced? The tree is not just to read and search data. There are operations which update the tree either by deleting a key, inserting a new key or just updating the values stored against the key. The Insert and Delete operations tend to modify the structure of the tree...
Read More

Introduction to B Trees

This post is just an introduction to B Trees and here we will discuss one of the complicated data structures, B Trees. I would advice the reader to get familiar with the Tree data structures, and Balanced Trees. For e.g. : Binary Search Trees, AVL Trees, Red Black Trees and 2-3-4 Trees. If you are not familiar with any/few of the above mentioned data structures, then please do not worry, I will try to explain everything here from scratch and hopefully you might not need any external support. But in case you are trying to learn the above topics, please look into the Additional Read section a...
Read More

Balanced Search Trees – AVL Tree

Introduction When we talk about balanced search trees, we specifically are talking about two things. A search trees. A height balanced tree. Here in this post we will consider a Binary Search Tree and will try to equip with features to self balance itself upon modifications. Before starting up with the logic and code part we need to understand the motive behind this kind of data structure and more precisely we need to understand the need of such a complex scenario. Apart from that we also need to understand what it means to be termed as balanced. What does balancing means? We sa...
Read More

Shortest path in Binary Search Tree

Introduction Another interview question for the most interesting data structure called BST (Binary Search Tree). To know more about BSTs check my previous post. Problem Statement : Given a Binary Search Tree, keyed on positive integers. The task is to find the Shortest path in Binary Search Tree which adds up to the number K. If no such path exists, return a message accordingly. Understanding the problem A node in a binary search tree always has a higher key at its right child compared to its left child. There are many path running from the roots to the leaves. When we add up the key val...
Read More