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

  • SEARCH
  • Home
  • 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 7771085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:33:41+00:00 2026-06-01T16:33:41+00:00

Given an N-by-N array a of N 2 distinct integers, design an O(N) algorithm

  • 0

Given an N-by-N array a of N2 distinct integers, design an O(N) algorithm to find a local minimum: an pair of indices i and j such that:

  • a[i][j] < a[i+1][j]
  • a[i][j] < a[i-1][j]
  • a[i][j] < a[i][j+1]
  • a[i][j] < a[i][j-1]

I found this question in a an online algorithm book, Introduction to Programming in Java, chapter 4.2: Sorting and Searching.

It is similar to problem 35 (same page):

  • Given an array of N real numbers, write a static method to find in logarithmic time a local minimum (an index i such that a[i-1] < a[i] < a[i+1]).

It has some sort of binary search based solution which I am not able to find out.

  • 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-01T16:33:43+00:00Added an answer on June 1, 2026 at 4:33 pm

    The same problem is mentioned in web version of book Algorithms by Robert Sedgewick and Kevin Wayne. (See “Creative problems” section, problem 19).

    The hint for the problem given by author in that link is:

    Find the minimum in row N/2, check neighbors p and q in column, if p or q is smaller then recur in that half.

    A better aprroach would be :
    Find the minimum in row N/2, check all entries in its column, if we get smaller entry in column, then recur in the row where smaller column entry belongs.

    eg.
    For array below, N=5:

    1  12  3   1  -23  
    7   9  8   5   6
    4   5  6  -1  77
    7   0  35 -2  -4
    6  83  1   7  -6
    

    Step 1: The middle row is [4 5 6 -1 77]. ie. row number 3.

    Step 2: Minimum entry in current row is -1.

    Step 3: Column neighbors for min entry (ie. -1) are 5 and -2. -2 being the minimum neighbor. Its in the 4th row.

    Continue with steps 2-3 till we get the local min.

    EDIT:

    For example mentioned in comment from @anuja
    (the main problem is for n-by-n array. This input is 3-by-4 array but we can work with that) :

    1 2 3  4 
    5 1 6 -1
    7 3 4 -2
    

    Step 1: The middle row is [5 1 6 -1]. ie. row number 2.

    enter image description here

    Step 2: Minimum entry in current row is -1.

    enter image description here

    Step 3: Column neighbors for min entry (ie. -1) are 4 and -2.
    -2 is the minimum column neighbor. Its in the 3rd row.

    enter image description here

    Iterating to Step 2: -2 is smallest in its row and smallest amongst its column neighbours. So we end with -2 as output for local minimum.

    enter image description here

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

Sidebar

Related Questions

For my algorithm design class homework came this brain teaser: Given a list of
So I am given an (unsorted) array A of N distinct integers, I am
Suppose that you're given an array A of n distinct elements drawn from some
Given an array of prime factors of a natural number, how can I find
Given array a= [1,4,5,9,2].I need to find/print combinations of two values where sum =
How to find Min,Max,Sum of given array? int[] number = { 1, 2, 3,
Given an array find the next smaller element in array for each element without
Start with an array of integers so that the sum of the values is
The task is this: generate k distinct positive numbers less than n without duplication.
I have this code to load the month of the birthday that corresponds to

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.