Segment Tree: Build and Query | Live Coding..
Вставка
- Опубліковано 4 лип 2024
- Check our Website:
In case you are thinking to buy courses, please check below:
Link to get 20% additional Discount at Coding Ninjas: bit.ly/3wE5aHx
Code "takeuforward" for 15% off at GFG: practice.geeksforgeeks.org/co...
Code "takeuforward" for 20% off on sys-design: get.interviewready.io?_aff=takeuforward
Crypto, I use the Wazirx app: wazirx.com/invite/xexnpc4u
Take 750 rs free Amazon Stock from me: indmoney.onelink.me/RmHC/idje...
Earn 100 rs by making a Grow Account for investing: app.groww.in/v3cO/8hu879t0
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
---------------------------------------------------------------------------------------------------------------------------------------------------- In this video, the Segment Tree Data Structure has been discussed.
Please donate to save someone's life: www.ketto.org/fundraiser/i-ne...
Proof: www.quora.com/Why-does-4-*-N-...
Striver's Linkedin Profile: / rajarvp
Instagram(I reply mostly here): / striver_79
Connect with us: t.me/Competitive_Programming_tuf (Use Link in Mobile only)
#FundRaiser #SegmentTree #Tutorial
This is so great that our coders community is helping to save someone's life . A great fan of yours sir . This is highly appreciated .
Super clear explanation. Loved the structure and the flow, keep it up.
Striver you really won my heart bro.....The cause is really worth donating. And I surely would. Having said that would you please try to make videos on SPOJ problems like GSS1, GSS2, GSS3, GSS4 and some other good problems on segments trees, like I many times find problem figuring out the merging conditions and even the updates when we are dealing with tougher problems, Striver would be really happy if u try making them.
I really appreciate this gesture of yours buddy.
Such a nice explanation on Segment Trees, You just removed my fear of Segment Trees!
Thank you so much Striver!
best segment tree lecture i can find. i was trying to learn it from last year
You are the best. Clearly explained
The way you explain was absolutely great.
kehna kya chahte ho hindi me bolo
Sir , It would be so great if you make a video on "How to stay motivated in CP and how to handle frustation" , i hope a lot of people need it .
One who explains tough concepts easily... 🔥
I personally felt this is the best video by striver.
Thank u Striver :)
No words to say .......He is the Absolute Best !
Fantastic explanation!!
Love your video...nice gesture
What a great coder, i hope he gets into a good mnc such as google, keep it up 👍
Update Code based on the above video code-
void add(vi&arr, int val,int tidx, int idx, int low, int high){
if(high == low && high == tidx){
seg[idx] += val; return;
}
seg[idx]+= val;
int mid = (low+high)/2;
if(tidx>=low && tidx=mid+1 && tidx
Really nice from you Striver . It would help him a lot . Continue your good work brother . The way you come forward to help others is really appreciable.
Wonderful Explanation 👌
Please continue uploading about advanced DSA
Thank u. Nice explanation and good code demo.
Nice video. Please upload lazy propagation too.
So on point, loved it
keep it up......great video on segment tree...
Thanks a ton
Amazing explanation!
This is the best and the simplest explanation i saw !!
Now, this is best content!
Thank you sir.
Excellent.. One of the best and precise explanation. Thank you 😊😊
Crystal clear explanation! Thanks bro!
Crystal clear explanation..✔️💯
how is segment tree different or useful from sparse table?
I want to edit any value in logn time.
Good initiative bro. I dontated my Part. Keep inspiring Us.
Segment Tree use to scare me but not anymore , thank you. this video deserves more like.
what about update_query_on_a_given_range?
Really nice gesture from you❤️
👑
Thanks
Clean explanation!! Understood in 1 go. Thanks..
Amazing man !! Just an amazing explanation
Really appreciable...thanks a lot sir.
where do I get this code?
Thank youu !!
you haven't write function for update operation
bro can u please tell is it possible to return the index of the maximum element within a given range??
store in terms of pair
Please made some video on javascript.
Thanks for saving time
Happy to help
Very nice explanation
Understood!!
great one..
Dude you are just awesome👍🏻, thanks
Thankyou..
Daa after this plz make video on lazy propogation there is no proper video on youtube..
great video
Perfect :)
Can you please make a video on range update query also!
yeah i will
@@takeUforward did you make one?
Striver is Legend For a Reason
We use array for storing value in segment tree .It is possible some index in middle of the array is empty?
Yeah might be..
but we will never access it
and won't ever have to
@@ojasdighe991 Nice meeting you here mamu
What are you using to "write" on the screen?
Digital pad
take U forward Can you recommend one to buy? Not too expensive
Wacom
LIT
The best explanation!
very interesting topic well explained bro :D
Understood
Thank you sooo much sir!!
great sir
understood❤❤❤
❤❤❤
Very nicely explained👍
great video sir ji
Java code:
class SegmentTree {
static int arr[];
static int seg[];
static void build(int ind, int low, int high) {
if (low == high) {
seg[ind] = arr[low];
return;
}
int mid = low + ((high - low) / 2);
build(2 * ind + 1, low, mid);
build(2 * ind + 2, mid + 1, high);
seg[ind] = Math.max(seg[2 * ind + 1], seg[2 * ind + 2]);
}
static int findMax(int idx, int low, int high, int l, int r) {
if (low >= l && high r)
return Integer.MIN_VALUE;
int mid = low + ((high - low) / 2);
int left = findMax(2 * idx + 1, low, mid, l, r);
int right = findMax(2 * idx + 2, mid + 1, high, l, r);
return Math.max(left, right);
}
public static void main(String[] args) {
arr = new int[] { 8, 2, 5, 1, 4, 5, 3, 9, 6, 10 };
int n = arr.length;
seg = new int[n * 4];
build(0, 0, n - 1);
// System.out.println(Arrays.toString(seg));
int q1 = findMax(0, 0, n - 1, 1, 4);
int q2 = findMax(0, 0, n - 1, 3, 8);
int q3 = findMax(0, 0, n - 1, 4, n - 1);
System.out.println(q1 + " " + q2 + " " + q3);
}
}
0:00 - 7:05
9:17 - 12:04
bhai maza aa gya video dekh kr
bahi maja agya , kya explain kiya hai
US
Simply awesome
Which software or pen table do you use for making videos?
osm
Hey striver tell them not to keep any prize money for the contest and keep tell them to donate entry fees for the same
Entry fees will be donated.
Bro, you missed the part on how to calculate the number of nodes in segment tree given the Array. That's one of the most important parts to understand when it comes to segment tree.
Isn't it the same as space taken in seg[ ] array, i. e. 4*n
@@GuitarCoversByRavi it should be 2n-1
*Hey striver, we'll participate for sure but i have a request that whatever amount their college mates get, please tell them to donate all of that money directly to Tarun not through that ketto app because that fundraiser organisation charges 10% of whatever they make through that platform.*
*Bold*
Okay we will look into it thanks for your suggestion/concern.
@@ShubhamSHARMA-oi4xf what happened to that boy is he okay now?
Do product based companies ask segment tree questions?
NO
@@takeUforward Google did
3 years after now it became a regular question
just awesome 3000
Please also make a video on sparse table data structure
i thought its a very hard topic but its easy but times consuming during contest
Hi frist
aye su che
wasn't this supposed to be one of the toughest concepts :(
First comment!!!