ARITHMETIC WORKSHEETS

Counting orders in which two specified items stay together

Count the orderings in which two named items must sit next to each other, by gluing them into one block and then ordering the block's inside.

Gluing the pair

Five distinct items include A and B, and every ordering must have A and B side by side. Treat the pair as one unit. The unit, together with the three other items, gives four units to put in a row. Any ordering of the four units, with A and B inside the block in some order, produces a valid arrangement of the original five, and every valid arrangement arises this way. The method turns a constraint on two items into an ordinary ordering problem on a smaller set, which is easier to count than the original. It is a standard technique in elementary counting courses, and it works because the constraint can be built into the objects being ordered instead of being checked afterward against every ordering.

Counting orders of the four units

Four distinct units can be ordered in 4 factorial, or 24, ways. The Permutation calculator returns 24 for n equal to 4 and r equal to 4. This number counts how the block and the three other items can be arranged along the row, without yet opening the block. Each of those 24 outcomes places the block somewhere, such as first, second, third or fourth, and fills the remaining places with the other items in some order. At this stage the block is a single object, and its inside has not been specified.

Opening the block, two internal orders

Inside the block, A can come before B or B before A. Those are two different arrangements of the original items, even when the outer pattern is identical. So each of the 24 outer orders splits into 2 complete orders, and the total is 24 times 2, which the basic calculator gives as 48. For instance, the outer order block, C, D, E becomes A B C D E or B A C D E, and the outer order C, block, D, E becomes C A B D E or C B A D E. Counting the internal order after the outer order keeps the two choices from being confused. The factor of 2 is the number of ways to order two items, which is 2 factorial.

When the internal order is fixed

If the problem states that A must come immediately before B, the internal choice disappears. There is only one arrangement inside the block, so the count equals the number of outer orders: 24. The difference between 24 and 48 is the phrase "next to each other" versus "A immediately followed by B." Reading the wording closely matters. Some problems say "adjacent," which allows both orders, and others say "A directly before B," which allows one. A related phrase, "A somewhere before B," allows other items to come between them, and by symmetry exactly half of all orders qualify, so 60 of the 120 orders of five items. The block method handles both, with a factor of 2 in the first case and 1 in the second.

A six-item example

With six distinct items and a required adjacent pair, there are five units, so 5 factorial orders of units, which the calculator gives as 120 for n equal to 5 and r equal to 5. Doubling for the internal order gives 240. All six items can be ordered in 6 factorial, or 720 ways, so 480 orders keep A and B apart. The basic calculator gives 720 minus 240 as 480. Subtracting the together case from the total is the standard way to count the opposite condition, that two items are not adjacent.

A four-item example for checking

With four distinct items and A and B adjacent, there are three units, so 3 factorial, or 6, outer orders, and 6 times 2, or 12, complete orders. The total of all orders is 24, so 12 orders have A and B apart. You can list them to confirm. With C and D as the other two items, the twelve orders with A and B adjacent are ABCD, ABDC, BACD, BADC, CABD, CBAD, DABC, DBAC, CDAB, CDBA, DCAB and DCBA. Writing out all 24 for four items takes a few minutes and verifies the formula for small cases. That builds trust in the method before it is applied to larger sets where listing is impractical, and it also shows how the block moves through the first, middle and last positions.

Larger blocks

The idea extends to a block of three items. With five distinct items and a required block of three, the block and the two other items form three units, which order in 3 factorial, or 6, ways. Inside the block, the three items can be arranged in 3 factorial, or 6, ways. The total is 6 times 6, or 36. The calculator confirms 3 factorial as 6 and the product as 36. The general rule is the factorial of the number of units times the factorial of the block size, for each block that must stay together.

Several adjacency requirements

When two separate pairs must each be adjacent, such as A with B and C with D, and the pairs share no items, each pair becomes its own block. Five distinct items would then form three units: the AB block, the CD block and the fifth item. The count is 3 factorial times 2 times 2, or 24. But if the pairs share an item, as in A next to B and B next to C, the blocks merge into a chain that must be analyzed as a block of three with its own internal orders. Multiplying separate pair counts in that case overcounts, as the guide warns.

Assumptions behind the block count

The items are distinct, the row has fixed positions and each item is used once. The method does not apply when items repeat, because swapping identical items does not create a new arrangement, and then the factors must be divided out. For instance, if C and D were identical, swapping them would leave the row unchanged, and the counts above would be halved when no other symmetry remains. It also does not account for circular rows, where the first and last positions touch and the block could wrap around the ends. For those, a separate analysis of the circular count is needed. Within the stated assumptions, the answer 48 is a count of possible orders, not a statement about which is more likely.

Reproduce the checks

Four unit orders

Open the Permutation calculator and enter:

Total items n
4
Positions r
4

Expected output:

Permutations

24

The pair occupies one temporary unit.

Either internal pair order

Open the Basic calculator and enter:

First number
24
Operation
multiply
Second number
2

Expected output:

Result

48

The two orientations give distinct complete orders.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Related tasks