Answer to: Recommended data structures/algorithms for checking peoples' availability schedules
Score: -1
I am not completely sure if this is applicable to your scenario a Sparse Matrix is what comes to my mind for a data structure.
I am not sure if this is usable in your scenario as
your data is stored inside of a data base (which limits the possibilities for custom adoptions)
the number of users is not fixed
A quick search showed that at least some data bases support sparse matrixes, but I am not aware how to use them, especially as the number of users can change, thus this might not match.
For a custom storage implementation that wouldn't be too complicated to do, but on a data base I simply don't know.
The idea of a sparse matrix is to not save every possible entry on a row or column, but to expect the matrix to be mainly empty and have pointers to the next (and optionally previous) occupied entry in the same axis.
The assumption to justify the sparse matrix is, that most combinations of [user, time, event] won't be filled.
In theory we could fill a 3-dimensional matrix and thus search in any axis direction:
next/previous user on same time slot and event
next/previous time slot on same user and event
next/previous event on same user and time
Of course, this is not yet exactly as it is needed. As you said, each person can attend to only one event at the same time and also each event is usually only a single block of adjacent time.
Thus event + time could be merged into a single entry which represents both (for each time slot, e.g. 15 or 30 minutes, thus having the same event on multiple slots) and the tricky part, to allow to search for any of the two identifiers instead of a combined identifier.
Thus we get back to a 2-dimensional matrix [user, time + event] or as a workaround to search for any individual key, make two similarly filled matrixes [user, time] and [user, event].
On such matrixes you can search
next/previous user on same time slot (not sure if helpful without the event)
next/previous user on same event (list of participants)
next/previous time slot on same user (user's occupied time)
next/previous event on same user (user's events)
I hope this helps you out and you get this running on your data base.
View Question ↗
Question
Parent Entity
Score: 5 • Views: 595
Site: softwareengineering
Other Comments / Reviews
SaaS Metrics