- O(N2) in average and worst case; no extra memory required; stable.
- Bubble sort
- Uses about N2/2 comparisons and N2/2 exchanges on the average and in the worst case.
- Selection sort
- Find the smallest element in the array and exchange it with the element in the first position. Then repeat for 2nd, 3rd,...,nth positions.
- Uses about N2/2 comparisons and N exchanges.
- Each item is moved at most once.
- Method of choice for sorting files with very large records.
- Insertion sort
- Consider the elements one at a time, inserting each in its proper place among those already considered, keeping them sorted.
- Is linear for "almost sorted" files.
- Uses about N2/4 comparisons and N2/8 exchanges on the average; twice as many in the worst case.
- Uses sentinel value to avoid having extra boundary check in inner loop.
Sunday, February 11, 2007
Sorting Algorithms Summary
Subscribe to:
Post Comments (Atom)
1 comment:
Here are a list of some important Interview Questions.
Click on them to view the answer:
1)Tell Me Something About Yourself ?
2) What Is (Are) Your Strength (Strengths)?
3) What Is (Are) Your Weakness (Weaknesses)?
4) Can You Work Well Under Pressure?
5) What Are Your Short Term Goals?
6) What Are Your Long Term Goals?
7) Where Do You See Yourself 5 Years From Now?
8) Why Should We Hire You?
9) What Kind Of Salary Are You Looking For?
10) Why Do You Want To Leave Your Current Job?
Post a Comment