No video

Sum of given range | Segment tree construction and update | Simplest explanation

  Рет қаралды 55,207

Techdose

Techdose

Күн бұрын

This video explains, in the simplest way possible, a very frequently asked data structure which is segment tree in details with construction of segment tree along with operations like range sum query and update of old values to new value. CODE explanation is done after each operation for better understanding. CODE LINK is given below. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
CODE LINK: gist.github.co...

Пікірлер: 168
@yushdecides
@yushdecides 3 жыл бұрын
Whenever I want an explanation of any tough topic, I see your videos. They are just awesome.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks bro :)
@kasecastiel5826
@kasecastiel5826 3 жыл бұрын
i guess im asking the wrong place but does someone know of a tool to log back into an instagram account?? I somehow lost my account password. I would appreciate any tricks you can offer me
@emilioangelo4753
@emilioangelo4753 3 жыл бұрын
@Kase Castiel instablaster =)
@kasecastiel5826
@kasecastiel5826 3 жыл бұрын
@Emilio Angelo i really appreciate your reply. I got to the site through google and I'm in the hacking process atm. Looks like it's gonna take quite some time so I will get back to you later with my results.
@kasecastiel5826
@kasecastiel5826 3 жыл бұрын
@Emilio Angelo It did the trick and I now got access to my account again. I am so happy:D Thank you so much, you saved my ass !
@AtulKumarVermaOnline
@AtulKumarVermaOnline 3 жыл бұрын
Only a handful of KZbin channel explain the concepts in this much clarity and yours is definitely one of them. Keep going.
@SR-we1vl
@SR-we1vl 4 жыл бұрын
I guess in Efficient approach 01:24 Sum(L, R) should be Sum(L, R) = Sum[R] - Sum[L-1] ! Great Tutorial by the way! Thank you very much!!
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@martinharris4416
@martinharris4416 3 жыл бұрын
before seeing this video i feared segment trees as i used to hear this word when CP was mentioned but i never though someone would explain so beautifully
@vikashmaddi1508
@vikashmaddi1508 3 жыл бұрын
Tech dose is underrated
@shubhammishra3012
@shubhammishra3012 4 жыл бұрын
I saw some of your lecture about rolling hash ,and this one , Your content is really worthy for competitive programming as well as interview purpose
@techdose4u
@techdose4u 4 жыл бұрын
Thanks
@lambar0
@lambar0 Жыл бұрын
Most Intuitive and comprehensive explanation so far…… I had watched three earlier videos on the topic giving scattered information….great job
@techdose4u
@techdose4u Жыл бұрын
Thanks :)
@aishwaryadwani9365
@aishwaryadwani9365 4 жыл бұрын
I was going through segment tree topic and saw your video. Now i don't have to watch/search for another videos. Thanks a ton !
@techdose4u
@techdose4u 4 жыл бұрын
Welcome
@bakrichodhpakistani7196
@bakrichodhpakistani7196 3 жыл бұрын
best content on segment tree on ytube
@techdose4u
@techdose4u 3 жыл бұрын
Thanks:)
@getsuha
@getsuha 2 жыл бұрын
Concise and compact. Only correction required at t=12.26, the two left most nodes have range [0-0] & [1-1] instead of [1-1] & [2-2].
@mondayemmanuel191
@mondayemmanuel191 3 жыл бұрын
You really know how to explain algorithms. Thank you.
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@mohammadtej5980
@mohammadtej5980 2 жыл бұрын
Best explanation of Segment tree, I understood it, thanks for your help. PS: I don't understand why people don't like such videos🤔
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@Pooja-xu4lp
@Pooja-xu4lp 3 жыл бұрын
On this topic, this is the best video. You saved my days and weeks. Thank you
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@aaronpauljacob5143
@aaronpauljacob5143 4 жыл бұрын
🔥 🔥 🔥 Such amazing explanation!!! 🔥 🔥 🔥 You are a wonderful teacher sir. The video was so simple to understand and exactly what was needed. ⭐️ ⭐️ ⭐️
@techdose4u
@techdose4u 4 жыл бұрын
Thanks
@neerajkulkarni6506
@neerajkulkarni6506 3 жыл бұрын
One of the best explanation of segment trees on KZbin! Great video.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@pradiplamsal1403
@pradiplamsal1403 Жыл бұрын
Such a clean explanation. Anybody with a Computer Science background would understand. Thank you very much.
@ArjunArjun-zg3mz
@ArjunArjun-zg3mz 3 жыл бұрын
Really love the way you explain these concepts with pseudo code and examples you solve!!! It greatly help grasp the concept.
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@high-oncode7576
@high-oncode7576 3 жыл бұрын
Support
@techdose4u
@techdose4u 3 жыл бұрын
🔥
@FWTteam
@FWTteam 4 жыл бұрын
I searched a lot and my search ended here. Superb explaination 🔥
@techdose4u
@techdose4u 4 жыл бұрын
Nice :)
@artistic__08
@artistic__08 7 ай бұрын
Best explanation of segment tree indeed
@choicespecss
@choicespecss Жыл бұрын
This was the best explanation of segment trees I've seen! Subscribed and Liked
@patienward
@patienward 11 ай бұрын
You made it very clear to me! Thanks!
@HimanshuKumar-xz5tk
@HimanshuKumar-xz5tk 3 жыл бұрын
I love this way of making video, everything explained from basic with comparison of different approaches.
@techdose4u
@techdose4u 3 жыл бұрын
👌🏼
@shahperzia1121
@shahperzia1121 3 жыл бұрын
very Underrated channel bro, content quality is gold.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@doitlikeprateek717
@doitlikeprateek717 2 жыл бұрын
The best channel for programming videos
@robinofautumn99
@robinofautumn99 5 ай бұрын
utterly smooth explanation!!😊😊
@biswamohandwari6460
@biswamohandwari6460 3 жыл бұрын
Mind blowing explanation understand every word in the video best one ever
@techdose4u
@techdose4u 3 жыл бұрын
Nice :)
@chiragchatwani9124
@chiragchatwani9124 4 жыл бұрын
you will have a Million subs one day. thank you so much can you explain Quick select algorithm
@techdose4u
@techdose4u 4 жыл бұрын
I already did explain quick select (even though using OK too many times :P ). Check it once.
@harshdeepsinghful
@harshdeepsinghful 2 жыл бұрын
Well the topic was explained so well, felt like segment tree is such a easy topic
@mohitbabani7816
@mohitbabani7816 3 жыл бұрын
The explanation is very good, thank you so much🙏
@techdose4u
@techdose4u 3 жыл бұрын
Welcome 🤗
@bishalkumarnath3176
@bishalkumarnath3176 3 жыл бұрын
Awesome Explanation. Couldn't be any better than this
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@originaladmin
@originaladmin 3 жыл бұрын
Hi. Very nice explanation. One thing though. I think the size of the tree should be pow(2, h +1) - 1, not pow(2, h) - 1.
@leepakshiyadav1643
@leepakshiyadav1643 2 жыл бұрын
I was scared of this topic, you made it damn simple and fun to understand, thanks a ton :)
@namanmehra8097
@namanmehra8097 3 жыл бұрын
Really Clear Explaination
@safalyaghoshroy2405
@safalyaghoshroy2405 4 жыл бұрын
Sir your process of explaining problems is excellent and video is superb. Pls add more videos of fenwick tree. Thank you.
@techmind9608
@techmind9608 4 жыл бұрын
dude ,,seriously what do u eat,,,,this video deserve more views,,,,,best ever video i hv seen:),,,i am addicted to ur channel :),,,
@techdose4u
@techdose4u 4 жыл бұрын
Keep watching :)
@akshatthakur5967
@akshatthakur5967 3 жыл бұрын
excellent explanation
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@gauravkumarjaiswal8224
@gauravkumarjaiswal8224 6 ай бұрын
Perfect explanation 😊
@ksTales
@ksTales 3 жыл бұрын
Sir no words to say how great you are
@techdose4u
@techdose4u 3 жыл бұрын
❤️
@vikashprasad1770
@vikashprasad1770 3 жыл бұрын
Very well explained sir, thanks a lot for this !!!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@manojamrutharaj9071
@manojamrutharaj9071 2 жыл бұрын
Awesome explanation... Thanks...
@mohitlaad8435
@mohitlaad8435 Жыл бұрын
great work! Thanks.
@techdose4u
@techdose4u Жыл бұрын
Thanks :)
@terigopula
@terigopula 2 жыл бұрын
great video.. great explanation.. kudos :)
@dollyakshaya7535
@dollyakshaya7535 Жыл бұрын
great explanation bro
@techdose4u
@techdose4u Жыл бұрын
Thanks :)
@manngondaliya4704
@manngondaliya4704 4 жыл бұрын
Bohot mast kaam karte hai aap .Keep it going
@techdose4u
@techdose4u 4 жыл бұрын
Thanq bhai :)
@ismail8973
@ismail8973 3 жыл бұрын
This class was really awesome
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@mohammadyahya78
@mohammadyahya78 Жыл бұрын
Thank you very much. At 1:05 you said we need O(n.q) to find sum, do you mean by q = n^2 so O(n^3)? Because we need 3 loops in the bruteforce approach. I am I wrong please?
@rahulsaha7412
@rahulsaha7412 4 жыл бұрын
You are always excellent, Sir
@techdose4u
@techdose4u 4 жыл бұрын
Welcome
@soumakpoddar4372
@soumakpoddar4372 3 жыл бұрын
I think the size of the segment tree should be 2*(2^h-)1.....Correct me if I am wrong
@twishabansal263
@twishabansal263 4 жыл бұрын
Great one. Just a suggestion though: It would be better if the written code is typed or something. That's easier to understand than the hand writing.
@techdose4u
@techdose4u 4 жыл бұрын
I did not use to include code explanation earlier but now I have been doing it.
@MarekXvX
@MarekXvX 2 жыл бұрын
Great explanation! Thanks for your work!
@dayanandraut5660
@dayanandraut5660 2 жыл бұрын
Beautiful explanation 👌
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@SahilKumar-yv8vh
@SahilKumar-yv8vh 4 ай бұрын
Thanks from IIT'K.
@toekneema
@toekneema 3 жыл бұрын
AMAZING, crystal clear!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@sezgingul6166
@sezgingul6166 3 жыл бұрын
Very good explanation ! I have a question though, at 3:11min you say "we use segment trees when we have more updates..." you meant the opposite right?
@techdose4u
@techdose4u 3 жыл бұрын
No. If you don't have updates then simply use array otherwise if updates are needed then use segment tree instead of array. Use lazy propagation to get more efficiency.
@ryderdonahue
@ryderdonahue 2 жыл бұрын
Great explanation! Although I wish you covered the insert function
@bhavnasoni9148
@bhavnasoni9148 4 жыл бұрын
Thank u for such a great explanation.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@nikitabhalla524
@nikitabhalla524 3 жыл бұрын
Just WoW
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@shubhammishra3012
@shubhammishra3012 4 жыл бұрын
Please make the videos for heaps,heap sort and Fenvick Tree ,that will be really helpful
@techdose4u
@techdose4u 4 жыл бұрын
Yes I will.
@hillarioushollywood4267
@hillarioushollywood4267 2 жыл бұрын
How come the time complexity of udaption is O(LogN), it should be O(N) as you are still updating each and every node in right sub segment tree. Even in the worst case where updation index is 1, then definitely it is O(N). Can you please explan @techDose?
@cricsinghvlogz
@cricsinghvlogz 2 жыл бұрын
just wow !!
@hereyoursdad
@hereyoursdad 2 жыл бұрын
very very nice
@anshumansharma2251
@anshumansharma2251 2 жыл бұрын
insertion and deletion in bst (segment tree) takes O(logn) time so how it is O(q) and O(n) in sum?
@pawandeepsingh2155
@pawandeepsingh2155 3 жыл бұрын
Awesome lecture
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@mohanawasthi7045
@mohanawasthi7045 Жыл бұрын
Great sir
@Mandeepsingh-jo5cf
@Mandeepsingh-jo5cf 3 жыл бұрын
Thanks. correction: pink == purple;
@chetan_bommu
@chetan_bommu 2 жыл бұрын
For array, Shouldn't Q query time be O(N + Q)? which can be said as O(N). As we first create the array and then do Q operations in O(Q).
@adityarathi3420
@adityarathi3420 3 жыл бұрын
Superb explanation ! Thanks a lot :-)
@AmanKumar-fd5ec
@AmanKumar-fd5ec 3 жыл бұрын
Really Awesome and Simplest way to understand this important and tricky data structure. By the way which software do you use for the demonstration which gives a black background?
@manikantapunnam1189
@manikantapunnam1189 3 жыл бұрын
Thanks a lot
@TheSridharraj
@TheSridharraj 3 жыл бұрын
Masssssss
@techdose4u
@techdose4u 3 жыл бұрын
:)
@Ishwarsingh-zq5ig
@Ishwarsingh-zq5ig 2 жыл бұрын
thank you sir
@ranitdey7369
@ranitdey7369 3 жыл бұрын
Excellent buddy. keep it up !
@techdose4u
@techdose4u 3 жыл бұрын
Sure :)
@Ajay-ju2ig
@Ajay-ju2ig 4 жыл бұрын
We use array for storing value in segment tree .It is possible some index in middle of the array is empty?
@techdose4u
@techdose4u 4 жыл бұрын
If it is a Full binary tree then No. Gaps will only be at the end.Leaf nodes will be storing the actual array elements. Internal nodes will have range query values.
@srinivasreddydanda1777
@srinivasreddydanda1777 3 жыл бұрын
awesome man. Thanks !!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@rishabhmishra9611
@rishabhmishra9611 4 жыл бұрын
Well explained
@techdose4u
@techdose4u 4 жыл бұрын
Thanks
@adityasinghaswal4923
@adityasinghaswal4923 2 жыл бұрын
best!
@spetsnaz_2
@spetsnaz_2 4 жыл бұрын
Good Explanation....
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@SreekantShenoy
@SreekantShenoy 2 жыл бұрын
wow!
@roshan84ya99
@roshan84ya99 4 жыл бұрын
Why we are using segment tree still we need to calculate or go for the node till we did not find the value total overlapping 🙄
@techdose4u
@techdose4u 4 жыл бұрын
Use Fenwick tree for easier implementation wherever possible.
@kushwanthkapa2041
@kushwanthkapa2041 3 жыл бұрын
sir i think it is not full binary tree because in full binary tree leaf nodes are only present at last level..................... in 5:16
@Ali-mc4le
@Ali-mc4le 4 жыл бұрын
Hi Sir, what tool are you using to draw and write your solutions?
@somnathmukherjee4305
@somnathmukherjee4305 4 жыл бұрын
Can u please make a video on MO's algorithm too as very less resources are there in KZbin??
@techdose4u
@techdose4u 4 жыл бұрын
Yea I understand. I will add it to list but it won't be possible with leetcode daily challenges.
@somnathmukherjee4305
@somnathmukherjee4305 4 жыл бұрын
Okay
@najimali32
@najimali32 4 жыл бұрын
If nums are negative then diff should be mod of new value minus previous one ??
@HimanshuSingh-ob9qo
@HimanshuSingh-ob9qo 3 жыл бұрын
👌👌👌👌👌🙏
@jaydalsaniya6986
@jaydalsaniya6986 2 жыл бұрын
A minor change in the formula. It should be , sum ( L , R ) = sum [ R ] - sum [ L-1 ] .
@jalsacentre1040
@jalsacentre1040 3 жыл бұрын
1:27 it should be num[R]-sum[L-1]
@kumarakash5219
@kumarakash5219 3 жыл бұрын
You are right ...i have same doubt bro..
@mwshubham
@mwshubham 3 жыл бұрын
Did you ever recieve negative comment on your videos?
@techdose4u
@techdose4u 3 жыл бұрын
Only when I announced about paid LIVE course 😂
@mwshubham
@mwshubham 3 жыл бұрын
@@techdose4u haha.
@AlayDhagia
@AlayDhagia 3 жыл бұрын
At 2:10 Wont the TC for range sum queries be O(Q logN) ?
@hillarioushollywood4267
@hillarioushollywood4267 2 жыл бұрын
Yes it would definitely be O(QlogN) if there are Q queries, but in this video he is talking about only 1 query so logN
@sainathmandavilli6538
@sainathmandavilli6538 2 жыл бұрын
i think update takes 0(n) in worst case
@hillarioushollywood4267
@hillarioushollywood4267 2 жыл бұрын
Exactly, this is what I was looking for in the comments. Moreover, he is udapting every other element in right sub segment tree, so how come time complexity come out to be O(logN)? it is nearly O(N). More precisely, he is updating N/2 nodes.
@nitya5120
@nitya5120 3 жыл бұрын
2*(si+1) hoga maybe
@DogVideos-Tommy
@DogVideos-Tommy 3 жыл бұрын
In update why we are not adding
@DogVideos-Tommy
@DogVideos-Tommy 3 жыл бұрын
when l==r
@hillarioushollywood4267
@hillarioushollywood4267 2 жыл бұрын
we are adding in right subtree
@abhireddy8164
@abhireddy8164 4 жыл бұрын
Longest substring containing vowels in even counts.please add to the queue sir
@techdose4u
@techdose4u 4 жыл бұрын
Provide me the question link.
@abhireddy8164
@abhireddy8164 4 жыл бұрын
There is no question link in gfg too sir.but similar questions are minimum window string.it might uses sliding window protocol or it might use dynamic programming.actually I see that question in amazon interview experience in gfg.
@abhireddy8164
@abhireddy8164 4 жыл бұрын
Given a string print the largest sub-string containing vowels in even counts.O(n) eg. S-> aqwrteakjeaghev , answer->aqwrteakje as it contain 2 ‘a’ and 2 ‘e’. Second in same question he want me to print all sub-string if multiple sub-strings are possible of same length.
@techdose4u
@techdose4u 4 жыл бұрын
Okay... But if there is no question link then it is difficult to verify code and technique. Only intuition can be discussed.
@abhireddy8164
@abhireddy8164 4 жыл бұрын
Ok sir it's fine.
@ayushgarg5929
@ayushgarg5929 3 жыл бұрын
Size kitna hoga array ka ?
@techdose4u
@techdose4u 3 жыл бұрын
Heap jaise implement krte ho waise hi krna.
@user-ls6qw2vw6i
@user-ls6qw2vw6i 3 жыл бұрын
I still not understand
@ojasvityagi9569
@ojasvityagi9569 4 жыл бұрын
GOLD
@techdose4u
@techdose4u 4 жыл бұрын
:)
@amitavamozumder73
@amitavamozumder73 3 жыл бұрын
when you finally learn dp and found this where dp would be a bad solution :/
@edward8111
@edward8111 Жыл бұрын
Leatcode 307
@abhireddy8164
@abhireddy8164 4 жыл бұрын
Thank u sir
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
Segment Tree Range Minimum Query
27:44
Tushar Roy - Coding Made Simple
Рет қаралды 274 М.
Zombie Boy Saved My Life 💚
00:29
Alan Chikin Chow
Рет қаралды 34 МЛН
managed to catch #tiktok
00:16
Анастасия Тарасова
Рет қаралды 55 МЛН
SEGMENT TREE  Implementation / Construction (Sum of range query and update query)
34:35
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 16 М.
Remove K digits | Build lowest number | Leetcode #402
15:30
Techdose
Рет қаралды 88 М.
Minimum edit distance | Dynamic programming | Backtracking
28:52
Fenwick Tree range queries
13:45
WilliamFiset
Рет қаралды 36 М.
Segment Tree Data Structure - Min Max Queries - Java source code
8:47
Sparse Table & RMQ (Range Minimum Query)
18:42
Errichto Algorithms
Рет қаралды 75 М.
Segment Tree: Build and Query | Live Coding..
20:20
take U forward
Рет қаралды 105 М.
My Brain after 569 Leetcode Problems
7:50
NeetCode
Рет қаралды 2,5 МЛН
Segment Trees Tutorial | Range Queries | Interview Questions
1:13:23
Kunal Kushwaha
Рет қаралды 46 М.
Zombie Boy Saved My Life 💚
00:29
Alan Chikin Chow
Рет қаралды 34 МЛН