Sai Subramanyam

Sai Subramanyam

67 Articles Published

Articles by Sai Subramanyam

Page 2 of 7

Loop through a hash table using Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 2K+ Views

Hash tables (also called hash maps) store key-value pairs and provide efficient lookup. To iterate through all entries, we need to traverse each chain in the underlying storage container since hash tables typically use chaining to handle collisions. Creating a forEach Method The forEach method loops over all key-value pairs in the hash table and executes a callback function for each pair. We iterate through each chain in the container and process every key-value pair. forEach(callback) { // For each chain in the hash table this.container.forEach(elem => { ...

Read More

The HashTable Class in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 221 Views

A HashTable (Hash Map) is a data structure that stores key-value pairs using a hash function to compute array indices. This implementation uses chaining to handle collisions, where multiple values can be stored at the same index using arrays. Complete HashTable Implementation class HashTable { constructor() { this.container = []; // Populate the container with empty arrays // which can be used to add more elements in // cases of collisions for (let i = ...

Read More

Binary Tree in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 321 Views

Binary Tree is a special data structure used for data storage purposes. A binary tree has a special condition that each node can have a maximum of two children. A binary tree has the benefits of both an ordered array and a linked list as search is as quick as in a sorted array and insertion or deletion operation are as fast as in the linked list. Here is an illustration of a binary tree with some terms that we've discussed below: A Root ...

Read More

How to offset an outline and draw it beyond the border edge with JavaScript?

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 273 Views

To offset an outline in JavaScript, use the outlineOffset property. This CSS property allows you to draw the outline beyond the border edge, creating space between the element's border and its outline. Syntax element.style.outlineOffset = "value"; The value can be specified in pixels (px), ems (em), or other CSS length units. Positive values move the outline away from the border, while negative values move it inward. Example #box { ...

Read More

Node in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 276 Views

In JavaScript tree data structures, a node is the fundamental building block that contains data and references to other connected nodes. For binary trees, each node has three essential properties: the data it stores and references to its left and right child nodes. Node Structure A typical tree node contains the following components: data − Stores the actual value or information in the node left − Reference to the left child node right − Reference to the right child node Creating a Node Class ...

Read More

Inserting a key into a tree in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 771 Views

In a Binary Search Tree (BST), inserting a new key follows a simple rule: smaller values go to the left subtree, and larger values go to the right subtree. The first insertion creates the root node, while subsequent insertions traverse the tree to find the correct position. How BST Insertion Works The insertion process starts at the root and compares the new value with each node. If the value is smaller, we move left; if larger, we move right. When we reach a null position (leaf node), we insert the new node there. Binary ...

Read More

AVL Rotations in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 504 Views

To balance itself, an AVL tree may perform the following four kinds of rotations: Left rotation Right rotation Left-Right rotation Right-Left rotation The 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 tree, let's understand them one by one. Left Rotation If a tree becomes unbalanced when a node is inserted into the right subtree of ...

Read More

What will happen when [50,100] is converted to Number in JavaScript?

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 179 Views

Use the Number() method in JavaScript to convert to Number. When an array like [50, 100] is converted to Number in JavaScript, the result might be surprising. What Happens with Array to Number Conversion? When Number() is called on an array, JavaScript first converts the array to a string, then attempts to convert that string to a number. For arrays with multiple elements, this results in NaN (Not a Number). Example Convert [50, 100] to Number ...

Read More

AVL Tree class in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 873 Views

An AVL Tree is a self-balancing binary search tree where the heights of left and right subtrees differ by at most one. This implementation provides insertion with automatic rebalancing through rotations. 10 5 15 3 7 Balanced AVL Tree (height difference ...

Read More

Graph Traversals in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 289 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. In JavaScript, the two most common graph traversal algorithms are Breadth-First Search (BFS) and Depth-First Search (DFS). Both algorithms systematically explore graph nodes but use different strategies. Graph Representation First, let's create a simple graph using an adjacency list representation: class Graph { constructor() { this.adjacencyList = {}; ...

Read More
Showing 11–20 of 67 articles
« Prev 1 2 3 4 5 7 Next »
Advertisements