Sai Subramanyam has Published 99 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

323 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

390 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

761 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

2K+ 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

231 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

212 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

700 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

Search Element in an Javascript Hash Table

Sai Subramanyam

Sai Subramanyam

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

391 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

Loop through a hash table using Javascript

Sai Subramanyam

Sai Subramanyam

Updated on 15-Jun-2020 11:01:51

2K+ Views

Now let us create a forEach function that'll allow us to loop over all key-value pairs and call a callback on those values. For this, we just need to loop over each chain in the container and call the callback on the key and value pairs.ExampleforEach(callback) {    // For ... Read More

Advertisements