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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:29:58+00:00 2026-05-27T09:29:58+00:00

For my algorithms class we are required to write a bottoms-up minimal-change algorithm. As

  • 0

For my algorithms class we are required to write a bottoms-up minimal-change algorithm.

As an example output our professor provided us with

n=4
1234     2314     3124
1243     2341     3142
1423     2431     3412
4123     4231     4312
4132     4213     4321
1432     2413     3421
1342     2143     3241
1324     2134     3214

Notice that it generates 24 permutations (6 for each digit). The permutations for 4 (as in, 4 being the first number in a permutation) are a byproduct from the other calls in that algorithm. You can also see that at most only 2 numbers every switch positions.

I’ve been struggling to find a good pattern within those numbers to base my code on.
So I was thinking of taking a slightly different approach to the problem.

If I take the factorial of n I can calculate the number of permutations. By dividing the number of permutations by n I get the number of times each digit is in each respective position (i.e. how many permutations start with each number). Dividing the subsequent result by n-1 I get the number of times each second digit will occur, given the first digit remains the same. So on and so forth (with n being decreased by one every time) until all digits have been exhausted.

As an example, assume that n=4

4! = 24
24/4 = 6
6/3 = 2
2/2 = 1

Using these results I can generate permutations vertically, not horizontally.

Instead taking a number and sliding it back and forth over the other numbers and doing swaps every so often I would instead generate a table that is nxn! in dimension. Then, going down the columns fill in the first column with 6 ones, 6 twos, 6 threes, 6 fours, and 6 fives.

When I get to second column each number would be put in twp times, and then repeated until the end of the array is reached. Subsequently, each column would follow a similar pattern. This pattern would work with any sized n input.

My output would be this:

n=4
1234    2134    3124    4123
1243    2143    3142    4132
1324    2314    3214    4213
1342    2341    3241    4231
1423    2413    3421    4312
1432    2431    3412    4321

Now my question is… is this still considered a minimal-change algorithm?

My algorithm works more in lexicographical order, and that worries me that it may not be considered a minimal-change algorithm (because during certain steps more than one number seems ‘swapped’, though in reality no swapping is being done).

  • 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-27T09:29:59+00:00Added an answer on May 27, 2026 at 9:29 am

    No, it’s not a minimum-change algorithm—the requirement is that each adjacent pair of permutations in the output differ by one swap.

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

Sidebar

Related Questions

It's been awhile since my algorithms class in school, so forgive me if my
One of the assignments in my algorithms class is to design an exhaustive search
In class we are doing sorting algorithms and, although I understand them fine when
I'm wondering how (un)common it is to encapsulate an algorithm into a class? More
I am writing a class to implement an algorithm. This algorithm has three levels
I have a class in a unit. Usually, when I changed the algorithm of
The following code can be found in the NHibernate.Id.GuidCombGenerator class. The algorithm creates sequential
#include <list> #include <set> #include <iterator> #include <algorithm> using namespace std; class MyContainer {
I want to create a class that can use one of four algorithms (and
I am attempting to write a two-pass algorithm incorporating some legacy code. I want

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.