• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
September 12, 2024 |390 Views

SDE Sheet - Sorted Array to Balanced BST

Description
Discussion

This video is part of the Binary Search Tree section under GFG SDE Sheet.

Given a sorted array. Convert it into a Height Balanced Binary Search Tree (BST). Return the root of the BST.

Height-balanced BST means a binary tree in which the depth of the left subtree and the right subtree of every node never differ by more than 1.

Note: The driver code will check the BST, if it is a Height-balanced BST, the output will be true otherwise the output will be false.

Examples :

Input: nums = [1, 2, 3, 4] Output: true Explanation: The preorder traversal of the following BST formed is [2, 1, 3, 4]:            2          /   \        1     3                \                 4

Do check out:-
Problem: https://www.geeksforgeeks.org/problems/array-to-bst4443/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/
Article Link: https://www.geeksforgeeks.org/sorted-array-to-balanced-bst/