Binary Search with C++ STL | 4 Problems followed up | Lower Bound and Upper Bound explained
Vložit
- čas přidán 7. 05. 2020
- 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
---------------------------------------------------------------------------------------------------------------------------------------------------- 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 CZcams recommends videos with more likes and comments.
Join out telegram channel to interact directly with me. Thanks!
Link: t.me/Competitive_Programming_tuf
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 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?
Learn the entire C++ STL here, czcams.com/video/zBhVZzi5RdU/video.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)..
The way you simplified the explanantion is amazing!
Truly!
Wonderful demonstration of stl binary search
Yesterday I was getting TLE on a problem because I was doing linear search , and decided to learn binary search and here it is !
9:20 in this we could write index instead of -1 in the else statement in cout
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
Amazing the problem set as well as explanation
How someone can explain with this ease....thanks bhaiya
Very good video.. I like ur way of teaching.. Pls make more such quick and topic specific video..
liked and subscribed ur channel
Extremely helpful thanks a lot🙂
I was confusing lower bound with floor value. thank you so much!
Really Helpful , Thank you !
very well explained thank you : )
Thank you very much. You are a genius. 👍👍👌👌🙏🙏🔝🔝
Banda achha explain karta hai!
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
Extremely helpful thanks a lot
Thanks a lot brother i will be always greatfull for your video
No kidding , You really explain very well . Thank you for all these videos . Really very helpful!!!!
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 are a gem 💎💎💎
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.
thank you srila prabhupad, krishna and sir
Well explained Thankyou.
i have a question can we use stl in job interviews ??
Explained really well!
thank u so much for this wonderful video
Thanks vaiya.. Implementing on BS was too complex.. These will definitely help..💫💫💫😇
Thank you very much
Bro do more STL videos which helps in CP.
Great quality content 👌
Wow bhai, learned something new
Very nice bhaiya 👍
Thanks a lot sir
Thanks bhaiya for this video
if the iterator goes out of range does it returns garbage val
Amazing videos. I'm actually the first one to watch all the videos you make. Thank You!
Well explained!
Thanks Raj bhaiya.
great video sir ...
Really you are a hero. Thanks for such a nice explanation. We even don't require the long geeks code after seeing your video.
thank you, sir
Thank You
Awesome.
Maja agya bhai bahut kam ha chiz hai
This was great video. Can you make videos about Binary Search algorithm on monotonic function and modified version of it.
Should the array be previously sorted to perform lower and upper bound
Yes, every question states sorted array.
tq
thank you
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
Thank you.
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
bro no one explain like you
Thanks for taking us forword ❤️😁
Our pleasure!
again this video also completed god or wott brother😎😜😎
Amazing Video 😀😀♥♥
is it possible to find upper_bound and lower_bound in an unsorted array?
No works only in sorted array
understood! well
just wow.....
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
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.
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.
THANKS ,,GREAT VIEDO
👍👍👍keep going striver bhai...
Nice Bhaiya
does upper_bound() and lower_bound() work only for sorted vectors / arrays?
Yes
Best🔥
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
3 march 2022 10-30am
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
Very helpful as always!
Extraordinary explanation 🔥🔥
Understood
ek hi to dil hai kitni baar jeetoge Striver 😇❤
ur lower bound explation is wrong it gives just smaller index but u told it give us >= index please checj it again
❤️❤️
Thanks striver
Striver OP
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?
💙💙
while(1)
{
cout
Compile Error ... Headerfiles not included ..
King 👑👈
Bro, plzz make videos on segment tree, Fenwick tree, trie.
can you please make some videos of python?and also div 4 solutions?
gold
halpful
Thank you bhaiya __/\__
Nice explanation striver
Great video...fuk scalar fraud