Possible Duplicate:
Plain English explanation of Big O
In the answer to a programming puzzle it said sorting a string takes O(n log n) time. How is that derived?
Does anybody have a good reference link for Big O resources.
Thanks
Mergesort is a divide and conquer algorithm and is O(log n) because the input is repeatedly halved.
It essentially follows two steps: Divide the unsorted list into sub-lists until there are N sub-lists with one element in each ( N is the number of elements in the unsorted list). Merge the sub-lists two at a time to produce a sorted sub-list; repeat this until all the elements are included in a single list.
Sort string in C++Organizing or arranging a group of characters in a definite order i.e, ascending or descending based on their ASCII values is known as sorting a string. The output of a sorting program produces a reordered input or its permutation.
Practical general sorting algorithms are almost always based on an algorithm with average time complexity (and generally worst-case complexity) O(n log n), of which the most common are heapsort, merge sort, and quicksort.
Why is sorting a string O(n log n)?
Sorting the characters in a string is not necessarily O(n log n).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With