Está en la página 1de 2

CSE 174

9/2/15
Algorithm Design

SORTING PHASE
compare the Dewey Decimal Numbers of the first two books on the left side
save the lowest number, move to the right and compare the next two.
if one of the next two have a lower number than the saved number, save that number.
If there is an odd number of books, the last comparison will be just books number compared to
the saved number
If the next two books have numbers that are bigger than the saved number, go on to the next
two books and compare those two numbers to the saved number.
repeat until the end of the shelf.
find the book with the saved number of that run-through and place it at the first position on the
left side of the shelf.
If a book is found with the same number as the saved number, move that book twin to the right
end of the shelf and disregard the book from the sorting phase or checking phase.
ignore the first book, start at the 2nd book, and repeat the process to find the lowest number of
the books left to be sorted in front of the book that run-through started at.
CHECKING PHASE
Once this process has used every book as the starting point, begin at the first two books, and
make sure that the first book has a lower number than the second book.
Move onto the next to book and compare, two at a time, that the number before is less than the
number after. If a book is found to be greater than the number after it, go back to the sorting
phase and start with the first book
Find the books on the end that are duplicates of numbers and place the duplicates on the right
side of their twin.
The bookshelf should now be sorted from lowest to highest. Stop.

1. a. Unlikely, as not every book gets used and put back in the shelf in a completely wrong
place. There will be a couple people who put a book back into the shelf in the right place or
people who put the book on a library cart so workers can put it back.
b.very unlikely, as the chance that someone will pick out a book and stick it back in in the
wrong place is very high when many people are using the bookshelf
c. likely, as the bookshelf is getting used some people put the book back in the right place
but some people are lazy and will put the book in the most convenient spot.
d. likely, the bookshelf will deteriorate over time and a bookshelf that starts at situation c (a
couple books out of place) will eventually end in situation d (many books in wrong place).

2. a) my algorithm, because it goes two books at a time and moves down the shelf all the way,
should take roughly equal time regardless of how out of order the shelf is.

3. A change I could use to make my algorithm better for the most common cases would be to,
rather than starting at the first book, scanning through the shelf, start at second book, scan
through the shelf, I could scan through the shelf until I find a book that has a higher number
before a lower number, and then start the scanning process there, because I know all the books
before it are still in the right order.

También podría gustarte