Karthikeya Boyini has Published 2383 Articles

Creating a hash table using Javascript

karthikeya Boyini

karthikeya Boyini

Updated on 15-Jun-2020 11:09:18

301 Views

Let us set up a simple class that we'll use to define all these methods on. We'll create a container object to store the hash table and create a display function to display the table. Note that for collision resolution, we'll use chaining.The display function takes each entry (hashed value) ... Read More

Add elements to a hash table using Javascript

karthikeya Boyini

karthikeya Boyini

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

754 Views

When adding elements to a hash table the most crucial part is collision resolution. We're going to use chaining for the same. There are other algorithms you can read about here: https://en.wikipedia.org/wiki/Hash_table#Collision_resolutionNow let's look at the implementation. We'll be creating a hash function that'll work on integers only to keep ... Read More

Remove elements from Javascript Hash Table

karthikeya Boyini

karthikeya Boyini

Updated on 15-Jun-2020 11:04:30

943 Views

To remove elements, we simply need to find them and remove them using a simple splice function call that removes elements in place from an array.Let us look at the implementation of the same − Exampleremove(key) {    let hashCode = this.hash(key);    for (let i = 0; i < ... Read More

Joining two hash tables in Javascript

karthikeya Boyini

karthikeya Boyini

Updated on 15-Jun-2020 11:00:35

393 Views

Sometimes we need to combine containers together using a join function and get a new container. We'll write a static join method that takes in 2 HashTables and creates a new HashTable with all the values. For the sake of simplicity, we'll let the values from the second one override ... Read More

Tree Data Structure in Javascript

karthikeya Boyini

karthikeya Boyini

Updated on 15-Jun-2020 10:55:39

412 Views

The tree represents hierarchical structures like organization hierarchy charts, file systems, etc. To put it more formally, a tree can be defined recursively (locally) as a collection of nodes (starting at a root node), where each node is a data structure consisting of a value, together with a list of ... Read More

Binary Search Tree in Javascript

karthikeya Boyini

karthikeya Boyini

Updated on 15-Jun-2020 10:54:03

304 Views

A Binary Search tree exhibits a special behavior. A node's left child must have a value less than its parent's value and the node's right child must have a value greater than its parent value.We'll mostly focus on such trees in this section on trees.Operations on Binary Search TreesWe'll define ... Read More

Set Data Structure in Javascript

karthikeya Boyini

karthikeya Boyini

Updated on 15-Jun-2020 09:52:17

398 Views

A set is an abstract data type that can store certain values, without any particular order and no repeated values. It is a computer implementation of the mathematical concept of a finite set. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests ... Read More

Creating a Set using Javascript

karthikeya Boyini

karthikeya Boyini

Updated on 15-Jun-2020 09:48:57

415 Views

Let's create a MySet class so that it doesn't hide the actual set class in JS. We'll create a container object that'll keep track of all our values that we add to the set. We'll also create a display function that prints the set for us. Exampleclass MySet {    constructor() ... Read More

Remove elements from a Set using Javascript

karthikeya Boyini

karthikeya Boyini

Updated on 15-Jun-2020 09:42:29

106 Views

The delete method checks if a value already exists in the set, if it does, then it removes that value from the set. We can implement it as follows &minusl Exampledelete(val) {    if (this.has(val)) {       delete this.container[val];       return true;    }    return false; ... Read More

Loop through a Set using Javascript

karthikeya Boyini

karthikeya Boyini

Updated on 15-Jun-2020 09:37:52

470 Views

In the set that we implemented, we can create a for each function in our class and accept a callback that we can call on every element. Let's see how we can implement such a function − ExampleforEach(callback) {    for (let prop in this.container) {       callback(prop);   ... Read More

Advertisements