Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on organizing a library

Post

organizing a library

+3
−0

Suppose you have $n>1$ books lined up on a shelf, numbered $1$ to $n$, not in the correct order, and you wish to put them in order. Here's your method: Choose a misplaced book[1] at random, and put it in its correct spot. For example, if $n=5$ and you pick book number $2$ out of spot number $4$, there are now four books left, and you put the book back between the first two, since it's book number $2$.

What's the maximum number of times you might have to do the pick-and-replace before the books are in order?


[1] meaning, a book numbered $k$ which is not in position $k$

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

What happens with the other books when you put a book in the right spot? Do you exchange the book wit... (4 comments)
what I know so far (2 comments)
What happens with the other books when you put a book in the right spot? Do you exchange the book wit...
celtschk‭ wrote over 2 years ago

What happens with the other books when you put a book in the right spot? Do you exchange the book with the other one? Or do you move all books in between one spot to the left/right?

For example, if your current order is 54321, and you pick book 2, what will the order be afterwards? 52341? 52431? Something else?

msh210‭ wrote over 2 years ago

If your order is 54321 and you pick book 2 from the fourth spot, you'll put it back in the second spot, yielding 52431.

celtschk‭ wrote over 2 years ago

Well, the second spot is already occupied, so you have to decide what to do with the book that's already there. From the example, I conclude that you move the book and those in between that spot and the original spot of the picked book one position towards that original spot, right?

To make sure that I understand correctly: If you start with 654321 and pick book 5, you end up with 643251, right?

msh210‭ wrote over 2 years ago

Yes, precisely so.