Karthikeya Boyini has Published 2193 Articles

Binary Search Tree in Javascript

karthikeya Boyini

karthikeya Boyini

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

436 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

525 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

589 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

203 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

611 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

Remove elements from a linked list using Javascript

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

Removing an element is very easy in a linked list. We just need to get rid of the node we want to remove, ie, lose its reference. There are 3 cases we need to consider −Removing an element from head: In this case, we can simply assign head = head.next. ... Read More

Inserting Elements to a doubly linked list using Javascript

karthikeya Boyini

karthikeya Boyini

Updated on 15-Jun-2020 09:24:31

517 Views

We need to create a function insert(data, position) that inserts data at given position in the linked list. We'll perform the following steps −Create a new NodeCheck if the list is empty. If it then adds the node to head and tail and return.If not, then we'll iterate to the ... Read More

The Doubly Linked List class in Javascript

karthikeya Boyini

karthikeya Boyini

Updated on 15-Jun-2020 09:19:51

485 Views

Here is the complete implementation of the DoublyLinkedList Class −Exampleclass DoublyLinkedList {    constructor() {       this.head = null;       this.tail = null;       this.length = 0;    }    insert(data, position = this.length) {       let node = new this.Node(data);   ... Read More

Singly Linked List as Circular in Javascript

karthikeya Boyini

karthikeya Boyini

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

281 Views

In the singly linked list, the next pointer of the last node points to the first node.

Remove elements from a PriorityQueue using Javascript

karthikeya Boyini

karthikeya Boyini

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

326 Views

Dequeuing elements from a PriorityQueue means removing the element of the highest priority. We are storing the elements with the highest priority at the end of the array, we can simply pop it to dequeue it.Hence, we can implement the dequeue function as follows − Exampledequeue() {    // Check if ... Read More

Advertisements