algorithm - Elementary Sorts Running Time Comparisons -
i've been learning elementary sorts in class (bubble sort, insertion sort, , selection sort) , have been bit confused running times.
on homework teacher has given us, question asks: "which of 3 elementary sorts run fastest file keys identical? file data in reverse order?"
for first part of question, i'm not entirely sure mean "keys". so, mean there array of size 1 multiple data? don't think "keys" same "data". know if of data ordered, insertion sort fastest i'm not sure if have affect on problem.
for second part of question, i'm thinking selection sort since take constant number of comparisons no matter number of inversions in data. insertion sort , bubble sort result in many exchanges.
i'm confused on first part of question.
usually in experience, when sorting file, 1 can file consists of "records" , moving each record appears prior records should prior to. "key" whatever part of record using in order determine whether 1 record should before or after record. if sorting numbers or strings, "key" entire record. in other cases each record might someone's school transcript, , reason want sort these records student's name, of data in record not part of key. helpful if teacher has said or considers unit of data moved during swap.
i think thinking correctly case records sorted, , keys identical 1 such case.
for case records in reverse order, question isn't how number of comparisons in selection sort affected initial order of data; rather, question (regarding comparisons) whether of algorithms able perform fewer others. insertion sort takes fewer comparisons selection, in case may able show otherwise. , of course need @ how many comparisons bubble sort need.
Comments
Post a Comment