
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10483 Articles for Web Development

332 Views
An AVL tree (named after inventors Adelson-Velsky and Landis) is a self-balancing binary search tree. A self-balancing tree is a tree that performs some rotation within it's subtrees so that it can be balanced on both left and right side.These trees are particularly helpful in cases where insertions cause a tree to become heavy on one side. Balanced trees keep the lookup times close to O(log(n)) as opposed to an completely unbalanced tree that leans more towards the O(n) side.

329 Views
Here is the complete implementation of the BinarySearchTree Class −Exampleclass BinarySearchTree { constructor() { // Initialize a root element to null. this.root = null; } insertIter(data) { let node = new this.Node(data); // Check if the tree is empty if (this.root === null) { // Insert as the first element this.root = node; return; } let currNode = this.root; while (true) { if (data < currNode.data) { // Set ... Read More

3K+ Views
Tree is a nonlinear data structure which has nodes and edges; where edges act as link between two nodes and nodes hold values in it. Traversal is a procedure where it will retrieve the data in every node of the tree and print them in a specified sequential order. There are three types of tree traversals which are mentioned below − In-order traversal − In-order technique will follow the path (Left → Root → Right). Pre-order traversal − Pre-order technique will follow the path (Root → Left → Right). Post-order traversal − Post-order technique will follow the path (Left ... Read More

2K+ Views
Tree is a hierarchical data structure which includes nodes and edges to it. Edges in tree acts as links connecting two nodes. The Preorder tree traversal is a technique where the root node will be traversed first and then it will traverse the left subtree followed by the right subtree. It will represent as ROOT → LEFT → RIGHT Algorithm These are the following steps to perform preorder tree traversal − Traverse the root node. Then, traverse the left subtree. Then, traverse the right subtree. To understand the preorder traversal better, consider the following binary search tree ... Read More

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 if it is ... Read More

3K+ Views
A tree is a non-linear hierarchical data structure and it is a combination of both nodes and edges. Nodes in the tree store the values and these nodes are connected to each other with Edges. The topmost node of the tree doesn’t have any Parent node and is called a Root node. The below Binary search tree is labeled with important terms. Fundamental Terms Node − Has a pointer to another node and the ability to store a value of any data type. Root − This node is at the very top of the tree and is ... Read More

484 Views
In this article, we will explain how to find the minimum and maximum values in a binary search tree (BST), with implementation in JavaScript. A binary search tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. So the leftmost node will have the minimum value, and the rightmost node will have the maximum value. Find Minimum and Maximum in a BST Given root node of a binary search tree, ... Read More

537 Views
We're going to use the property of a BST to look up elements in it. Let us look at first an iterative implementation of search − ExamplesearchIter(data) { let currNode = this.root; while (currNode !== null) { if (currNode.data === data) { // Found the element! return true; } else if (data < currNode.data) { // Go Left as data is smaller than parent currNode = currNode.left; } else { ... Read More

707 Views
The first insertion in a newly created binary tree creates a node at the root. Further insertions will be inserted according to the binary search tree property of left children being smaller than parent and right ones being greater than parents.Let us look at how we can implement this algorithm in code −ExampleinsertIter(data) { let node = new this.Node(data); // Check if the tree is empty if (this.root === null) { // Insert as the first element this.root = node; return; } let currNode = this.root; ... Read More

283 Views
Let us understand how we're going to create and represent a binary search tree in Javascript. We'll first need to create the class BinarySearchTree and define a property Node on it. Exampleclass BinarySearchTree { constructor() { // Initialize a root element to null. this.root = null; } } BinarySearchTree.prototype.Node = class { constructor(data, left = null, right = null) { this.data = data; this.left = left; this.right = right; } };We've simply created a class representation of our BST class. We'll fill this class in as we proceed to learn functions that we'll add to this structure.