Binary Search with C++ STL | 4 Problems followed up | Lower Bound and Upper Bound explained
ฝัง
- เผยแพร่เมื่อ 5 ต.ค. 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.geeks...
Code "takeuforward" for 20% off on sys-design: get.interviewr...?_aff=takeuforward
Crypto, I use the Wazirx app: wazirx.com/inv...
Take 750 rs free Amazon Stock from me: indmoney.oneli...
Earn 100 rs by making a Grow Account for investing: app.groww.in/v...
Linkedin/Instagram/Telegram: linktr.ee/take...
---------------------------------------------------------------------------------------------------------------------------------------------------- Binary Search is one of the most widely used algorithms in programming. Its good to know some shortcuts which saves a lot of time in Contests. However, in interviews it is highly advised to code Binary Search.
At 0:50 I said a+n points to the last element, it will be it points to after the last element, also the function takes range [Start, end). which means takes the starting element, and excludes the last element.
Please subscribe to the channel if you have not done it. Do leave a like and a comment, as TH-cam recommends videos with more likes and comments.
Join out telegram channel to interact directly with me. Thanks!
Link: t.me/Competiti...
the end pointer points to the element after the last element, like a.end() will point to the element after the last element.. also a + n will point to the nth element (which doesn't actually exist, it's a theoretical end position).. the pointers point like [start, end)..
Yeah I missed it I know this one that a.end() points to after the end element. Did not check out for a+n, thanks for the update, will pin this comment.
Ok, a+n also points to the element after last element, which does not occur in the array....
@@takeUforward op 🎉 to 🎉🎉 to
@@manishshee6990 it exists but its a null operator
you got the point rite?
Whether you are doing an interview or working on your project, always stick to the STL. The algorithms in STL are written in the most optimized way. They can outperform the same algorithms written in C. That’s the promise of STL: either it runs faster than C code or at least not slower than C.
The way you simplified the explanantion is amazing!
Truly!
Learn the entire C++ STL here, th-cam.com/video/zBhVZzi5RdU/w-d-xo.html.
Note: the end pointer points to the element after the last element, like a.end() will point to the element after the last element.. also a + n will point to the nth element (which doesn't actually exist, it's a theoretical end position).. the pointers point like [start, end)..
what a coincidence sir I was learning this STL a few minutes ago and you make a video on this thanks a lot sir!!
Same
hui placement ?
@@KrishnaSharma-bv5ys Han Bhai 1 saal pahle hi I'm now a software engineer at UHG
@@deepakkoushal56 Congo Sir 🙏🏻
@@KrishnaSharma-bv5ys thanks
9:20 in this we could write index instead of -1 in the else statement in cout
Yesterday I was getting TLE on a problem because I was doing linear search , and decided to learn binary search and here it is !
Undoubtedly the best video tutorial on the topic ❤️❤️❤️ Good job @Striver
You must have a job till now na?
@@harshdasila6680 he's working in samsung now
@@nostalgiccringeallhailchel3881 then refer me
How someone can explain with this ease....thanks bhaiya
the upper bound condition check should be like this. you missed the -1 from index.
if( ind >= 0 && [ ind - 1 ] ==x)cout
i did not get the boundary conditions are not they written opposite. I am confused
he already did i - - before writing a[ind]==X; Check.
No kidding , You really explain very well . Thank you for all these videos . Really very helpful!!!!
I was confusing lower bound with floor value. thank you so much!
Awesome explanation bro...
Please try to make more videos on STL..
Thank you
A complete tutorial on how to learn stl in 30 minutes coming your way.
@@takeUforward Tq bro...
That's awesome.. 😍
You literally speak like the girl in the American Pie who kept saying:
"Aah,.... that one time, ..at Band Camp"😂😅.
But you really are a solid teacher.. loved the video.
Should the array be previously sorted to perform lower and upper bound
Yes, every question states sorted array.
thank you srila prabhupad, krishna and sir
You are a gem 💎💎💎
Wonderful demonstration of stl binary search
Lower_bound(start_ptr, end_ptr, num) STL in c++ has one weird return value
If it doesn't find the value 'num' it returns the immediate higher number value of num. What is the use of this new higher value ?
If u want to just find the number greater irrespective whether that element is present or not
The video is really good. I think you should make videos on the algorithms and techniques also. It helps a lot of students because your teaching is good.
i have a question can we use stl in job interviews ??
This was great video. Can you make videos about Binary Search algorithm on monotonic function and modified version of it.
Banda achha explain karta hai!
Please upload more dynamic programming videos
+1
Sorry bro, I am really buzy with my ongoing schedule, but then I have plans on launching a series on Atcoder DP problems soon.
+1
@@takeUforward that's great even coding blocks have made it a paid course of problems in atcoder pls bro start the series as soon as possible
Amazing the problem set as well as explanation
Amazing videos. I'm actually the first one to watch all the videos you make. Thank You!
For question 2, tell me a case where ind will be less than 0 . There will be no case when ind will become less than 0. Lets say, we passed X=1 in this questions. upper_bound will return iterator pointing to element "4" which is located at index 1. We will do ind-- , so finally our ind will become ind = 0. I can't think of a case where ind will be less than 0. So I think even if we remove ind>=0 from the if condition program will do fine. Please do reply if anyone understood what I'm trying to say.
x
If we find upper bound for 0 then ind will be 0
Pls make video on complete stl in detail like this one,
Amazing video 🙂
Made, check in channel
@@takeUforward as i have started learning programming, problem that i face is when i start one topic in data structures, in question(medium) they use some algo which i don,t know, wheni start algo problem solving(medium), they use data structure with it so all this make path confusing, can u make video on this?
Thanks vaiya.. Implementing on BS was too complex.. These will definitely help..💫💫💫😇
Thank you very much. You are a genius. 👍👍👌👌🙏🙏🔝🔝
Really Helpful , Thank you !
Maja agya bhai bahut kam ha chiz hai
does upper_bound() and lower_bound() work only for sorted vectors / arrays?
Yes
is it possible to find upper_bound and lower_bound in an unsorted array?
No works only in sorted array
Extremely helpful thanks a lot🙂
hi bhaiya can you make some videos on c++ stl it is very confusing to learn from online articles plz make these videos its a humble request
if the iterator goes out of range does it returns garbage val
Really you are a hero. Thanks for such a nice explanation. We even don't require the long geeks code after seeing your video.
Very good video.. I like ur way of teaching.. Pls make more such quick and topic specific video..
liked and subscribed ur channel
Why do we do (-a) for taking out the index of lower bound or upper bound....plzz answer i am stuck here
In the line ...int ind= upper _bound(a,a+n,X) -a;
Because it returns an iterator, so to get the index we subtract starting indez
@@takeUforward one more thing I still have a doubt sir suppose the iterator is 4 so when we subtract the iterator from a(a is the first address of the array right?) So suppose (4- address of a) so as a is the address of first element right so again if we substract 4 then something else is coming
Sorry I am thinking this way so I am stuck...I think I am thinking wrongly I know
So sir plzz elaborate it a little more nd what wrong I am thinking...plzz sir
@@salonikarki1462if the address of first element is 1612 then second element will be 1613 and so on, its consecutive. Hence you get 0-based indexing on subtraction.
@@takeUforward oo yes yes bro thank you very much now I understood...I was subtracting index value with address instead of subtracting address value with first address to get the index...thank you very much😇
@@takeUforward sir How 1612's next address is 1613
why it is not 1616
Bro do more STL videos which helps in CP.
ur lower bound explation is wrong it gives just smaller index but u told it give us >= index please checj it again
thank u so much for this wonderful video
Thanks a lot brother i will be always greatfull for your video
Very nice bhaiya 👍
Extremely helpful thanks a lot
Explained really well!
Thank you very much
Well explained Thankyou.
very well explained thank you : )
Thanks Raj bhaiya.
Awesome.
thank you
Wow bhai, learned something new
Thank you.
thank you, sir
can you please make some videos of python?and also div 4 solutions?
Great quality content 👌
Well explained!
Thanks a lot sir
Amazing Video 😀😀♥♥
ek hi to dil hai kitni baar jeetoge Striver 😇❤
again this video also completed god or wott brother😎😜😎
great video sir ...
Bro, plzz make videos on segment tree, Fenwick tree, trie.
Thanks bhaiya for this video
understood! well
tq
bro no one explain like you
3 march 2022 10-30am
Thanks for taking us forword ❤️😁
Our pleasure!
Very helpful as always!
👍👍👍keep going striver bhai...
understood
THANKS ,,GREAT VIEDO
just wow.....
Understood
Nice Bhaiya
while(1)
{
cout
Compile Error ... Headerfiles not included ..
Extraordinary explanation 🔥🔥
Thanks striver
Best🔥
❤
Striver OP
King 👑👈
Nice explanation striver
❤️❤️
💙💙
gold
Thank you bhaiya __/\__
halpful
Great video...fuk scalar fraud
Thank You