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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:56:24+00:00 2026-05-24T03:56:24+00:00

Easy problem and known algorithm: I have a big array with 100 members. First

  • 0

Easy problem and known algorithm:

I have a big array with 100 members. First X members are 0, and the rest are 1. Find X.

I am solving it by a binary search: Check member 50, if it is 0 – check member 75, etc, until I find adjacent 0 and 1.

I am looking for an optimized algorithm for the same problem in 2-dimensions:

I have 2-dimensional array 100*100. Those members that are on rows 0-X AND on columns 0-Y are 0, and the rest are 1. How to find Y and X?

  • 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-24T03:56:25+00:00Added an answer on May 24, 2026 at 3:56 am

    Simple solution: go first in X-direction and then in Y-direction.

    Check (0,50); If it is 0, check (0,75); until You find adjacent 0 and 1. Then go to Y direction from there.

    Second solution:

    Check member (50,50). If it is 1, check (25,25), until You find 0. Continue, until You find adjacent (X,X) and (X+1,X+1) that are 0 and 1. Then test (X,X+1) and (X+1,X). Neither or one of them will be 1. If neither, You are finished. If only one, say for example (X+1,X), then You know that the box’s size is between (X+1,X) and (100,X). Use binary search to find box’s height.

    EDIT: As Chris pointed out, it seems that the simple approach is faster.

    Second solution (modified):

    Check member (50,50). If it is 1, check (25,25), until You find 0. Continue, until You find adjacent (X,X) and (X+1,X+1) that are 0 and 1. Then test (X,X+1). If it is 1, then do binary search on line (X,X+1)…(X,100). Else do binary search on line (X,X)…(100,X).

    Even then I am probably beating a dead horse here. If it will be faster, then by neglible amount. This is just for theoretical fun. 🙂

    EDIT 2 As Fezvez and Chris put it, binary search divides the search space in two most efficiently; My approach divides the area to 1/4 and 3/4 pieces. Fezvez pointed out that this could be remedied by calculating the dividing factor beforehand (but that would be extra calculation). In modified version of my algorithm I choose the direction where to go (X or Y direction), which effectively also divides the search space in two, and then conduct binary search. To conclude, this shows that this approach will always be a bit slower. (and more complicated to implement.)

    Thank You, Igor Oks, for interesting question. 🙂

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

Sidebar

Related Questions

The problem is easy to explain: we have two big arrays (32 bit integer
I hope this is a relatively easy problem although I have spent hours websearching
Problem: I have CaretListener and DocumentListener listening on a JTextPane. I need an algorithm
An easy problem, but for some reason I just can't figure this out today.
This should be an easy problem but... I need to format a currency for
I'm trying to solve pretty easy problem. I want to establish connection to 2
This problem is easy fixed clientside. But for performance I want to do it
The problem it's easy. Is there any function in JAVA to compare two Strings
is there an easy way to solve the following problem. Let's say I fetch
This is a problem I'm sure is easy to fix, but I've been banging

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.