Sai Subramanyam has Published 102 Articles

Depth-first search traversal in Javascript

Sai Subramanyam

Sai Subramanyam

Updated on 15-Jun-2020 12:24:59

4K+ Views

DFS visits the child vertices before visiting the sibling vertices; that is, it traverses the depth of any particular path before exploring its breadth. A stack (often the program's call stack via recursion) is generally used when implementing the algorithm.Following is how a DFS works −Visit the adjacent unvisited vertex. ... Read More

Binary Search Tree Class in Javascript

Sai Subramanyam

Sai Subramanyam

Updated on 15-Jun-2020 11:59:47

217 Views

Here is the complete implementation of the BinarySearchTree Class −Exampleclass BinarySearchTree {    constructor() {       // Initialize a root element to null.       this.root = null;    }    insertIter(data) {       let node = new this.Node(data);    // Check if the ... Read More

AVL Rotations in Javascript

Sai Subramanyam

Sai Subramanyam

Updated on 15-Jun-2020 11:52:10

224 Views

To balance itself, an AVL tree may perform the following four kinds of rotations −Left rotationRight rotationLeft-Right rotationRight-Left rotationThe first two rotations are single rotations and the next two rotations are double rotations. To have an unbalanced tree, we at least need a tree of height 2. With this simple ... Read More

AVL Tree class in Javascript

Sai Subramanyam

Sai Subramanyam

Updated on 15-Jun-2020 11:50:25

570 Views

Here is the complete implementation of the AVL Tree Class −Exampleclass AVLTree {    constructor() {       // Initialize a root element to null.       this.root = null;    }    getBalanceFactor(root) {       return this.getHeight(root.left) - this.getHeight(root.right);    }    getHeight(root) ... Read More

Graph Data Structure in Javascript

Sai Subramanyam

Sai Subramanyam

Updated on 15-Jun-2020 11:46:10

1K+ Views

A graph is a pictorial representation of a set of objects where some pairs of objects are connected by links. The interconnected objects are represented by points termed as vertices, and the links that connect the vertices are called edges.Formally, a graph is a pair of sets (V, E), where ... Read More

Graph Traversals in Javascript

Sai Subramanyam

Sai Subramanyam

Updated on 15-Jun-2020 11:34:08

149 Views

Graph traversal (also known as graph search) refers to the process of visiting (checking and/or updating) each vertex in a graph. Such traversals are classified by the order in which the vertices are visited.

Node in Javascript

Sai Subramanyam

Sai Subramanyam

Updated on 15-Jun-2020 11:31:41

134 Views

Each element in a tree is a node. We need to define a node before we proceed to define a binary tree as a tree consists of nodes. We'll create a very simple node definition that has 3 properties, namely: left, right and data.left − This holds the reference to ... Read More

Inserting a key into a tree in Javascript

Sai Subramanyam

Sai Subramanyam

Updated on 15-Jun-2020 11:29:40

515 Views

The first insertion in a newly created binary tree creates a node at the root. Further insertions will be inserted according to the binary search tree property of left children being smaller than parent and right ones being greater than parents.Let us look at how we can implement this algorithm ... Read More

Searching for minimum and maximum values in an Javascript Binary Search Tree

Sai Subramanyam

Sai Subramanyam

Updated on 15-Jun-2020 11:21:39

253 Views

In a Binary Search Tree, if we look at the property that the left child is always smaller than the parent, we will find that if we keep iterating towards the left child till we reach a node with no left child, we'll basically find the smallest element in the ... Read More

Search Element in an Javascript Hash Table

Sai Subramanyam

Sai Subramanyam

Updated on 15-Jun-2020 11:06:23

220 Views

We've kind of already implemented this in our put method. Let us look at it again in isolation.Exampleget(key) {    let hashCode = hash(key);    for(let i = 0; i < this.container[hashCode].length; i ++) {       // Find the element in the chain       if(this.container[hashCode][i].key === ... Read More

Advertisements