Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:27:35+00:00 2026-06-10T15:27:35+00:00

Given an array of integers, find the local minima. An element A[i] is defined

  • 0

Given an array of integers, find the local minima. An element A[i] is defined as a local minimum if A[i-1] > A[i] and A[i] < A[i+1] where i = 1…n-2. In case of boundary elements, the number has to be just smaller than its adjacent number.

I know if there is only one local minimum, then we can solve with modified binary search.
But if it is known that there exist multiple local minima in the array, can it be solved in O(log n) time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:27:37+00:00Added an answer on June 10, 2026 at 3:27 pm

    If the array elements are not guaranteed to be distinct, then it’s not possible to do this in O(log n) time. The reason for this is the following: suppose that you have an array where all n > 1 values are the same. In this case, none of the elements can be local minima, because no element is less than its neighbors. However, in order to determine that all values are the same, you will have to look at all the array elements, which takes O(n) time. If you use less than O(n) time, you can’t necessarily look at all the array elements.

    If, on the other hand, the array elements are guaranteed to be distinct, you can solve this in O(log n) time using the following observations:

    1. If there is just one element, it’s guaranteed to be a local minimum.
    2. If there are multiple elements, look at the middle element. If it’s a local minimum, you’re done. Otherwise, at least one of the elements next to it must be smaller than it. Now, imagine what would happen if you were to start at one of the smaller elements and progressively move toward one of the ends of the array in the direction away from the middle element. At each step, either the next element is smaller than the previous, or it will be bigger. Eventually, you will either hit the end of the array this way, or you will hit a local minimum. Note that this means that you could do this to find a local minimum. However, we’re not actually going to do that. Instead, we’ll use the fact that a local minimum will exist in this half of the array as a justification for throwing away one half of the array. In what remains, we are guaranteed to find a local minimum.

    Consequently, you can build up the following recursive algorithm:

    1. If there is just one array element, it’s a local minimum.
    2. If there are two array elements, check each. One must be a local minimum.
    3. Otherwise, look at the middle element of the array. If it’s a local minimum, return it. Otherwise, at least one adjacent value must be smaller than this one. Recurse in the half of the array containing that smaller element (but not the middle).

    Notice that this has the recurrence relation

    T(1) ≤ 1

    T(2) ≤ 1

    T(n) ≤ T(n / 2) + 1

    Using the Master Theorem, you can show that this algorithm runs in time O(log n), as required.

    Hope this helps!

    Please also notice that this algorithm only works if edges of the array count as local minima if they are smaller than the adjacent element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given an array of integers ,You have to find two elements whose XOR is
Given an array of integers, how can you find two indices, i and j,
Given an array A of integers, find any 3 of them that sum to
Given is an array of integers. Each number in the array occurs an ODD
Given an array of prime factors of a natural number, how can I find
Given a number N and an array of integers (all nos less than 2^15).
Given the following question, Given an array of integers A of length n, find
Given a sorted array of integers, how can we find a pair of integers
Given an array of n integers, where one element appears more than n/2 times.
Question: Given an unsorted array of positive integers, is it possible to find a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.