Find a peak element in an array

preview_player
Показать описание
Problem:
Given an array of size n, find a peak element in the array.
For example:
In Array [1,4,3,6,7,5] 4 and 7 are Peak Elements. Return any one Peak Element.

Solution:
2: Repeat following steps till peak element is found:
(a) Find mid = (start+end)/2
(b) If mid is peak element, return array[mid]
(c) If array[mid-1] is greater than array[mid], find peak in left half of array set end = mid - 1
(d) Else find peak in right half of array set start = mid + 1

Time Complexity: O(log n)
Space Complexity: O(1)

Рекомендации по теме
Комментарии
Автор

kya bande ho aap kya concept hai apke apne to mera dil jeet liya. Yaar bhagwan apke knowledge aur apke channel ko bahut upar tak le jaye

forget
Автор

After watching all these videos, your explanation is the best! Thank you!

amberbai
Автор

Finally I got a perfect channel to start comp prograaming.. thanks for your videos

sachin_bhandari
Автор

this is best explanation on internet, I have been struggling to understand why move left or right, but now it's super clear

krishankantray
Автор

Very clear explanation. I have seen many solutions but not able to understand the way I have learned here. Your analysis is very good to solve the problem.

TarunKumar
Автор

Very clear and good explanation please do more videos on c

saiprasanth
Автор

I was confused by what a professor meant by finding peak through binary search but it's crystal clear in my mind now, thanks

cyril
Автор

Trust me you had the best way of explaining the solutions visually which will have a huge impact in understanding the problems with great explanation. Thank you so much . Iam subscribing your channel right away.🙂

sailakshmi
Автор

Absolutely great platform to learn algorithms. Thanks a lot for your awesome work

saicharan
Автор

Fantastic videos! I really appreciate the quality of your animations and the simplicity of your explanation.

giubueno
Автор

The visualization part really helped a lot to understand the algorithm! Thanks

ChandraShekhar-bycd
Автор

just too good, best tutorials available on youtube

meghasharma
Автор

sir, u r really amazing.
i do not know how to thank you,
previously i do not under stand the concepts.
but now it really helps.
pls keep doing, what u r doing,
pls do not stop.
thank you

abhaychandrasingha
Автор

Love the way you present the material. Thank you from Southern California!!

sammyiboi
Автор

+Erfan Hossain Shoaib

For finding more than 1 peak element, you will have to do linear search because you need to check every array element. This is O(n) algorithm.
Hope this helps.

Thanks,
-Team IDeserve.

IDeserve
Автор

Your content is very clean and neat for understanding every concept in detail. cheers. Keep up the good work.

vedantkakade
Автор

Thanks a lot for your video. Could you please upload more video and keep enlighting us all.

ChandraShekhar-bycd
Автор

Amazing! Thanks for the nice explanation

muskanmendiratta
Автор

Great job.... simply awesome... way u explained peak element using graph...

RohitKumar-ujho
Автор

This is the best explanation every tutorial is just randomly throwing binary search without explaining reason

mradulagrawal