Exponential Search - better than Binary search? (Explained)

Поділитися
Вставка
  • Опубліковано 15 гру 2024

КОМЕНТАРІ • 46

  • @spetsnaz_2
    @spetsnaz_2 5 років тому +3

    In your given code, in the last line of the function exponentialSearch(), will it not be return binarySearch(arr, i/2, min(i, n-1), x); instead of return binarySearch(arr, i/2, min(i, n), x); ???

    • @techdose4u
      @techdose4u  5 років тому +5

      Please change it to min(i,n-1) and you will get the correct result.

    • @spetsnaz_2
      @spetsnaz_2 5 років тому +1

      @@techdose4u ok man!!

  • @AmandeepSingh-ot6st
    @AmandeepSingh-ot6st 4 роки тому +1

    Bhai ekdum jhaakkass samjhaya hai❤️❤️..keep it up..lots of love from my side

  • @100dollerbill4
    @100dollerbill4 4 роки тому +2

    Thank you vey much for your explanation and efforts for this video totally appreciate it. keep up the good work.

  • @ibrahimshaikh3642
    @ibrahimshaikh3642 4 роки тому +1

    Very helpful, keep updating such new topic, thanks a lot

  • @saichennu5288
    @saichennu5288 5 років тому +2

    Please.. please... Upload more videos on data structures based problems

  • @RanjitSingh-rq1qx
    @RanjitSingh-rq1qx Рік тому

    Very good explanation ❤

  • @wasit-shafi
    @wasit-shafi 5 років тому +1

    Odom sir....keep it up

  • @RANAND-xd3zu
    @RANAND-xd3zu 4 роки тому +1

    Sir time and space complicity didn't understand fully please make one video on time and space which searching algorithm is best why and compare with another what difference could you explain in more detail

  • @bm-ub6zc
    @bm-ub6zc 4 роки тому

    Isn't the command "min(i, n-1)" unnecessary, because the while loop already has prevented, that n would be larger than i? (while i

    • @ganeshkamath89
      @ganeshkamath89 2 роки тому

      the while loop does not prevent it. It just handles elements in side that range. when I exceeds range While loop breaks (without preventing)

  • @ankitjhunjhunwala9895
    @ankitjhunjhunwala9895 3 роки тому

    Great video sir! Just one observation, should n't expression (i

  • @joshuakhoo2234
    @joshuakhoo2234 5 років тому +1

    What does min(i, n-1) do? Sorry im new to coding. As in why are there two parameters inside

    • @techdose4u
      @techdose4u  5 років тому +1

      Min(x, y) will return minimum of these two values. If x

  • @soniamalik4929
    @soniamalik4929 3 роки тому

    Great Sir but one question plz do ans.....2^n gets counted in one of worst complexities....and while finding runtime we take the max time...so we need to take 2^n instead of logN....

  • @sudershansingh2839
    @sudershansingh2839 2 роки тому

    But we're still using binary search right?
    We've just reduced some computations but the algorithm runs in O(log n) still so why do all this can't we just do with pure binary search.

  • @SudeeptaSood
    @SudeeptaSood 3 роки тому

    hi, how is the exponential jump from i = 2, 4, 8... giving (logn) time complexity? can you let me know. thanks

    • @vinayak186f3
      @vinayak186f3 3 роки тому +2

      i=1 initially , then i gets pow(2,1), pow(2,2) and so on ,let's say this continues upto k times , pow(2,k) ,the loop will be exited when i>=n , thus k = no of times loop runs =logn ,also the time complexity of BS is O logn,so it's O logn +O logn =O logn

  • @DeepakGupta-zz1vf
    @DeepakGupta-zz1vf 3 роки тому

    Why are we incrementing i = i*2 , why not x3 or x5 ???

  • @klydy4671
    @klydy4671 4 роки тому +1

    Thank you sir

  • @sperovita9931
    @sperovita9931 4 роки тому +1

    Can you provide the same code in MATLAB?

    • @techdose4u
      @techdose4u  4 роки тому +3

      I don't know matlab.

    • @ChandrapalSd
      @ChandrapalSd 4 роки тому +1

      @@techdose4u MATLAB is a multi-paradigm numerical computing environment and proprietary programming language developed by MathWorks .
      Source:- wikipedia

    • @Unknown-Stranger
      @Unknown-Stranger 3 роки тому

      @@ChandrapalSd LOL he want to say that He don't have the knowledge about MATLAB.

  • @adityasingh9755
    @adityasingh9755 5 років тому

    Why we compared 0th element separately in beginning ?

    • @joshuakhoo2234
      @joshuakhoo2234 5 років тому +2

      Because i represents the index number and if yo ustart with 0, you cannot increase i exponentially as 0x2=0

  • @mohammedfahimullah4999
    @mohammedfahimullah4999 3 роки тому

    why should be we give min(i,n-1).Instead of that can we give n-1 alone

    • @TheNoobyPeatreat
      @TheNoobyPeatreat 3 роки тому

      No because if I < n && a[I] > x then we don't want to search to the end of the array if variable "I" can be smaller than the array size

  • @diwyanshukanthwal8669
    @diwyanshukanthwal8669 4 роки тому

    WHY I/2 TAKEN PLEASE EXPLAIN

  • @rockdestrobreakz1128
    @rockdestrobreakz1128 4 роки тому +1

    If 11 would be present in 5th,6th or 7th index we can't find it.

    • @rockdestrobreakz1128
      @rockdestrobreakz1128 4 роки тому

      I got it. But how can i get the explanation of the lower bound of i/2. why it is i/2 it should be anyother thing. Please explain.

  • @aklilebelayneh4581
    @aklilebelayneh4581 4 роки тому +1

    10+11/2=10,how it is true??????

  • @alexisandersen1392
    @alexisandersen1392 2 роки тому

    Hi, this is absolutely ridiculous.
    Unless you have an extremely large array where modular exponentiation indexing becomes useful,... You're far better off just doing a linear search, or maybe a binary search if the list is larger by an order of magnitude or two than a cache line.
    Even If you had a million integers, linear search is still faster, however you might see improvement with a binary search at that scale.... Maybe.... It really depends if you are on hardware that can fetch polynomially ahead rather than linear ahead.
    For this algorithm to net actually gains, you'd have to be searching through some obscenely massive collection of hashes indexing objects in a relatively remote record heap with two or more layers of pointer indirection... then it might be worth it. But you might actually be better off using modular exponentiation indexing.
    The point is that anything outside of cache is obscenely slow by comparison, and a single short tight loop will optimize far better than a sequence of loops and a potentially recursive function call... and because of that being able to leverage the automatic cache prefetch using linear iteration is preposterously effective.
    I mean.... We have multi gigahertz processor cores, you can linearly iterate through about a billion member list of candidates checking for equality in less than a second. Trust me, binary search isn't the problem.
    In your algorithm, it could be argued that the overhead of the loops, and function calls alone will obliterate any gains you think you're getting from this algorithm at this scale and scales even several orders of magnitude greater. I don't care what your big O notation says.

  • @mjofficial.07
    @mjofficial.07 3 місяці тому

    Exanple u took is completely ridiculous. Can't u take index and values different?

  • @Stupid-uc9mj
    @Stupid-uc9mj 11 місяців тому

    Its useless