Interview Problem: How to Build A Segment Tree?
Вставка
- Опубліковано 12 вер 2024
- Get COURSES For FREE Using This Scholarship Test. Register Here Now: www.codingninj... In this video, you will learn how to build a segment tree.
0:30 Concept behind building a segment tree.
2:26 Elements required to build a segment tree.
5:39 Code for Building a segment tree.
14:30 Explanation of output.
----------------------------------------------------------------------------------------
Join our Coding Ninjas official telegram community here: t.me/codingnin...
----------------------------------------------------------------------------------------
Coding Ninjas is one of the leading EdTech company providing India’s Highest rated programming courses in C++, Data Structures and Algorithms, Java, Python, Machine Learning, web development, Data Science, Android Development, Kotlin, React.
To explore our courses, click here: bit.ly/2WWmdE1
To explore our Free Trial Courses click here: bit.ly/2YqUL1Y
-----------------------------------------------------
To watch more exciting videos on programming, subscribe to our channel here: bit.ly/36n3g08
------------------------------------------------------
Explore more on our social media platforms:
Facebook: / codingninjas
Instagram: / coding.ninjas
Linkedin: / 1319…
Join our Coding Ninjas official telegram community here:
t.me/codingninjas_official
The size of the tree array is not always 2*N. It should be calculated by visualizing the number of nodes required in the complete binary tree. eg. h < log(N) < h+1. Then take size of the tree array as pow(2, h + 1). 2*N does not always work.
Got queries related to segment tree, Let us know in the comments section.
In this video, you will learn how to build a segment tree.
0:30 Concept behind building a segment tree.
2:26 Elements required to build a segment tree.
5:39 Code for Building a segment tree.
14:30 Explanation of output.
------------------------------------------------------------------------------------------------------------------------------------------------------
To explore our courses, click here: bit.ly/2WWmdE1
To explore our Free Trial Courses click here: bit.ly/2YqUL1Y
-----------------------------------------------------
To watch more exciting videos on programming, subscribe to our channel here: bit.ly/36n3g08
Nice explanation sir... For zero based indexing, left child is at 2*n+1 and right child is at 2*n+2... Not that it is not possible as you said in video
True
And it's easy also because we already use in heaps.
@Sunil ikr
Good Job, thank you for sharing it for FREE!!
Thank You
The best explanation one would ever see about segment trees. Thank you sir and coding ninjas .
Logic completely fails, array is not sufficient to cover the whole, segment tree
the code fails when input N = 6
because 2*6 = 12
and we are trying to store the value of [3 : 3] to index 12 and [4 : 4] to index 13.
Yes you are correct. In this video focus was on the logic behind building a segment tree. How each calling works and all.
Size of the segment tree was not in focus in this video.
Yes if size is 6 and input is 1,3, 5,7,9,11
Then in the output 0 is also coming and also size of tree is not even correct
shubhendra singh chauhan do this
H = ceil(log2(size));
H = (int)(2*(pow(2, H))-1);
H is the required size....
Mid = pow(2, ceil(log(end-start)/log(2))-1)
This would work for all sizes.
it will require atmost 4n indices
Thanks for sharing this video ,it is very well explained but Program will not work for all test cases, Eg:- Consider an array with length 6.
Thanks @Coding Ninjas. Shared to the CP group.
Thank you for the kind words! We hope that this video has helped you!
Stay tuned to Coding Ninjas UA-cam channel for more such content! Do check our Coding Ninjas Studio, where you can upskill for free and become a Ninja Coder: www.codingninjas.com/studio/home?
If reading is your preference, you can find top articles to upskill in your career here: www.codingninjas.com/studio/library?
If you would like to opt for a Coding Ninjas course, you can check our courses here: www.codingninjas.com/?
it took me hours to actually find a good explanation ,,,,thank yu so much...:)
beautifully explained....Thank you.
Finally i understand ST
look if you don't want to upload another video than its ok we have many other coders on you tube how desperately want to teach us. So i believe if you start any topic then it's your responsibility to complete it. plz while teaching put your business mind aside and teach completely what ever you teaching where is video 2???
It will not work for all test cases for example consider [1,2,3,4,5,6]. It will work for the trees which are full of course but also last level nodes are as left as possible. Kindly correct your video. Otherwise the video was good.Nice explanation.
Simplest explanation on UA-cam. Thank you so much
This remember me my jee teachers...hahaha...lil bit annoyingly explained. But at the end any one can understand.
Brilliant!!!
Kya mast samjhata hai ye banda awesome video
Does coding ninjas provide how to set up coding environment in sublime text or editor in competitive programming course?
Amazing explanation!! Subscribed.
Thank you so much bhaiya!! online Articles padhke nahi samajh a raha tha. Ab aa gaya, subscribed the channel after seeing this video!
You have not kept whose range is the THIS node sum !!
and where are the next vedios Update and Query ??? forgot ?
awesome tutorial. Good work bro. thanks.
Best explanation , Thank you
Superb Explanation..
Please add the update part. It will be very helpful. Thanks in advance.
Thank you for the kind words! We hope that this video has helped you!
Stay tuned to Coding Ninjas UA-cam channel for more such content! Do check our Coding Ninjas Studio, where you can upskill for free and become a Ninja Coder: www.codingninjas.com/studio/home?
If reading is your preference, you can find top articles to upskill in your career here: www.codingninjas.com/studio/library?
If you would like to opt for a Coding Ninjas course, you can check our courses here: www.codingninjas.com/?
Great job!!
very nice and interacting
Why this code is not workng for this array {2,6,1,4,7,8}
?
Is this competitive career track program course available in English lectures
I dont think so
I think this segment tree wont work for array of size above 9
thanks bro!!
VERY NICE EXPLANATION!!
It is wrong implementation, this recursive implementation requires twice the next power of 2,there is one iterative implementation on codeforces which takes 2*n size.
thanks a lot
Awesome!
are root toh dikh hi nahi raha or kya garantee hai ki yeh tree fruit de ga
where is the next part please upload
i would like to learn updating and complete query problemfrom you
Anany Sharma hey, you can drop us mail at contact@codingninjas.in or call us at toll free: 1800-300-28085
Sir there will be (2*n)-1 nodes for sure but the index can be greater than (2*n)-1. So the size of tree should be 2*(2^(log2(n))) instead of (2*n)-1.
Jitti nodes hoti hai wahi size hota hai tree ka
can someone please add subtitles... i can`t understand hindi...
Awesome
Why is the title and description in English when you are speaking some other language?
this is an indian coding company bro using indian language
Explain it in English sir !
👌👌👌👌👌🙏
fails for n=13 for some reason
Probably you need to check the size of the bigger array, it won't be 2*13, try making it a power of 2 next to 26. ie. 32.
Wrong implementation
can someone please add subtitles... i can`t understand hindi...