Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Web Development Articles
Page 400 of 801
The Linked List Class in Javascript
Here is the complete implementation of the LinkedList class in JavaScript. This data structure allows you to store elements in a linear sequence where each element points to the next one. Complete LinkedList Implementation class LinkedList { constructor() { this.head = null; this.length = 0; } insert(data, position = this.length) { let node = new this.Node(data); if (this.head === null) ...
Read MoreLoop through a hash table using Javascript
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 MoreRemoving Elements from a Double Linked List using Javascript
Removing an element from a doubly linked list involves updating the pointers of adjacent nodes to bypass the node being removed. There are three main cases to consider based on the position of the element. Three Cases for Removal Removing from head: Update head to point to the second node and remove the previous link from the new head node. Removing from tail: Update tail to point to the second-to-last node and set its next pointer to null. Removing from middle: Connect the previous and next nodes directly, bypassing the current node by updating their pointers. ...
Read MoreThe Doubly Linked List class in Javascript
A doubly linked list is a data structure where each node contains references to both the next and previous nodes, allowing bidirectional traversal. Here's a complete implementation of a DoublyLinkedList class in JavaScript. Complete Implementation class DoublyLinkedList { constructor() { this.head = null; this.tail = null; this.length = 0; } insert(data, position = this.length) { let node = new this.Node(data); ...
Read MoreCircular linked lists in Javascript
A Circular Linked List is a variation of the standard linked list where the first element points to the last element and the last element points back to the first element, forming a circle. Both singly and doubly linked lists can be implemented as circular structures. Data: 10 Data: 20 Data: 30 ...
Read MoreSet Data Structure in Javascript
A Set is a built-in data structure in JavaScript that stores unique values of any type. Unlike arrays, Sets automatically prevent duplicate values and don't maintain insertion order for iteration purposes, making them ideal for storing collections of unique items. Creating a Set You can create a Set using the Set constructor: // Empty Set let emptySet = new Set(); console.log(emptySet); // Set with initial values let numbers = new Set([1, 2, 3, 4, 5]); console.log(numbers); // Set automatically removes duplicates let duplicates = new Set([1, 2, 2, 3, 3, 4]); console.log(duplicates); ...
Read MoreWhen should you use sets in Javascript?
Sets in JavaScript are ideal when you need to store unique elements where order doesn't matter and you primarily need to check for membership of different objects. Sets are also useful when you want to perform operations like union, intersection, and difference similar to mathematical sets. Let's explore both the built-in ES6 Set and understand when to use it effectively. When to Use Sets Use Sets when you need: Unique values only − Automatically prevents duplicates Fast membership testing − O(1) lookup time with has() Set operations − Union, intersection, difference between collections Simple deduplication ...
Read MoreRemove elements from a Set using Javascript
JavaScript Sets provide methods to remove elements efficiently. The primary method is delete(), which removes a specified value from the Set. Using the delete() Method The delete() method removes a value from the Set and returns true if the value existed, or false if it didn't. Syntax set.delete(value) Example: Removing Individual Elements const mySet = new Set([1, 2, 3, 4, 5]); console.log("Original Set:", mySet); // Remove elements console.log("Delete 3:", mySet.delete(3)); // true - existed console.log("Delete 10:", mySet.delete(10)); // false - didn't exist console.log("Updated Set:", mySet); console.log("Set size:", ...
Read MoreThe Set Class in Javascript
JavaScript's built-in Set class is a collection of unique values that allows you to store distinct elements of any type. Unlike arrays, Sets automatically prevent duplicate values and provide efficient methods for adding, removing, and checking element existence. Creating a Set You can create a Set using the new Set() constructor, optionally passing an iterable like an array: // Empty set let mySet = new Set(); // Set from array let numbersSet = new Set([1, 2, 3, 4, 4, 5]); console.log(numbersSet); // Duplicates are automatically removed let wordsSet = new Set(['hello', 'world', 'hello']); console.log(wordsSet); ...
Read MoreDictionary Data Structure in Javascript
In computer science, an associative array, map, symbol table, or dictionary is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears at most once in the collection. Note that a dictionary is also known as a map. The dictionary problem is a classic computer science problem: the task of designing a data structure that maintains a set of data during 'search', 'delete', and 'insert' operations. There are many different types of implementations of dictionaries. Hash Table implementation Tree-Based Implementation (Self-balancing ...
Read More