Linked List data structures explained

Linked List is a data structure used for storing collection of data where successive elements are connected through pointers and the size of linked list can grow or shrink dynamically.
Linked List data structure is a type of Linear data structures.
In short, Linked list can be thought as similar to array in which traversal can happen through pointers instead of indexes.

Let’s have a look into some graphical examples of Linked List.

(more…)
Linked List data structures explained Read More

Boundary Traversal Of A Binary Tree

A tree is a data structure similar to Linked list in which each node points to multiple nodes instead of simply pointing to the next node. A tree is called Binary tree if each node in a tree has maximum of two nodes.

Boundary traversal of a binary tree, traverses through all the boundary nodes which includes

  • The left boundary of a binary tree
  • All the leaves of the binary tree
  • The right boundary of a binary tree

Before going ahead have a look into Binary Tree basicsBinary Tree Traversal and Binary Tree implementation.

(more…)
Boundary Traversal Of A Binary Tree Read More

Program To Find the Lowest Common Ancestor In Binary Tree

A tree is a data structure similar to Linked list in which each node points to multiple nodes instead of simply pointing to the next node. A tree is called Binary tree if each node in a tree has maximum of two nodes.
The lowest common ancestor of any two nodes X and Y in a binary tree is the lowest node in tree that has both X and Y node as successor.
Before going ahead have a look into Binary Tree basicsBinary Tree Traversal and Binary Tree implementation.

(more…)
Program To Find the Lowest Common Ancestor In Binary Tree Read More

Program to Convert Binary Tree to Sum Tree

A tree is a data structure similar to Linked list in which each node points to multiple nodes instead of simply pointing to the next node. A tree is called Binary tree if each node in a tree has maximum of two nodes.
An empty tree is also a Binary tree. We can call the two children of each node as Left and Right child of a node. The node of the tree which has no parent is called the Root of the tree. Perhaps Binary tree is the most used tree data structure in the programming world. Before going ahead have a look into Binary Tree basicsBinary Tree Traversal and Binary Tree implementation.

(more…)
Program to Convert Binary Tree to Sum Tree Read More

Program To Check if a Binary Tree is a Sum Tree

A tree is a data structure similar to Linked list in which each node points to multiple nodes instead of simply pointing to the next node. A tree is called Binary tree if each node in a tree has maximum of two nodes.
An empty tree is also a Binary tree. We can call the two children of each node as Left and Right child of a node. The node of the tree which has no parent is called the Root of the tree. Perhaps Binary tree is the most used tree data structure in the programming world. Before going ahead have a look into Binary Tree basicsBinary Tree Traversal and Binary Tree implementation.

(more…)
Program To Check if a Binary Tree is a Sum Tree Read More

Program to Check Whether a Binary Tree is Symmetric

A tree is a data structure similar to Linked list in which each node points to multiple nodes instead of simply pointing to the next node. A tree is called Binary tree if each node in a tree has maximum of two nodes.
An empty tree is also a Binary tree. We can call the two children of each node as Left and Right child of a node. The node of the tree which has no parent is called the Root of the tree. Perhaps Binary tree is the most used tree data structure in the programming world. Before going ahead have a look into Binary Tree basicsBinary Tree Traversal and Binary Tree implementation.

(more…)
Program to Check Whether a Binary Tree is Symmetric Read More

Autocomplete Feature Using Trie Explained With Simple Example

Autocomplete is a feature to suggest possible words to a partially typed string. This feature is widely used by most applications such as – Google, Bing, IDEs etc. To support auto complete feature, Trie data structure is used to maintain a dictionary and based on those suggestions can be made.

A trie is a N-ary tree data structure for storing strings in order to support fast string search. Tries can insert or search the string in O(L) time where L is length of string. Trie is mainly used in cases where dictionary kind of data structure needs to be maintained.

Assuming the dictionary contains all the strings were made of all small alphabets “a” to “z” then each node of the trie will have 26 pointers, one for each character.

(more…)
Autocomplete Feature Using Trie Explained With Simple Example Read More

Trie Data Structure Basics and Implementation Explained With Simple Example

A trie is a N-ary tree data structure for storing strings in order to support fast string search. Tries can insert or search the string in O(L) time where L is length of string. Trie is mainly used in cases where dictionary kind of data structure needs to be maintained.

Assuming the dictionary contains all the strings were made of all small alphabets “a” to “z” then each node of the trie will have 26 pointers, one for each character. Let’s have a look into simple trie data structure definition.

#define LETTER_LENGTH 26
class Trie
{
    public:
        Trie* m_ptr[LETTER_LENGTH];
        bool is_word_complete;
        Trie ();
};
Trie::Trie ()
{
    for (int i = 0; i < LETTER_LENGTH; i++)
    {
        m_ptr[i] = NULL;
    }
}
(more…)
Trie Data Structure Basics and Implementation Explained With Simple Example Read More

Count Distinct Elements in Every Window of Size K in a Subarray

Given an array of size “n” and an integer “k” where k < n. Write a program to return the count of distinct elements in every subarray of size “k”.
For eg:
      int arr[] = {1,2,3,4,1,3,4} , window size k = 4
      For 1st window of size 4 (index 0-3) – subarray = {1,2,3,4}, distinct element = 4
      For 2nd window of size 4 (index 1-4) – subarray = {2,3,4,1}, distinct element = 4
      For 3rd window of size 4 (index 2-5) – subarray = {3,4,1,3}, distinct element = 3
      For 4th window of size 4 (index 3-6) – subarray = {4,1,3,4}, distinct element = 3

(more…)
Count Distinct Elements in Every Window of Size K in a Subarray Read More