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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:26:42+00:00 2026-06-03T14:26:42+00:00

Here is an interesting exercise: Let P be a simple, but not necessarily convex,

  • 0

Here is an interesting exercise:

Let P be a simple, but not necessarily convex, polygon and q an arbitrary point not necessarily in P.

Design an efficient algorithm to find a line segment originating from q that intersects the maximum number of edges of P.

In other words, if standing at point q, in what direction should you aim a gun so the bullet will go through the largest number of walls?

A bullet through a vertex of P gets credit for only one wall.

An O(n log n) algorithm is possible. n is the number of vertices or edges, as it is a polygon, number of edges roughly equals to number of vertices.

Here is my thought:

Connect q with all vertices (let’s say there are N vertices) in P first. There will be N lines, or N-1 pairs of lines.

The final shooting line must be in between these pairs. So we must find the pair that contains the largest number of edges.

I don’t think this solution is O(n log n).

Any ideas?

  • 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-03T14:26:43+00:00Added an answer on June 3, 2026 at 2:26 pm

    Well, first transform the points coordinates into a polar system centered at P.

    • Without loss of generality, let’s choose clockwise direction as special with respect to the angle coordinate.
    • Now let’s conduct a circular walk in sequence along all the edges of the polygon, and let’s notice the starting and the ending point of those edges, where the walk takes us in the clockwise direction with respect to P.
    • Let’s call the ending point of such edge a ‘butt’, and the starting point a ‘head’. This all should be done in O(n). Now we’ll have to sort those heads and butts, so with quicksort it might be O(nlog(n)). We are sorting them by their angle (φ) coordinate from the smallest φ up, making sure that in case of equal φ coordinate, heads are considered smaller than butts (this is important to comply with the last rule of the problem).
    • Once finished, we’ll start walking them from the smallest φ, incrementing the running sum whenever we encounter a butt, and decrementing whenever we encounter a head, noticing a global maximum, which will be an interval on the φ coordinate. This should be also done in O(n), so the overall complexity is O(nlog(n)).

    Now would you tell me why are you asking this kind of questions?

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

Sidebar

Related Questions

Here's something interesting, turnsout that many people out there had this problem, but i
Here's an interesting problem: I'm using ReadProcessMemory (from within C#) to write a simple
I was reading an interesting article here and it made an interesting point about
Here's an interesting writeup of using eye tracking software to generate heat maps that
Here's an interesting problem to solve in minimal amounts of code. I expect the
Interesting one here. I have an ASP.NET 1.1 project that contains a web service
I have an interesting problem here I've been trying to solve for the last
Here's (i think) an interesting question. With AJAX more and more common i feel
Here is the sample code, which produces interesting output: > gg<-data.frame(x=c(a,b),y=as.integer(c(1000,100000))) > gg x
I've got an interesting box-model problem here. I have a header full of links,

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.