Original Post
I have a problem with a homework assignment and I hope someone here can give me some hints. I'm given the following struct (this is in straight C):
typedef struct Student_ {
char *name;
int average;
} Student; A database of these structs is stored in a binary file. The file starts with the number of students, and for each student, it contains the name's length, the name and the average grade. I need to write a program that takes such a file and creates an offset file for it, that is, a file containing offsets into the database such that each offset "points" to a student. The offsets have to be laid out such that if you go through them in order, you'll get the students sorted by name. The problem I have is that I am required to use the most efficient sorting algorithm possible. The ones we covered are: Bubble sort Insertion sort Merge sort Quicksort Bucket sort To make a long story slightly less long, I'm only familiar with the first four and my instructor told me that Bucket sort is the most efficient out of these. However, he said that I need to use the most efficient algorithm possible, which is different from just picking the one that is most efficient in general. I couldn't get him to clarify this much, but basically it seems like one of the other algorithms might be more suitable in this particular case. But I don't see what makes this problem any different than a general sorting problem. I know that Merge sort is suitable for working with large files (when you can't hold all the data in memory at once), but I don't think it applies here because I can just use the offsets to fetch each name only when I need it (and this is a constant time operation). I'm kind of lost here, so any hints you can offer me would be greatly appreciated.