3.c) Sorted data to balanced bst || Binary Search Tree

preview_player
Показать описание
In this video, I have discussed about making a balanced binary search tree data structure(bst) from sorted data.

The algorithm used is to make the middle element as root and recursively build left and right subtree.

Practice questions:

I hope you liked my video, do subscribe to my channel to get the updates of my latest uploads.

#bst #binarysearchtree #binarytree #datastrucuture #algorithm #interviewquestions #placement #internship #faang
Рекомендации по теме
Комментарии
Автор

Thank you bhaiya, Your channel is One stop destination,

peehugandhi
Автор

Your decision tree concept is just awesome !!

abhishekranjansingh
Автор

void buildBST(vector<int>&nums, int start, int end, vector<int>&ans){
if(start>end)
return;
int mid = (start+end)/2;
ans.push_back(nums[mid]);
buildBST(nums, start, mid-1, ans);
buildBST(nums, mid+1, end, ans);

}
vector<int> sortedArrayToBST(vector<int>& nums) {
vector<int>ans;
int n = nums.size();
buildBST(nums, 0, n-1, ans);
return ans;
}

wecan
Автор

bhai i have chosen you as my guidance on trees. Waiting for more topics now on BST as you pictured in the first video. Thank you for making me believing that i can also understand tree and code the same :D More power to you !!

PS - When are you uploading next ?? ;-)

TusharRaj
Автор

Gold level contents, all your videos are very simple and easy to understand, thanks for your help buddy, after aditya verma you are the person who is teaching recursion in his own style.

shashankshekhar
Автор

class Solution {
public:
void buildBST(vector<int>&nums, int start, int end, vector<int>&ans){
if(start>end)
return;
int mid = (start+end)/2;
ans.push_back(nums[mid]);
buildBST(nums, start, mid-1, ans);
buildBST(nums, mid+1, end, ans);

}
vector<int> sortedArrayToBST(vector<int>& nums) {
vector<int>ans;
int n = nums.size();
buildBST(nums, 0, n-1, ans);
return ans;
}
};

manikanth.
Автор

this is kashish mahendiratta is missing kashish bhai after hello everyone, ... badly missing

HIMANSHUVERMA-wuhc
Автор

waiting for more interesting questions😁🔥

abhishekvishwakarma