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 my book Head First Design Patterns in the mail. Pretty interesting
I just started reading Effective C++ today and got to the point where the
I got this error today when trying to open a Visual Studio 2008 project
I got an error today while trying to do some formatting to existing code.
I got to thinking today: what is the best way of getting a distinct
I got to thinking about font (typeface) selection today. A site I did for
I've got some (C#) code that relies on today's date to correctly calculate things
The accepted answer to this question , and a similar discussion at work today
today I've got some interesting observation, that I need to explain. I've got my
Today, I ran into this weird problem with a user using Mac OS X.

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.