Web Development Articles

Page 402 of 801

Joining two hash tables in Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 676 Views

Sometimes we need to combine hash tables together using a join function to create a new merged hash table. We'll write a static join method that takes 2 HashTables and creates a new HashTable with all the values. For simplicity, values from the second hash table will override values from the first one if there are duplicate keys. Syntax static join(table1, table2) { // Implementation logic return newHashTable; } Implementation Here's the complete implementation of the join method: class HashTable { ...

Read More

The HashTable Class in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 210 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

Tree Data Structure in Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 633 Views

The tree data structure represents hierarchical relationships like organization charts, file systems, and DOM elements. A tree consists of nodes connected in a parent-child relationship, where each node has a value and references to its children, with no duplicate references. Tree Terminology Understanding key tree terms is essential: Root: The top node with no parent Parent: A node that has children Child: A node connected to a parent above it Leaf: A node with no children Height: Maximum depth from root to any leaf Depth: Number of edges from root to a specific node ...

Read More

Node in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 270 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

Creating a BinaryTree using Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 327 Views

A Binary Search Tree (BST) is a hierarchical data structure where each node has at most two children. Let's learn how to create and represent a binary search tree in JavaScript by building a complete BST class with essential operations. Basic Structure We'll start by creating the BinarySearchTree class and defining a Node class for individual tree elements. class BinarySearchTree { constructor() { // Initialize a root element to null this.root = null; ...

Read More

Inserting a key into a tree in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 759 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

Searching for values in an Javascript Binary Search Tree

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 586 Views

We're going to use the property of a BST to look up elements in it. In a Binary Search Tree, values smaller than the current node are in the left subtree, and values larger are in the right subtree, making search operations efficient. Iterative Search Implementation The iterative approach uses a loop to traverse the tree: searchIter(data) { let currNode = this.root; while (currNode !== null) { if (currNode.data === data) { ...

Read More

In-order traversal in Javascript Tree

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

The tree is a data structure that is comprised of nodes and edges. These entities are interconnected to each other to form a tree structure. Traversing a data structure means visiting each and every node in that structure and bringing out a sequence of values from that. There are three types of traversals namely, in-order (L→ Root→R ), pre-order(Root→L→R) and, post-order(L→ R → Root) In-order Traversal In the In-order Traversal, the left subtree is visited first, followed by the Root node and finally the right subtree. A binary tree will provide sorted key values in ascending order ...

Read More

Calculating the balance factor in a Javascript AVL Tree

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 859 Views

AVL tree checks the height of the left and the right sub-trees and assures that the difference is not more than 1. This difference is called the Balance Factor. For example, in the following trees, the first tree is balanced and the next two trees are not balanced: Balanced (BF ≤ 1) B A C Unbalanced (BF = 2) ...

Read More

Inserting a node in a Javascript AVL Tree

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 310 Views

We can learn how to insert a node in an AVL Tree. Insertions in AVL trees follow the same process as BST, but we need to perform one extra step called balance tree during insert whenever we move down the tree. This requires calculating the balance factor and applying appropriate rotation methods based on the tree configuration. The balance factor determines which type of rotation is needed to maintain the AVL property. Understanding AVL Tree Balance An AVL tree maintains balance by ensuring that for every node, the heights of its left and right subtrees differ by ...

Read More
Showing 4011–4020 of 8,010 articles
« Prev 1 400 401 402 403 404 801 Next »
Advertisements