Libary Books Algorithm

Embed Size (px)

Citation preview

  • 8/17/2019 Libary Books Algorithm

    1/2

    CSE 174

    9/2/15

    Algorithm Design

    ● SORTING !ASE

    ● 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.■ f there is an odd number of books, the last comparison will be !ust book"s number compared to

    the saved number ○ f 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.○  f 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 $nd 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.● C!EC"ING !ASE● %nce 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.● &ove onto the next to book and compare, two at a time, that the number before is less than the

    number after. f a book is found to be greater than the number after it, go back to the sorting

    phase and start with the first book● 'ind the books on the end that are duplicates of numbers and place the duplicates on the right

    side of their twin.● (he bookshelf should now be sorted from lowest to highest. )top.

    *. a. +nlikely, as not every book gets used and put back in the shelf in a completely wrong

    place. (here 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 lay 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.

    $. a my algorithm, because it goes two books at a time and moves down the shelf all the way,

    should take roughly e/ual time regardless of how out of order the shelf is.

  • 8/17/2019 Libary Books Algorithm

    2/2

    0. 1 change 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, could scan through the shelf until find a book that has a higher number

    before a lower number, and then start the scanning process there, because know all the books

    before it are still in the right order.