Find a peak element in an array

Author: | Posted in how to 37 Comments



Drawback:
Given an array of dimension n, discover a peak aspect within the array.
For instance:
In Array [1,4,3,6,7,5] four and seven are Peak Components. Return anyone Peak Ingredient.

Answer:
1: Initialize begin = 0, finish = array.size – 1
2: Repeat following steps until peak aspect is discovered:
(a) Discover mid = (begin+finish)/2
(b) If mid is peak aspect, return array[mid]
(c) If array[mid-1] is bigger than array[mid], discover peak in left half of array set finish = mid – 1
(d) Else discover peak in proper half of array set begin = mid + 1

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

Code: http://www.ideserve.co.in/be taught/find-a-peak-element-in-an-array

Web site: http://www.ideserve.co.in

Fb: https://www.fb.com/IDeserve.co.in

source

Comments
  1. Posted by Binayak Choudhary
  2. Posted by tgtffr
  3. Posted by Sachin Bhandari
  4. Posted by Bhanu Chand
  5. Posted by Eddie Ye
  6. Posted by Gustav
  7. Posted by Raushan singh
  8. Posted by Aemad 1447
  9. Posted by danna dai
  10. Posted by Ashutosh Rautela
  11. Posted by sidhant manchanda
  12. Posted by Jad Skr
  13. Posted by Christo Pettas
  14. Posted by Tanishq Saluja
  15. Posted by Antriksh Verma Handa
  16. Posted by Shubham Tripathi
  17. Posted by Abhay Chandra Singha
  18. Posted by sammyiboi
  19. Posted by Oscar Duran Avendaño
  20. Posted by Silly Seagull
  21. Posted by megha sharma
  22. Posted by Veronika Benkeser
  23. Posted by ananth deepak sharma
  24. Posted by Abhishek Sagar
  25. Posted by RAGHAV CHADHA
  26. Posted by Sushil Rakhonde
  27. Posted by Robin Ranabhat
  28. Posted by Yoosuf
  29. Posted by Giulliano Bueno
  30. Posted by Sanket Bhat
  31. Posted by Ray Pinioco
  32. Posted by Rohit Kumar
  33. Posted by IDeserve
  34. Posted by Suriya Krish
  35. Posted by Pratik Surana
  36. Posted by Sharkes Monken
  37. Posted by Jimit Rupani

Add Your Comment