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 6866737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:13:21+00:00 2026-05-27T03:13:21+00:00

Design an algorithm , FindElement(a,p), where a is two-dimensional square array of positive integers

  • 0

Design an algorithm , FindElement(a,p), where “a” is two-dimensional square array of positive integers with duplicates and each row of integers is in non – decreasing order:
a[i][0] ≤ a[i][1] ≤ a[i][2] · · · ≤ a[i][n-1]
(i=0,1,. . .,n-1),. The algorithm should define whether or not p is contained in a. It should return true if the “p” was founded, false otherwise.
Your algorithm must be as efficient as possible. Algorithm should be based on Binary Search

I have found the following solution (but i’m not sure that it is correct):

Solution is to search for the element working on one row at a time using binary search. Binary searching a given sorted row of size (n) takes O(Log(n)) so it would take O(nlog(n)) to search the entire array in worst case.

Does this solution is suitable for the given task or not? I do not know how to implement this algorithm, please could you give me pseudo – code or explanation how to do it.
Thanks in advance.

  • 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-05-27T03:13:22+00:00Added an answer on May 27, 2026 at 3:13 am

    Yes, your solution seems correct and efficient (given your description of the initial problem, they probably want you to use binary search). Your algorithm should go something like this:

    public Point FindElement(int[][] matrix, int number) {
        Point p = new Point(); // holds two integers and represents 
                               // a position in the matrix.
        int found = -1;
        for(int i = 0; i < N; i++) {
            found = binarySearch(matrix[i], number, 0, N);
            if(found != -1) { 
               p.setX(i); 
               p.setY(found); 
               return p; 
            }
        }
        return null;
    }
    

    where binary search can be implemented according to the pseudocode found here: http://en.wikipedia.org/wiki/Binary_search_algorithm#Recursive

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

Sidebar

Related Questions

Given a square matrix, where each cell is black or white. Design an algorithm
How to design an algorithm to simulate multiplication by addition. input two integers. they
Design an algorithm to find all pairs of integers within an array which sum
I want to design an algorithm that determines whether an array A is plural,
I recently was asked to design an algorithm that checks if two strings are
Let A[1..n] be an array of real numbers. Design an algorithm to perform any
The median of five is sometimes used as an exercise in algorithm design and
I've been thinking recently on using the Object Oriented design in the sorting algorithm.
My design exposes two kinds of resources: Images Tags I would like clients to
Problem: I have to design an algorithm, which does the following for me: Say

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.