Segment Tree | Introduction | Basics | Build Segment Tree | Video 1 | codestorywithMIK
VloĆŸit
- Äas pĆidĂĄn 27. 07. 2024
- iPad PDF Notes - github.com/MAZHARMIK/Intervie...
Whatsapp Community Link : www.whatsapp.com/channel/0029...
This is the 1st video of our playlist "Segment Tree Concepts & Questions". Find the Details below :
Video Name : Segment Tree | Introduction | Basics | Build Segment Tree | Video 1
Video # : 1
đ Unraveling Segment Tree : A Journey into the Depths of Code
đ„ Welcome to the 1st Video of my Segment Tree Concepts & Questions Playlist! đ In this enlightening video, we dive headfirst into the world of Segment Tree, demystifying its essence and unraveling its secrets. đ
đ What's Inside ?
đ Definition: Get ready to grasp the fundamental concept of Segment Tree - What is it ? Why do we need it ? How to build it etc.
đ Why Segment Tree ? Uncover the beauty and power of segment tre in solving complex problems, making your code more elegant and efficient.
đ©âđ» Who Should Watch ?
This playlist is for everyone but best suited for Freshers who are new to Segment Tree.
đ Embark on the Segment Tree Adventure Now!
My DP Concepts Playlist : âą Roadmap for DP | How t...
My Graph Concepts Playlist : âą Graph Concepts & Qns -...
My Recursion Concepts Playlist : âą Introduction | Recursi...
My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
Subscribe to my channel : / @codestorywithmik
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
Summary : In this video, we will see what a segment tree is, why we need it. We will see with a simple example of "Range Sum Query". We will understand the details and
basics of segment tree. Understand with a complete example dry run. Make the tree diagram and deduce the simple recursive code to build a segment tree.
âââŠâââŠââââŠââŠâŠâŠâŠââââ
âââŁâââââŁââŁââŁââŁâââŁââŁ
â âââââââ ââââŁâââââââŁ
âââ©âââ©ââ©ââ©ââ©âââ©ââ©ââ
âš Timelinesâš
00:00 - Introduction
0:45 - Whe to use Segment Tree
5:35 - How to visualise segment Tree
15:30 - How many nodes in Segment Tree
25:10 - Code for Segment tree from tree diagram
37:46 - Complete Dry Run
49:43 - Time & Space Complexity of Build Segment Tree
52:46 - Whatâs Next ???
#codestorywithMIK
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear #RecursionExplained #CodingJourney #Programming101 #TechTalks #AlgorithmMastery #Recursion #Programming #Algorithm #Code #ComputerScience #SoftwareDevelopment #CodingTips #RecursiveFunctions #TechExplained #ProgrammingConcepts #CodeTutorial #LearnToCode #TechEducation #DeveloperCommunity #RecursiveThinking #ProgrammingLogic #ProblemSolving #AlgorithmDesign #CSEducation
#segmenttree #segment #rangequeries
ab maza aayega na biduâ€
Finally ab to leetcode ke contest ke 4 swal solve honge ab.
Ab aayega n maza đ.
Thank you for the playlist bhaiya.
Bhai Kal Hi Descide kia tha ki segment tree sikhna padega accha resource dhundna hoga nd Allhamdulillah you start this â€đ« Thank You So Much đ
One more weapon in the arsenal . Segment Tree . THANK YOU SIR
Love you bhai(sir) so much , I was thinking of doing this topic from somewhere and got confused from where but you made my work easy, now I don't have to go anywhere else. Thanks a lot and appreciate your efforts.
Thanks
By far the most clear segment tree explanation...đ„đ„đ„đ„
Can't wait more for the second part. Please please upload it soon :')
goated lecture bhaiya
Eid Mubarak !! , Please iss series ko continue kijiye
so much Respect and love to you mik for hearing to our requests in comments.
thanks a lot. is video se ye to lag raha ki segment tree easy hai ab. waiting for video 2, thank you so much
most waited series for me thanku MIK bhaiya
Jiska tha humko khub intezaar wo gadhi aa gayi đ Thanks sir for this
*Ghadee
IMPORTANT!!! bro i was just thinking to start segment tree today and found this awesome video thanks... pls segment tree ka baki videos jaldi laana ASAP
Bas aj leetcode last question dekh kr hi socha tha ke ab segment tree sikhna hai.
And here we go â€
same here bro
are guruji ye Hui na baat
14:40 iss property ko i guess bolte hai :- self balancing property/balancing factor/ AVL tree mein padhaya tha ki balancing factor 0 or 1 hi hogi , (Maybe)..Thanks
exactly i thought of avl is well
Your videos are amazing and helping me so much in understanding the concepts.. Thank you so muchâ€â€
Insane teaching skills
waiting for more videos to comeđđ
I was already having the intuition that Segment Tree is on the way â€â€â€
Great video đđ»
It is finally here! Let's go!
Thankyou sir!
With MIK all my DSA dar is over.
Eid Mubarak
pls further videos asap
best explanation sir being beginner i also understood it
Bro, segment tree is not for beginner, you will never be able to use it in any contest.
Thank you so much bhaiya â€â€
Too much underrated !... hatsoff to u... just do some marketing and u can kill it ! trust me
Thanks :) Watched complete video ,Will practice tomorrow morning. Please start discussing some LC questions on this topic
thanks bhaiya
bhaiya maza aagya saare concept clear hogye!!âŁâŁ
completed this video.....waiting for next video sir, please upload soon
Some Questions on segment Tree
Range Sum Query - Mutable (Medium)
Modify elements and calculate the sum in a specific range.
Range Sum Query 2D - Mutable (Hard)
A 2D version of the range sum query where you need to handle updates and sum calculations in a 2D matrix.
Count of Smaller Numbers After Self (Hard)
Count the number of smaller elements to the right of each element in an array.
The Skyline Problem (Hard)
Given buildings in the form of (left, right, height), find the skyline formed by these buildings.
Falling Squares (Hard)
Given a list of squares that drop onto the x-axis, return the height of the tallest square after each drop.
Kth Largest Element in an Array (Medium)
Find the kth largest element in an array, where updates to the array can occur.
Range Frequency Queries (Medium)
Handle queries on the frequency of elements within a specific range.
Thank you bhaiya .Ye concept CP ke liye important hai .
Aapke deep drive lecture se CP me help hogi thanks
Thanks sir. It was much needed. Ajkal ke contest main segment tree bahut zyada aa raha hain.
Haa 4th problem leetcode ke contest ka segment tree ka hii hota h
Eid Mubarak Bhai!!!!!!!!!!!
Much needed sir....please do solve some of the famous leetcode seg tree question.....I think it will be very helpful....mostly the 4th question in leetcode contests is seg tree or fenwick tree.....thanks a lot for thisâ€
Completely understood the concept. We need more parts of it frequently pleaseâ€
maza agaya bhai.
Wowww đ„łđ„ł
Yesssss â€â€â€â€â€
Finally. Thanks a lot for making the playlist in Parts â€â€â€
Indeed very important.
wow
sir dp ka playlist bhi complete kar dijiye ho sake to, aap bohot accha padhate hai
finally 4 question se dar nahi lagegađđđ
Too good yaar. Thank you soooo much for this awesome gift â€â€â€â€ You really are doing a great job. Keep it up sir ji
Thanku â€
401 and 402 contest ka 4th wala Q's bhi karva dena pls â€
Finally đ
Bahot ache se samajh agay.
Waiting for 2nd video
Bhaiya iske questions CSES problemset se krwana Please . CSES problemset ke solutions kisi ne bhi nhi krwae hue h ache se .. Bas ab aapse hi umeed h .Please jldi se krwa do Placement season start hone wala h next month se
love you sirâ€
love you sir
understood clearly thanks sir for such a nice explanation
Yeahhhhâ€â€â€
Wow! â€â€â€ Thank you so much Bhaiya â€â€â€â€â€
Explanation is really awesome đ
Watched the entire video. Thank you bhaiya.
Bhaiya, aap pls contest ke solutions bhi banaya karo na pls.. aap jaisa koi nahi samjha sakta and bahut ache problems hote hain contest main. it would be very very helpful bhaiya. Agar aapko time mile toh pls bana saktein hain?
thank you bhayia â€â€â€
next video lao bhaiyya
Can you please explain when to use difference array and when to use segment tree? Or any video on difference array.
Great Work â€â€â€â€
â€â€đ
sir please complete this segment tree first leaving all other dsa series lecture..
Bhaiya please complete the graph playlist â€
Thanks for this informative video sir. One request to you please make a video of Leetcode problem 2910 . Minimum number of groups to create a valid assignment as it's a OA question and I'm not able to understand the solutions
Ab bas sir iske other parts me or detailed with question solving leao jaldi se jaldi
Build segment tree me problem hai..
For example: [-28,-39,53,65,11,-56,-65,-39,-43,97]
Iss array ka segment tree build karo toh aapke hisaab se 10+5+2+1=18 elements hone chahiye but actual me usse jyaada honge
This is because tree ka harr leaf node same depth pe ho aisa zaruri nahi hai.. which is happening in the above case...
Since it is a balanced binary tree, height ka difference at max 1 ho sakta hai which is why your GP of N, N/2, N/4 should begin from 2N
Total nodes => 2N, N, N/2, N/4... 1 = 4N
So instead of 2N nodes in a segment tree, there should be 4N nodes.
I totally agree. I was planning to add this in my next video.
When the size of the input array
n is not a power of 2, the segment tree may need more nodes to handle the uneven distribution of elements. Using 4n
ensures that there is always enough space to build the tree without running into indexing issues. The worst-case size of the segment tree for any array size can be up to 4n due to how the tree is balanced and structured internally.
Bhaiya time complexity segment tree ki O(log n) hona chahiye na ,kyuki apn toh height wise ja rhe na.
Bhaiya please make solution of leetcode 3186 solution humble request
can u post the second video today itself??
But generally we take size of segment tree array as 4*n why is that can you explain that?
Bhaiya dp ki concept playlist khtm krwa dijiye
next video kb aegi bhai
please leetcode 3187 for explaining segment trees
Oye hoye aye haye , moka mile kaddi kaddi
pls sir je jldi krado plcaement start hore
Please share the code link
Here is the code for building segment tree.
void buildSegmentTree(int i, int l, int r) {
if (l == r) {
segmentTreeArray[i] = nums[l];
return;
}
int mid = (l + r) / 2;
buildSegmentTree(2 * i + 1, l, mid);
buildSegmentTree(2 * i + 2, mid + 1, r);
segmentTreeArray[i] = segmentTreeArray[2 * i + 1] + segmentTreeArray[2 * i + 2];
}
I understood the Segment Tree l but While contruct.
2*n Size segment Tree is Giving out of range issue.
4*n Solve the issue, Can you explain more about this?
Code
arr=[0,3,3,5,7,6]
n=len(arr)
segmentTree=[-1]*(4*n)
def buildTree(indx,low,high):
if low==high:
segmentTree[indx]=arr[low]
return
mid=low+(high-low)//2
buildTree(2*indx+1,low,mid)
buildTree(2*indx+2,mid+1,high)
segmentTree[indx]=segmentTree[2*indx+1]+segmentTree[2*indx+2]
buildTree(0,0,n-1)
print(segmentTree)
coming in next video
@@codestorywithMIK Thanks dude !
Video jaldi jaldi laana is playlist ki bhai. Great content
Notes de do mik bhai
description me link hai iPad pdf notes karke jo likha hai. It was not opening yesterday, now it's opening.
dp ka khatam kijiye please
Thanks