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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:33:49+00:00 2026-05-26T15:33:49+00:00

I have to write an algorithm for Assigning Contiguous seats in a seat map.For

  • 0

I have to write an algorithm for Assigning Contiguous seats in a seat map.For example: allocating seats in a stadium. The seat map can be viewed as a 2d array of N rows and M columns. The system must assign contiguous seats for bookings that are made together. Since no seat map is presented to the user, the system should automatically assign the available seats corresponding to each purchase. In addition to this, it should do this in such a fashion such that the holes/gaps in the seats are minimized.

  • 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-26T15:33:50+00:00Added an answer on May 26, 2026 at 3:33 pm

    Finding a perfect solution is NP-hard. Look at the equivalent language problem:

    L={((x1,x2,...,xk),n,m)} where xi are the number of co-booked tickets, and n,m are the stadium sizes.

    We will show Partition <=(P) L, and thus this problem is NP-Hard, and there is no known polynomial solution for it.

    Proof

    let S=(x1,x2,..,xk) be the input for a partition problem, and let sum=x1+...+xk

    Look at the following reduction:

    Input: S=(x1,...,xk)
    Output:((x1,...,xk),sum/2,2)
    

    Correctness:
    If S has a partition, let it be S1=(x_i1,x_i2,...,x_it), then by definition of partition, x_i1+...+x_it=sum/2, and thus we can insert x_i1,..,x_it in the first row, and the rest in the second row, and so ((x1,...,xk),sum/2,2) is in L

    If ((x1,...,xk),sum/2,2) is in L, then by definition there are t bookings such that x_i1,x_i2,...,x_it form a perfect first line, and thus x_i1+x_i2+...+x_it=sum/2, and thus it is a valid partition and S is in Partition problem

    Conclusion:

    Since L is NP-Hard, and the problem you seek is the optimization problem for this language, there is no known polynomial solution for it. For an exact solution you can use backtracking [check all possibilities, and choose the best], but it will take a lot of time, or you can sattle for a heuristic solution, such as greedy, but it will not be optimized.

    EDIT: Backtracking solution [pseudocode]:

    solve(X,n,m):
       global bestVal <- infinity
       global bestSol <- null
       solve(X,new Solution(n,m))
    solve(X,solution):
       if (X is empty):
           gaps <- solution.numGaps()
           if (gaps < bestVal):
                bestVal <- gaps
                bestSol <- solution
           return
       temp <- X.first
       X.removeFirst()
       for i from 0 to m:
           solution.addToLine(i,temp)
           solve(X,solution)
           solution.removeFromLine(i,temp)
       X.addFirst(temp)
    

    Assuming Solution is an implemented class, and for an illegal solution [i.e. too many people in one row] numGaps() == infinity

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

Sidebar

Related Questions

How can I determine if I have write permission on a remote machine in
I have to write an algorithm in AS3.0 that plots the location of points
I need to write and algorithm that can detect which state an application (used
I have an assignment to write an algorithm to find duplicate in a Dynamic
We have A apples, B baskets. How would you write the algorithm that lists
We have A apples, B baskets. How would you write the algorithm that lists
I'm looking for a way to have to write and maintain a certain algorithm
I have to write an algorithm to find the determinant of a matrix, which
I am trying to check if I have write access to a specific key
The debug screen says that django does not have write access to the db.

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.