- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 8862 Articles for Front End Technology
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
We'll be creating a graph class that supports weights and both directed and undirected types. This will be implemented using an adjacency list. As we move to more advanced concepts, both weights and directed nature of the graphs will come in handy.An adjacency list is an array A of separate lists. Each element of the array Ai is a list, which contains all the vertices that are adjacent to vertex i. We're defining it using 2 members, nodes and edges.Let's set up the graph class by defining our class and some methods that we'll use to add nodes and edges ... Read More
![Sai Subramanyam](https://www.tutorialspoint.com/assets/profiles/13512/profile/60_68191-1512710774.jpg)
1K+ Views
A graph is a pictorial representation of a set of objects where some pairs of objects are connected by links. The interconnected objects are represented by points termed as vertices, and the links that connect the vertices are called edges.Formally, a graph is a pair of sets (V, E), where V is the set of vertices and E is the set of edges, connecting the pairs of vertices. Take a look at the following graph −In the above graph, V = {a, b, c, d, e} E = {ab, ac, bd, cd, de}TerminologyMathematical graphs can be represented in the data ... Read More
![Sai Subramanyam](https://www.tutorialspoint.com/assets/profiles/13512/profile/60_68191-1512710774.jpg)
598 Views
Here is the complete implementation of the AVL Tree Class −Exampleclass AVLTree { constructor() { // Initialize a root element to null. this.root = null; } getBalanceFactor(root) { return this.getHeight(root.left) - this.getHeight(root.right); } getHeight(root) { let height = 0; if (root === null || typeof root == "undefined") { height = -1; } else { height = Math.max(this.getHeight(root.left), this.getHeight(root.right)) + 1; } ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
165 Views
We can learn how we can insert a node in an AVL Tree. Insertions in AVL trees are the same as BST, we just need to perform one extra step called balance tree during insert whenever we move down the tree.This requires calculating the balance factor which we already saw before. And according to the configurations, we need to call appropriate rotation methods. These are pretty intuitive with the help of the above explanation.We again create a class method and a helper function for recursive calls − Exampleinsert(data) { let node = new this.Node(data); // Check if the tree ... Read More
![Sai Subramanyam](https://www.tutorialspoint.com/assets/profiles/13512/profile/60_68191-1512710774.jpg)
242 Views
To balance itself, an AVL tree may perform the following four kinds of rotations −Left rotationRight rotationLeft-Right rotationRight-Left rotationThe first two rotations are single rotations and the next two rotations are double rotations. To have an unbalanced tree, we at least need a tree of height 2. With this simple tree, let's understand them one by one.Left RotationIf a tree becomes unbalanced, when a node is inserted into the right subtree of the right subtree, then we perform a single left rotation −In our example, node A has become unbalanced as a node is inserted in the right subtree of ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
670 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 −In the second tree, the left subtree of C has height 2 and the right subtree has height 0, so the difference is 2. In the third tree, the right subtree of A has height 2 and the left is missing, so it is 0, and the difference is 2 again. AVL tree ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
217 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.
![Sai Subramanyam](https://www.tutorialspoint.com/assets/profiles/13512/profile/60_68191-1512710774.jpg)
234 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
![Nikhilesh Aleti](https://www.tutorialspoint.com/assets/profiles/519798/profile/60_1221559-1663324574.jpg)
2K+ 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
![Nikhilesh Aleti](https://www.tutorialspoint.com/assets/profiles/519798/profile/60_1221559-1663324574.jpg)
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