Тёмный

Binary Search Algorithm | C Programming Example 

Portfolio Courses
Подписаться 226 тыс.
Просмотров 56 тыс.
50% 1

An implementation of the binary search algorithm in C. Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!

Опубликовано:

 

1 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 85   
@parinrava978
@parinrava978 11 месяцев назад
I love your videos. I have a midterm tomorrow on uni course C programming and I have been watching many videos about this topic and nobody can describe it well like you do. I used to hate C cause I didn't understand anything but after watching your videos everything makes sense. It's very detailed and contains only information that we need to know in order to understand the concept. Thank you so much for great work.
@PortfolioCourses
@PortfolioCourses 11 месяцев назад
I’m glad you enjoy the videos, thank you so much for leaving this nice comment and good luck on your midterm! :-)
@eugeneplay9416
@eugeneplay9416 2 года назад
Love your videos. Really easy to follow along and very good explanations.
@PortfolioCourses
@PortfolioCourses 2 года назад
Thank you very much Eugene, I'm glad to hear you enjoy the videos! :-D
@johnofalltrades2000
@johnofalltrades2000 Год назад
the mathematical operation presented in the line: int mid = l + (r - 1) / 2; doesn't work for me. My compiler seems to go out of memory bounds because of this. I've tried: int mid = (l + r) / 2; and it worked.
@PortfolioCourses
@PortfolioCourses Год назад
It should be: int mid = l + (r - l) / 2 So it's an l not a 1. It's more complicated, but it's actually better to do it this way instead of (l + r) /2, see this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-JNFGvjATOUA.html
@johnofalltrades2000
@johnofalltrades2000 Год назад
@@PortfolioCourses oh I see now, what a silly mistake. thank you so much for clarifying it for me.
@PortfolioCourses
@PortfolioCourses Год назад
No problem! :-)
@aditopguy9785
@aditopguy9785 11 месяцев назад
Thank you for putting in the time and effort to make these videos. You are explain concepts so well, way better than my university lecturer
@PortfolioCourses
@PortfolioCourses 11 месяцев назад
You’re very welcome, I’m glad you’re enjoying the explanations! :-)
@germankoga8640
@germankoga8640 3 месяца назад
I didn't understand how you calculated mid, wouldn't you have to sum the two extremes and divided them by 2 to find the mid point?
@Aaron-hh8nx
@Aaron-hh8nx Год назад
#include using namespace std; int main() { int LIST[25],MAX; int FIRST, LAST, MIDDLE, I, ITEM, LOC=-1; coutMAX; cout
@PortfolioCourses
@PortfolioCourses Год назад
That looks like the correct C++ solution to me. :-) Maybe I should make a C++ version of this video too though, that would be fun.
@Aaron-hh8nx
@Aaron-hh8nx Год назад
@@PortfolioCourses please do, it's from my school text book
@PortfolioCourses
@PortfolioCourses Год назад
Cool! :-)
@loginashaalan2826
@loginashaalan2826 4 месяца назад
what if the value needed is less than all the elements of the array does we do the same as return -1?
@ostryy0560
@ostryy0560 Год назад
Thanks my man. I am preparing for a test, and this video helped me AF. Greetings from PL 🇵🇱
@PortfolioCourses
@PortfolioCourses Год назад
That's awesome I'm glad to hear it helped you out! And good luck on that test! :-)
@veggieveggie1215
@veggieveggie1215 6 месяцев назад
what microphone do you use?
@OumaamarIsra
@OumaamarIsra 4 месяца назад
Thank you man you save my life
@FeroLight-e2n
@FeroLight-e2n Год назад
That was amazing .Thank you
@maven5463
@maven5463 2 года назад
Hmm, Can't we just write mid = (l + r) / 2 🤔
@PortfolioCourses
@PortfolioCourses 2 года назад
Great question! 😀 You could do it that way too, though what we do in this video is better in terms of preventing an integer overflow: stackoverflow.com/questions/25113506/why-m-l-r-l-2-instead-of-m-lr-2-avoid-overflow-in-c.
@maven5463
@maven5463 2 года назад
@@PortfolioCourses oh, understood now. The video was so helpful! 😄 Thank you.
@PortfolioCourses
@PortfolioCourses 2 года назад
You’re welcome! :-)
@SouvikMandal-tl2to
@SouvikMandal-tl2to 5 месяцев назад
a better breaking condition for the binary search would be if(l == r) rather than if(l>r) i think !
@adamsetterberg5223
@adamsetterberg5223 2 года назад
Love the video!
@PortfolioCourses
@PortfolioCourses 2 года назад
This number guessing game might be close to what you're looking for: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-41NmcgA1HF0.html And to my knowledge we can't really use binary search on an unsorted array, unless we sort it first. Here are some folks explaining why: www.quora.com/Can-binary-search-be-applied-on-unsorted-list
@erennkose
@erennkose Год назад
bro thank you so much
@PortfolioCourses
@PortfolioCourses Год назад
You're welcome Aaron! :-)
@athunasos1649
@athunasos1649 9 месяцев назад
Using a loop is more memory efficient than using a recursive function
@elfullin
@elfullin 4 месяца назад
I like that you used recursive methods. Thank you
@pvcksubhashini4984
@pvcksubhashini4984 2 года назад
Very Nice Content Useful to all Plz make subtitles in english (In this video Subtitiles r translating in dutch when converted to english it doesn't make sense) Plz make C++ also , u r explaining very nice!!
@PortfolioCourses
@PortfolioCourses 2 года назад
That's so weird that it auto-generated the subtitles to Dutch! Thank you for letting me know, I will see if there is anything I can to do fix that. :-) Also, I have now started a series of C++ videos as well: ru-vid.com/group/PLA1FTfKBAEX6BdpNaWp2uw-YspHwY7qwW
@pvcksubhashini4984
@pvcksubhashini4984 2 года назад
@@PortfolioCourses Ya i saw that one also I shared to my friends too. Thanks for the Content ☺
@PortfolioCourses
@PortfolioCourses 2 года назад
It's interesting, but I'm not sure RU-vid will allow me to "re-generate" the subtitles as English. I may need to upload my own or something, what a pain!
@TSkateT666
@TSkateT666 2 года назад
have an exam soon in "Introduction to C" course in uni, this really helped alot!
@PortfolioCourses
@PortfolioCourses 2 года назад
Awesome, I’m glad to hear it was helpful! And good luck on your exam! :-D
@adamsetterberg5223
@adamsetterberg5223 2 года назад
Hello Again! I having a problem with binary searching...... So lets say that you tell you computer to "random generate" 10 numbers between 1 - 20. And you want to know if the number 7 have been generated. Do you need to bubble sort first before you use binary searching?
@PortfolioCourses
@PortfolioCourses 2 года назад
Yes, the list needs to be sorted before you can use binary search. You could use bubble sort, or you could use something like insertion sort, selection sort, quicksort, or merge sort. In terms of performance, for very small arrays like this, using insertion sort or selection sort would be best (better than bubble sort too). For larger arrays, using something like quicksort or merge sort would be better. We have videos on all these aglorithms too: Insertion Sort: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Tz7vBodZqo8.html Selection Sort: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-YepJ7fDmyjI.html Quicksort: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-0jDiBM68NGU.html Merge Sort: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-LeWuki7AQLo.html
@haniforange
@haniforange 8 месяцев назад
2 hours before final exam wish me luck
@PortfolioCourses
@PortfolioCourses 8 месяцев назад
Good luck! :-)
@Muaz_tofik
@Muaz_tofik 8 месяцев назад
Lol sameeee 🫣
@epicgameryt4052
@epicgameryt4052 Год назад
You're actually kinda awesome, thanks!
@PortfolioCourses
@PortfolioCourses Год назад
Aww thank you so much, I really appreciate that! :-)
@mongraal2272
@mongraal2272 2 года назад
Thaaaaank you...i I watched this video for 3 hours and i finally understood...thank u,ur logic is so impressive
@PortfolioCourses
@PortfolioCourses 2 года назад
You’re welcome, I’m glad you figured it out! :-)
@Code-nv8xl
@Code-nv8xl 8 месяцев назад
Why you didn't use that unsorted array searching :/
@elfullin
@elfullin 4 месяца назад
Because you can’t use binary search on an unsorted array.
@emeziekejedidiah5547
@emeziekejedidiah5547 2 года назад
This video is great
@PortfolioCourses
@PortfolioCourses 2 года назад
Thank you! Very glad to hear you enjoyed it! :-D
@softvampir3
@softvampir3 4 месяца назад
Watching this video for class - please please turn on subtitles at least auto subtitles it takes no work and saves many people who are watching.
@PortfolioCourses
@PortfolioCourses 4 месяца назад
The video does have auto subtitles, you just have to click the gear icon in the top-right to enable them. :-)
@softvampir3
@softvampir3 4 месяца назад
@@PortfolioCoursesNo actually when I click the gear icon I see: "Stable Volume" ; "Ambient Mode" ; "Playback speed" ; and "Quality" there is no closed captions or subtitles on the gear icon. Next to the gear icon on the left is "cc" button which is greyed out and when I hover over it the message reads -> "Subtitles/closed captions unavailable".
@PortfolioCourses
@PortfolioCourses 4 месяца назад
Weird, what type of device/software are you using? I'm using Firefox on MacOS. I'm thinking it could be a difference related to using web vs. app or something like that.
@SurajBhandari-px1rv
@SurajBhandari-px1rv 4 месяца назад
​@@PortfolioCoursesIts not available in my device too
@PortfolioCourses
@PortfolioCourses 4 месяца назад
What type of device are you using?
@bieelzzin
@bieelzzin Год назад
Thank you! Perfect explained
@PortfolioCourses
@PortfolioCourses Год назад
You're welcome Gabriel, I'm glad you enjoyed it! :-)
@magdugalrexon7234
@magdugalrexon7234 2 года назад
Thank you for the video. It was really helpful.
@PortfolioCourses
@PortfolioCourses 2 года назад
You're welcome! I'm glad to hear it was helpful for you. :-D
@Mnogojazyk
@Mnogojazyk 2 года назад
Love your videos. Finally do I understand the concepts! Many thanks!
@PortfolioCourses
@PortfolioCourses 2 года назад
You’re very welcome! :-D
@RelAxGamingKing77
@RelAxGamingKing77 2 года назад
Thank you so much, really helped me out!
@PortfolioCourses
@PortfolioCourses 2 года назад
You're very welcome, I'm glad to hear it helped you out! :-D
@omatzi7251
@omatzi7251 10 месяцев назад
Great video and great teacher!
@PortfolioCourses
@PortfolioCourses 10 месяцев назад
I’m glad you enjoyed the video and teaching! :-)
@CSstudent_1001
@CSstudent_1001 11 месяцев назад
Thank u a lot 🌸
@PortfolioCourses
@PortfolioCourses 11 месяцев назад
Your very welcome! :-)
@nazaraljendli9758
@nazaraljendli9758 2 года назад
best c tutorials out there thank you
@PortfolioCourses
@PortfolioCourses 2 года назад
You're welcome Nazar! 😀 And thank you very much for the positive feedback too.
@idanmariani8601
@idanmariani8601 Год назад
your awsome :)
@PortfolioCourses
@PortfolioCourses Год назад
Aww thank you Idan! :-)
@DeadPool-jr2er
@DeadPool-jr2er 2 года назад
I love it!! Thank you!
@PortfolioCourses
@PortfolioCourses 2 года назад
You're very welcome! :-)
@juanmacias5922
@juanmacias5922 2 года назад
Great video! Explained super well!
@PortfolioCourses
@PortfolioCourses 2 года назад
I’m glad you enjoyed it Juan! :-
@dabawocks1121
@dabawocks1121 2 года назад
Thank you for this
@PortfolioCourses
@PortfolioCourses 2 года назад
You're welcome! :-D
Далее
Learn Binary Search in 10 minutes 🪓
10:04
Просмотров 114 тыс.
ОБЗОР НА ШТАНЫ от БЕЗДNA
00:59
Просмотров 391 тыс.
Airpod Through Glass Trick! 😱 #shorts
00:19
Просмотров 647 тыс.
Dynamic Memory Allocation | C Programming Tutorial
31:51
Merge Sort | C Programming Example
18:02
Просмотров 79 тыс.
Compiled Python is FAST
12:57
Просмотров 111 тыс.
Being Competent With Coding Is More Fun
11:13
Просмотров 84 тыс.
Create a copy of an array | C Programming Example
11:33
C++ Programming: Linear Search Algorithm
14:14
Просмотров 174 тыс.