This is a problem from my Algorithms course in uni
There are $n$ students, each have a single book. They come into a party to exchange books among themselves. Each have a list of students that have the book that they want.
Give and prove an algorithm that says if a switch of books is possible, i.e. every student got the book that they want.
*A student can't write themself in their list
**If student $i$ took student $j$'s book, it doesn't mean that student $j$ also took student $i$'s book
My algorithm is as follows: Go over the lists from shortest to longest (if there are several lists of same size, start with the list that belongs to biggest number, and progress in ascending order): In the list $i$, take the minimal student's number which isn't marked taken, and mark it as taken. If there is none, return with false
When you're done, return with true
I didn't manage to prove it, so I don't even know if it's true. Thanks in advance