Binary Search in Python: Find Bitonic Peak

preview_player
Показать описание
In this video, we will be given an array that is bitonically sorted, an array that starts off with increasing terms and then concludes with decreasing terms. In any such sequence, there is a "peak" element, that is, the element in the sequence that is the largest element. We will be writing a problem to help us in finding the peak element of a bitonic sequence.

This video is one part of the Binary Search playlist on my channel. For more videos on binary search and how to apply it to various problems, check out the other videos:

The software written in this video is available at:

Do you like the development environment I'm using in this video? It's a customized version of vim that's enhanced for Python development. If you want to see how I set up my vim, I have a series on this here:

If you've found this video helpful and want to stay up-to-date with the latest videos posted on this channel, please subscribe:
Рекомендации по теме
Комментарии
Автор

What if the list is [1, 2, 5, 5, 5, 3, 2, 1]? In this case, the left of the mid == the right of the mid.

kedazhu
Автор

hi, very well-explained video once again, you're helping many others with this playlist :)
2 Qs on bitonic sequences:
1) is it valid to assume that for any given input list, there can be NO duplicate elements? Since I noticed in the code there's only 'if, elif, elif' checks, but no 'else' statements which accounts for the duplicate adjacent elements case.
2) just clarifying how you defined the `mid_left` and `mid_right` variables, is it because you assume the 1st and last elements can never be the peak element?
3) When defining `mid_right`, why did you assign '+Inf' instead of ' - Inf'? e.g. for bitonic seq [1, 2, 3, 8, 1], would we not want the last element to be as *small* as possible, hence assign '-Inf' if mid == last element index?

Thank you!

elisad
Автор

sir i followed your both data structure and algorithm series, can u please tell me, how do i increase my algorithm building and programming logic.

adityagedam
Автор

If I run your program with the list [9, 7, 6, 5] I don't get 'None', rather I get the second element in the list. I think the problem is in the assignment of mid_left in the while loop. In fact, passing any list sorted in descending order gives the first or second element as a result rather than "None".

richardhunter
Автор

At 9:50 why did you use the else statement to put float('-inf') and float of ('inf') to mid_left and mid_right ? Can you give some examples where this would be used ?
Thankyou . These videos are really useful watching your entire series!

shonnoronha
Автор

Shouldn't it be if mid -1 >= 0 else float('-inf') rather than just > ? For a simple example A = [1, 3, 1] where mid = 1 here mid -1 = 0 and is valid.

samarthbhandari
Автор

I do not understand the part where you give float(-inf) for the else statement. Can you explain what that does?

mukeshvishwanathan
Автор

Sir, I m not getting those if statement's, how does the work, I m getting confused at 9:30

anshulvairagade