C++ Programming: Binary Search Algorithm

Поделиться
HTML-код
  • Опубликовано: 21 янв 2025

Комментарии • 146

  • @yasina63
    @yasina63 2 года назад +3

    I have seen the Linear search algorithm you completely figured out for me. Your teaching way is a piece of cake.
    Watching from Ethiopia. Thanks a bunch.

  • @studyfreak8429
    @studyfreak8429 9 месяцев назад +5

    this is year 2024 and this stuff is still relevant, man c++ IS evergreen

  • @christianvillamor6273
    @christianvillamor6273 11 лет назад +34

    WOW. Thank you! Programmers tend to be really snobby when it comes to helping. WE NEED MORE PROGRAMMERS LIKE YOU!

  • @uzumaki9t
    @uzumaki9t 8 лет назад +24

    Very well explained. I thought binary search was something awful when I saw it on my last exam. Thank you very much!

  • @mbulelogumede6903
    @mbulelogumede6903 Месяц назад

    Out of all programmers I've listened to, you're the best.

  • @mountgraph1403
    @mountgraph1403 6 лет назад +1

    Pls dont stop making this videos. They really help!

  • @davidporterrealestate
    @davidporterrealestate 7 лет назад +178

    Thank God you have an American accent

  • @opiumslave
    @opiumslave 5 лет назад

    I've my Computer Science boards practical exam on 1st Feb. U helped me a lot.... Thanks man

  • @NatsukiSY
    @NatsukiSY 3 года назад +1

    I love you man
    Even my doctor couldn't make it this simple

  • @rajcodes100
    @rajcodes100 7 лет назад +1

    Thanks so much - I have listened to your videos on arrays and passing arrays to functions - now I finally think I get the concepts - the explanations were clear and systematic - keep posting more videos - kudos sir for sharing your knowledge in a way that communicates to the student.

  • @marik996
    @marik996 Месяц назад

    If all your videos explain stuff this well then i am lucky to have found your channel def going to sub

  • @babbalgts
    @babbalgts 8 лет назад

    you are good at teaching...... i didn't find any video that made it as clear as you did!.... thanks a lot;... coz tomorrow is my 12th grade final exam.

  • @eaglebaize
    @eaglebaize 12 лет назад +2

    Thank you so much! I have a comprehensive c++ final today (it will cover material from both this and the previous semesters). Cheers!

  • @lamp_x
    @lamp_x Год назад +1

    So basically, we can't do binary search if the array isn't sorted from low to high?
    Unlike linear search that can do even though if the array isn't sorted (random number)

  • @grigorebordea1212
    @grigorebordea1212 6 лет назад +2

    Thank you so much i've tried to understand this algorithm for 2 days even though this isnt that hard

  • @vulcuemil4367
    @vulcuemil4367 4 года назад +6

    When dealing with huge arrays you risk to overflow when calculating mid. A safer way is: mid = low + (high - low) / 2 .

    • @Asterite
      @Asterite 3 года назад

      what does overflowing mean?

  • @sakspan3265
    @sakspan3265 10 лет назад

    Sir can you explain why there is high = size-1 because I am little bit confuse. What is the use of high = size-1?
    10:01

    • @aarjavbaxi2299
      @aarjavbaxi2299 4 года назад +1

      Here, size stands for the number of elements in the array ; So according to that , your high index value would be 1 less than the number of elements.

  • @corrondo25
    @corrondo25 9 лет назад

    watch 4 videos looking for a simple detail concerning the algorithm. You had it.

  • @delvindavid2804
    @delvindavid2804 8 лет назад

    Thank You so much Derek, I wouldn't be able to answer this question in exam ,if I had not found your channel!

  • @cristopheririas1509
    @cristopheririas1509 6 лет назад

    I really love your way of explaning. I should tell you I am not a native English Speake however, I've been able to understand most. Congratulation !!!! pd: GREETINGS FORM HONDURAS!

  • @WalterCueva
    @WalterCueva 10 лет назад

    I have a Two-Dimensional Arrays. Do you have a video showing how to use linear and binary search on a Two-Dimensional Arrays?

  • @rafiullahqallander
    @rafiullahqallander 9 лет назад +1

    I just can say, you are THE BEST.
    Many thanks for your great contribution, May God bless you :)

  • @spicytuna08
    @spicytuna08 6 лет назад

    with C++, there is no need for binary search. Just store data into set STL data structure and use its set::find() member function. But thanks for explaining binary search algo.

  • @snipere2009
    @snipere2009 9 лет назад

     Using a C++ array of STRUCTUREs, write a program that takes input of student information - for 10 students - like:
    1) Student ID.
    2) Student name.
    3) Course marks (5 courses for each student).
     The program provides below functionality:
    1) Show all records.
    2) Search and display a student record on ID.
    3) Modify the record of a particular student.
    4) Show the passing percentage for each course.
    5) Show the names of students who failed in a particular course.
    6) Show the total marks, the percentage, and the overall letter grade for individual students.
    7) Show the names and the letter grades of all students in each course.
    9) Show the student names for each letter grade in each course [ A >= 90% - B >= 80% - C >= 70% - D >= 60% - F < 60% ].
     It is required to write a modular program.

  • @Lolablue1986
    @Lolablue1986 7 лет назад +1

    Great video been looking for something like this all day lol

  • @stevezes
    @stevezes 5 лет назад +1

    your mid point calculation can cause overflow

  • @aarjavbaxi2299
    @aarjavbaxi2299 4 года назад +1

    It was really cool ! But here is the question though : What if the list/array is unsorted ; I mean if there is a large search space , say 50000 elements ; would we be able to sort it manually ? - NO. So, why don't we have a function for sorting too?
    Thinking practically , there are not gonna be arrays with just 8 or 10 or 50 elements, so i think we need it.
    Comment down your thoughts on this. :)

    • @LandonGernand
      @LandonGernand 4 года назад +2

      there are functions for sorting collections called sorting algorithms. there are a lot of good videos on youtube about them

  • @bluesaint9163
    @bluesaint9163 8 лет назад

    How could I store all the words in my project? if I will go for a dcitonary?

  • @ledues3336
    @ledues3336 7 лет назад

    10:32, what if an overflow happens?

  • @robbiecastillo7495
    @robbiecastillo7495 8 лет назад +3

    Well done sir! Very helpful.

  • @talhaghaffar1324
    @talhaghaffar1324 10 лет назад

    my great video lecture ever...

  • @stephenkamenar
    @stephenkamenar 11 лет назад

    Oops, I think that was just a typo on my part and it still doesn't work, right?

  • @alsayedalsisi2709
    @alsayedalsisi2709 7 лет назад

    But now what would the purpose of the binary search algorithm if the array is not sorted?? The binary search algorithm forces you to have the array sorted, and if you have to sort the array then it would be faster to use linear search than sorting then searching the array.

    • @aNz0r2
      @aNz0r2 7 лет назад

      Let's assume that you have your target value at the end of your brute (unsorted) array. Linear search will be in worst case, which will give maximum complexity. Meanwhile, a quicksort function before using binary search will be much more efficient, as the complexity will be at least modest.
      Sorting an array doesn't always mean using 2 for() loops.

    • @nexgen2816
      @nexgen2816 7 лет назад

      you can use bubble sort algorithm to sort it before search

  • @1314rom
    @1314rom 10 лет назад

    Awesome video. Clear and to the point.

  • @aovlover415
    @aovlover415 7 лет назад

    well done explained. Should the number sequence ? coz i try random number and false answer.
    what is your application ? i'm using borland 5.02 ,about your code 'using namespace std' ,borland say that 'namescpace name expected'
    i'm bit consfused, please answer :)

  • @billzhang1892
    @billzhang1892 12 лет назад

    Thanks very much for so simplified and excellent lecture!

  • @snyfalcryo524
    @snyfalcryo524 4 года назад

    My question is, would binary search still works if there's double or more of the specific data you're looking for?
    If so, how/what's the algorithm?

    • @pendyalaabhishek6273
      @pendyalaabhishek6273 4 года назад

      for example if you are looking for 2 numbers you can give search value as input 2 times and run code 2 times ..

  • @kingsapo
    @kingsapo 12 лет назад

    Thanks a bunch, got really stuck on this, your video helped a lot!

  • @Gooneryz
    @Gooneryz 12 лет назад

    @ReelLearning you made it so simple and logical to understand.Thanks for the video it helped me a lot. :) By the way what is the program you're using to write the code and compile it?

  • @ranjhi369
    @ranjhi369 12 лет назад

    excellent and simplified presentation. thanx

  • @DesignAndDevops
    @DesignAndDevops 2 года назад

    What about last element

  • @AhmedHadiPADI_scuba_instructor
    @AhmedHadiPADI_scuba_instructor 7 лет назад

    what the result of log2(64000) represents ? i mean the 15.966. thanks a lot !

    • @phatchunk99
      @phatchunk99 7 лет назад +1

      It takes 16 loops to search a number within an array of 64000 numbers.

  • @weldejewergskahsay
    @weldejewergskahsay 8 месяцев назад

    admiration come it self if you competent like you .thanks

  • @talhaghaffar1324
    @talhaghaffar1324 10 лет назад

    sir 1 question can u tell me the name of your compiler. which u use in that video...

    • @gluedtogames
      @gluedtogames 10 лет назад +1

      Since he didn't ever get back to you, it's Eclipse.

    • @ledues3336
      @ledues3336 7 лет назад

      Gabe Payne that's not a compiler

    • @ledues3336
      @ledues3336 7 лет назад

      Talha Ghaffar gcc

  • @hokutoueda6215
    @hokutoueda6215 4 года назад

    you are wonderful person and i really like your videos.

  • @dawitmekuria5349
    @dawitmekuria5349 5 лет назад

    Sir, that's nice video but it not working for descending array values. Any solution for that?

    • @kkn5523
      @kkn5523 5 лет назад

      Reverse that array by storing it in another array like this:
      Say your original array is:array1[size];
      int array2[size],k=0;
      for(int i=size-1;i>=0;i--)
      {
      array2[k]=array1[i];
      k++;
      }
      Apply the sort on array2. That' s what i do. Hope it helps! You can also manipulate the binary sort algorithm but this method seems simpler

  • @TheVerbalAxiom
    @TheVerbalAxiom 9 лет назад

    Wonderful, perfect explanation.

  • @escaravar7417
    @escaravar7417 10 лет назад +1

    Thank you for this video, it's so helpful!!

  • @raghurammuthyala1023
    @raghurammuthyala1023 9 лет назад

    Great video! Amazing! Thank you for uploading sir!
    Sir which one do you think is the best compiler ( user friendly and easy to understand)?

  • @hyunbinpark3382
    @hyunbinpark3382 7 лет назад +1

    Thank you for posting!

  • @Brad6013-
    @Brad6013- 2 года назад

    You explained this very well. Thank you

  • @whateveriwannabe1
    @whateveriwannabe1 7 лет назад +1

    These are very helpful videos

  • @JBMJaworski
    @JBMJaworski 12 лет назад

    Thank you for sharing good quality teaching. :-)
    Regards!
    Jarek Jaworski

  • @kironsaha2679
    @kironsaha2679 4 года назад +1

    Amazing video, helped a lot for a project.

    • @abdurraheem2444
      @abdurraheem2444 4 года назад

      your project was based upon binary search only🤣🤣

  • @salehabuhussein5229
    @salehabuhussein5229 4 года назад

    what software do you use to run cpp file?

  • @stephenkamenar
    @stephenkamenar 11 лет назад

    Whoa, has nobody noticed that what he's showing doesn't even work? Using his example array, try searching for 55, or 98; it can't find it. The check for (low >= high) needs to be just after you check (value == arr[mid])

  • @ariskoutsoukis7849
    @ariskoutsoukis7849 5 лет назад

    Why you update low and high to mid+1 or mid-1; and not just update low or high to mid; see for 55 would much faster

  • @techwithehusain5967
    @techwithehusain5967 7 лет назад +1

    You are awesome. Honestly!!

  • @aliabid2839
    @aliabid2839 6 лет назад

    Great work man.

  • @debashismondal7536
    @debashismondal7536 8 лет назад

    what software are you using sir?

  • @hilaritas1544
    @hilaritas1544 9 лет назад

    Can anybody explain me, why "return -1"?

  • @markbones00
    @markbones00 11 лет назад

    i tried, 55 is at index 4 and 98 is at index 7...

  • @erictronic
    @erictronic 9 лет назад

    Thank you for great lesson!

  • @NadaAhmed-zx1ru
    @NadaAhmed-zx1ru 10 лет назад

    This was great and simply explained, than you :)

  • @roasted_guava5706
    @roasted_guava5706 5 лет назад

    This is so helpful! Thanks!

  • @jasonderero3922
    @jasonderero3922 8 лет назад

    what happened to you why did you disappear we missed you

  • @Kiran200002
    @Kiran200002 12 лет назад

    very nice presentation. Thankyou

  • @Jordan-og5kd
    @Jordan-og5kd 7 лет назад +1

    great explanation

  • @blind_neighbourhoodNerd
    @blind_neighbourhoodNerd 5 лет назад

    Thanks so much for this!!

  • @efim_bistrov
    @efim_bistrov 12 лет назад

    Thank you very much, it helped me with homework)

  • @notarealhandle123
    @notarealhandle123 10 лет назад

    This is an incomplete explanation, because you rely on your C++ compiler's functionality in converting variable mid into the index. You need to be explicit about what index is actually being used, because it may be different in other compilers and certainly in other languages, which in turn changes the algorithm outcome completely. Is it FLOOR, CEIL or ROUND? - one must know in order to adopt the algorithm in other systems.
    For example, in Java Script you have to make this change: mid = Math.round((low + high) / 2); otherwise the algorithm won't work.

    • @rehanasghar5181
      @rehanasghar5181 9 лет назад

      Vitaly Tomilov Do you read the title of this video ???
      It is about the binary search uses in C++ language , not in java ....

    • @notarealhandle123
      @notarealhandle123 9 лет назад

      rehan asghar These tutorials are all about algorithms, not C++ language. They are meant to be applicable to any platform. The fact that C++ helps them hide some of the very important logic of the algorithm doesn't really help others understand how it works.

    • @aarjavbaxi2299
      @aarjavbaxi2299 4 года назад

      @@notarealhandle123 Maybe you shouldn't have come here if you didn't want c++ to be the language .

  • @bermudatriangle94
    @bermudatriangle94 4 года назад

    dude you are amazing!

  • @kpippink
    @kpippink 10 лет назад

    Thank you for posting :D

  • @tarikabughalib1263
    @tarikabughalib1263 2 года назад

    Thank you so much this is unbelievable helpful

  • @fortunesuwedi6714
    @fortunesuwedi6714 Год назад

    Good explanation

  • @millionasseghegn770
    @millionasseghegn770 Год назад

    now my eyes are widely open

  • @rehanasghar5181
    @rehanasghar5181 9 лет назад

    Hey thanks for this great video. It clears my confusions
    Can you please tell me how do you edit this video?
    What software you were using to teach us by writing on screen ?

  • @braindeadjoe
    @braindeadjoe 10 лет назад

    Great work, this really helped me out thank you! Instant like!

  • @ayuparpe1580
    @ayuparpe1580 7 лет назад

    how about this way no function than main is used .
    int n, i, arr[50], search, first, last, middle;
    coutn;
    cout

  • @4sky
    @4sky 11 лет назад

    yo dis my go to video for binary search

  • @HarisHussainkhan
    @HarisHussainkhan 10 лет назад

    Thanxz very Good Instructions Given ..... Thank you Very Much.....

  • @ankitkumardubey0095
    @ankitkumardubey0095 5 лет назад

    Thank you so much brother.

  • @jeongmooyoo8692
    @jeongmooyoo8692 6 лет назад

    very well explained~!!!

  • @davidgaster
    @davidgaster 8 лет назад

    Note that the way you are updating hi and lo means there could be integer overflow. In practice you should use high/2 + low/2. Using (high + low)/2 could potentially cause an overflow if high + low is larger than the maximum representable value: 32 bits = 2^32 -1.

    • @ledues3336
      @ledues3336 7 лет назад

      DaveyJones I commented that too! I didn't think about how to do it otherwise, thanks

    • @AlyssaMarie-vr8cc
      @AlyssaMarie-vr8cc 2 года назад

      Ok, interesting - I thought it was mid= low+(high-low)/2 -- is this the same thing as high/2 + low/2 ??

  • @jasonpinto8664
    @jasonpinto8664 7 лет назад +1

    excellent!!

  • @hilaritas1544
    @hilaritas1544 9 лет назад

    Thank you, man!

  • @user-yk3sf9is2u
    @user-yk3sf9is2u 9 лет назад

    Great video

  • @nouraaliabuhlega4023
    @nouraaliabuhlega4023 6 лет назад

    great work ,

  • @superqaxclub
    @superqaxclub 6 лет назад

    Very helpful

  • @halah1995
    @halah1995 9 лет назад

    Thank you very much sir.

  • @AnasMations
    @AnasMations 4 года назад

    you're awesome!

  • @yemimasandra4796
    @yemimasandra4796 4 года назад

    thanks u save my life :')

  • @fisslewine1222
    @fisslewine1222 9 лет назад

    Good tutorial.

  • @satyamjindal8483
    @satyamjindal8483 9 лет назад

    Amazing!!

  • @eXeMutey
    @eXeMutey 6 лет назад

    Thanks a lot man.

  • @rupal3628
    @rupal3628 9 лет назад

    Thank you!!

  • @bellsandoor
    @bellsandoor 8 лет назад

    you are amazing :)

  • @shtprof2000
    @shtprof2000 5 лет назад

    What's up Derek from speech class

  • @hanzalajamash5376
    @hanzalajamash5376 8 лет назад

    Thank you Brother

  • @sama5854
    @sama5854 9 лет назад

    Dont't work !!!!!!!!!!!!!!!!!!