Sorting


next up previous contents
Next: The travelling salesman problem
Up: Limits on speed - complexity theory
Previous: Limits on speed - complexity theory
Back: to main list of student notes

Sorting

One simple algorithm: the bubble-sort. Given a sequence of numbers, scan along it until you find a pair that's out of order. Interchange them. Go back to the start, and scan again. Repeat until all numbers are sorted. The time this takes increases (on average) with the square of the number of numbers.

Can we do better? Yes. I think the best possible algorithm that works by comparing pairs of numbers has a time which increases as , where is the number of numbers input.


next up previous contents
Next: The travelling salesman problem
Up: Limits on speed - complexity theory
Previous: Limits on speed - complexity theory
Back: to main list of student notes



Jocelyn Ireson-Paine
Wed Feb 14 23:47:23 GMT 1996