

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A programming assignment for cmps 101 students to write a java program implementing the perfect shuffle algorithm on a list adt. The goal is to ensure understanding of java, modularity, and abstract data types, as well as building an adt implementation for future assignments. Instructions on how to read input, initialize a list, perform perfect shuffles, and print out the number of shuffles performed.
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Algorithms and Abstract Data Types Summer 2005
The purpose of this assignment is threefold: to make sure everyone is up to speed with Java, to practice modularity and ADTs, and to build an ADT implementation which will be used (with minor modifications) in future programming assignments. You should therefore test your ADT carefully, even though all of its features may not be used here. You are to write a Java program which takes as input a positive integer n from the command line, creates a deck of n cards, then repeatedly performs a perfect shuffle on this deck until the cards are again in their original order. Each card is labeled with a number from 1 to n. A perfect shuffle is performed by splitting the deck into a top part and a bottom part (if n is odd, the middle card goes into the top part) and then (starting with the top part) repeatedly taking the bottom card from each part and placing them on top of a new deck. Thus to perform a perfect shuffle on the deck 1 2 3 4 5 6 7 8 9 ( n 9 ), we begin by splitting it into a top part 1 2 3 4 5 , and a bottom part 6 7 8 9. We start the new deck with 5 on the bottom, then 9 , then 4 , and so on until the new deck is 1 6 2 7 3 8 4 9 5. (Note that if n is odd, then the first card remains in its original location after the shuffle.) Repeatedly shuffling a deck of size 9 results the following sequence of deck permutations: #Shuffles Deck Order
0 1 2 3 4 5 6 7 8 9 1 1 6 2 7 3 8 4 9 5 2 1 8 6 4 2 9 7 5 3 3 1 9 8 7 6 5 4 3 2 4 1 5 9 4 8 3 7 2 6 5 1 3 5 7 9 2 4 6 8 6 1 2 3 4 5 6 7 8 9 Repeatedly shuffling a deck of size 14 results in: #Shuffles Deck Order
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 8 1 9 2 10 3 11 4 12 5 13 6 14 7 2 4 8 12 1 5 9 13 2 6 10 14 3 7 11 3 2 4 6 8 10 12 14 1 3 5 7 9 11 13 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 The relationship between the deck size and the number of shuffles required to bring the deck back to it’s original state is an interesting one. A deck of size 500 requires 166 shuffles, while one of size 508 requires 508 shuffles, and a deck of size 511 requires only 9 shuffles. Note that the above examples are for illustration only and do not represent program output. Although there are many ways to shuffle cards, the purpose of this assignment is to implement and use a list of integers ADT. Your program will do the following: