Docsity

SORTING TECHNOQUES IN DETAILS, Slides of Data Structures and Algorithms

Partial preview of the text

Download SORTING TECHNOQUES IN DETAILS and more Slides Data Structures and Algorithms in PDF only on Docsity!

Data Structure and Algorithms

Lecture 10

Sorting

Why do we need sorting?

● Mostly, problem becomes easy if items are sorted e.g.

○ Finding a median of an array, in a sorted list B[0:n] of n

elements, median would simply be B[n/2]. This solution

now is a constant time.

○ Binary Search i.e looking for a specific item becomes

easier if array is sorted

● Data compression and computer graphics are other

applications of sorting

Why do we need sorting?

Why do we need sorting?

Types of sorting

• Selection sort

• Insertion sort

• Bubble sort

• Merge sort

• Quick sort

• Heap sort

• Shell sort

Selection Sort

Selection Sort

Selection Sort

Example: Selection Sort

  • •
  • • 17 |
  • • 17 26 |
  • • 17 26 33 |
  • • 17 26 33 43 |
  • • 17 26 33 43 46 |
  • • 17 26 33 43 46 52 |
  • • 17 26 33 43 46 52 53 |
  • • 17 26 33 43 46 52 53 77 |

Bubble Sort