0
0
DSA Javascriptprogramming~5 mins

BST Find Maximum Element in DSA Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Binary Search Tree (BST)?
A Binary Search Tree is a tree where each node has at most two children. The left child's value is less than the parent's value, and the right child's value is greater than the parent's value.
Click to reveal answer
beginner
In a BST, where is the maximum element located?
The maximum element is always found at the rightmost node because values increase as you move right.
Click to reveal answer
beginner
Why do we keep moving right to find the maximum element in a BST?
Because in a BST, all right children have values greater than their parents, so the farthest right node holds the largest value.
Click to reveal answer
intermediate
What is the time complexity to find the maximum element in a BST?
The time complexity is O(h), where h is the height of the tree. In the worst case (skewed tree), it can be O(n).
Click to reveal answer
beginner
Show the JavaScript code snippet to find the maximum element in a BST.
function findMax(root) {
  if (!root) return null;
  while (root.right) {
    root = root.right;
  }
  return root.value;
}
Click to reveal answer
Where do you find the maximum element in a BST?
ALeftmost node
BRightmost node
CRoot node
DAny leaf node
What is the first step to find the maximum element in a BST?
AGo to the right child
BGo to the left child
CCheck the root value
DTraverse all nodes
What is the time complexity to find the maximum element in a balanced BST?
AO(1)
BO(n log n)
CO(log n)
DO(n)
If a BST has only one node, what is the maximum element?
AThe right child value
BNo maximum element
CThe left child value
DThe root node's value
What happens if you call findMax on an empty BST?
AReturns null
BReturns 0
CThrows error
DReturns undefined
Explain how to find the maximum element in a Binary Search Tree.
Think about where larger values are stored in a BST.
You got /4 concepts.
    Write a simple JavaScript function to find the maximum value in a BST and explain its steps.
    Use a while loop to traverse right children.
    You got /3 concepts.