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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:21:52+00:00 2026-05-18T07:21:52+00:00

Today we got an assignment to complete in lab (in two hours). The question

  • 0

Today we got an assignment to complete in lab (in two hours). The question was:

  • You’re given an m*n matrix.
  • The matrix has ‘h’ residential halls and ‘b’ main building entrances.
  • The location of these ‘h’ halls and ‘b’ entrances is known (in terms of (x,y) coordinates).
  • You need to lay pathways such that every residential hall has at least one way to reach one of the ‘b’ entrances.
  • There can be at most ‘b’ such disconnected pathways.
  • The length of the pathway must be minimum.
  • You can only move up, down, left or right.
  • The solution must not be a brute force attempt.

The assignment is over. But I’m still thinking how this would be solved. Is there a standard term for such problems? What should I read up?

Do people use such algorithms to laying roads in cities as well?

  • 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-18T07:21:53+00:00Added an answer on May 18, 2026 at 7:21 am

    Here’s a solution I came up with. It doesn’t generate ‘b’ disconnected paths. It generates one path that goes through all residential halls and entrances.

    • Calculate the distance between each pair of nodes (difference of X coordinates + difference of Y coordinates). Now you have a complete graph.
    • Find the MST for this complete graph
    • Each inclined edge of the MST (those that are not vertical or horizontal) can be split into two parts – the horizontal and the vertical.
    • Each split can be made in two ways – either horizontal first followed by vertical or vice versa.
    • Go through each such permutation and calculate the path with the least length. This is the answer.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I got this question for which I think I answered very bad. I
I asked this goofy question earlier today and got good answers. I think what
Today I got an interview question as titled. For example, a Update Panel contains
Today I got this error in two projects on Heroku when I try to
I've got a homework assignment where I have a base class Package, and two
This question got me today, my repositories should always return full objects? They can
I asked a question here earlier today and got that fixed, but now I
today I got confused when doing a couple of <%=Html.LabelFor(m=>m.MyProperty)%> in ASP.NET MVC 2
Today I got my new PC ( Windows 7 , 32 bit) and installed
Today I got a project written in PHP. There's an error when I try

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.