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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:00:39+00:00 2026-05-16T05:00:39+00:00

I tried thinking of an algorithm, but couldn’t do it. Here is the problem:

  • 0

I tried thinking of an algorithm, but couldn’t do it. Here is the problem:

There are 16 elements, grouped by four types (a, b, c and d). We also have four groups, A, B, C and D.

In the initial state, the four groups have four random elements each, eg.:

A: c, c, a, d
B: b, b, a, a
C: b, b, c, c
D: d, d, d, a

The order of elements in the group is significant.

There are two operations permitted:

1) rotating the elements of the group (in both directions), eg.:

c, c, a, d -> d, c, c, a

2) swapping two adjacent elements in a group with the corresponding elements in an adjacent group, considering that the first and last groups and elements are also adjacent, so.:

A: (c, c), a, d
B: (b, b), a, a

->

A: (b, b), a, d
B: (c, c), a, a

or

A: c), c, a, (d
D: d), d, d, (a

->

A: d), c, a, (a
D: c), d, d, (d

The goal of the algorithm is to place the elements into their corresponding groups (A: a, a, a, a, etc.). The algorithm doesn’t have to be optimal in terms of time and solution, but it should be reasonably fast on average (ie. no brute-force).

Can anyone help? Is this algorithm even polynomial?

  • 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-16T05:00:40+00:00Added an answer on May 16, 2026 at 5:00 am

    I think it is always possible. First consider the case when a letter (say b) appears only in two rows X and Y. We can ensure that X and Y are adjacent by the swap operations.

    Case i)

    X: b - - -
    Y: - b b b
    

    We can make X all b’s by

    Cyclich shift X.

    X: - - b - 
    Y: - b b b
    

    swap middle

    X: - b b -
    Y: - - b b
    

    Now cyclic shift and swap.

    Case ii)

    X: b - b -
    Y: b - b -
    

    make it

    X: - b - b
    Y: b - b -
    

    Swap last two.

    The other case is trivial.

    Now given any distribution of a particular letter in 2,3 or 4 rows, we can ensure that it appears only in two rows. I will leave that to you, as it is easy to see and hard to type!

    (If it appears only in one row, our work is mostly done for that letter)

    Thus the algorithm would be

    Ensure a appears only in two rows. Make sure the rows are A and B (by swapping later).

    Now perform above to make A to be aaaa.

    Ignore A.

    Consider B,C,D. Ensure that b appears only in two rows. Make B to be bbbb as above.

    Ignore B.

    Given C and D, you can use the above to make C to be cccc, D will be dddd.

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

Sidebar

Ask A Question

Stats

  • Questions 522k
  • Answers 522k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem with stdin is that it's a macro that… May 16, 2026 at 9:27 pm
  • Editorial Team
    Editorial Team added an answer Yikes. Without knowing what GetCube is doing, I can't begin… May 16, 2026 at 9:27 pm
  • Editorial Team
    Editorial Team added an answer JVM is Java Virtual Machine, a memory space where classes… May 16, 2026 at 9:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have tried many things, but I'm still not getting this to work. Here's
The title attempts to summarize the problem, but here's a more detailed summary: our
I am looking for a general algorithm to help in situations with similar constraints
I was thinking earlier today about an idea for a small game and stumbled
I am working on a group senior project for my university and I have
I'm looking for the appropriate algorithm to use to compare two files. I think
I would like to embed an image into my JasperReports jrxml file. I have
I'm thinking about writing a simple UI designer in Java. I'm just playing with
I'm thinking of implementing a configuration file written in Python syntax, not unlike what
hi i tried a select query that contains an left outer join on SQL

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.