Professional Documents
Culture Documents
Data Structure: in This Lecture, You Will Learn About
Data Structure: in This Lecture, You Will Learn About
Data Structure: in This Lecture, You Will Learn About
• Sorting algorithms
• Selection sort
• Bubble sort
C// Central Ideas:-
- Sorting algorithms
- Selection sort
Sorting - Bubble sort
Algorithms D// Objectives:-
After studying this unit, the
student will be
able to use following ways in
sorting:
- Selection sort
- Bubble sort
Definition of sorting algorithms
A sorting algorithm is a method for reorganizing a large number of items
into a specific order, such as alphabetical, highest-to-lowest value or
shortest-to-longest distance. Sorting algorithms take lists of items as
input data, perform specific operations on those lists and deliver ordered
arrays as output.
Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort, Heap
Sort
2. Non-comparison sort:
The techniques of sorting can be divided into two categories. These are:
•Internal Sorting
•External Sorting
Internal Sorting: If all the data that is to be sorted can be adjusted at a time in the
main memory, the internal sorting method is being performed.
External Sorting: When the data that is to be sorted cannot be accommodated in
the memory at the same time and some has to be kept in auxiliary memory such
as hard disk, floppy disk, magnetic tapes etc, then external sorting methods are
performed.
complexity of sorting algorithm
Before sorting 14 2 10 5 1 3 17 7
After pass 1 14 2 10 5 1 3 7 17
After pass 2 7 2 10 5 1 3 14 17
After pass 3 7 2 3 5 1 10 14 17
After pass 4 1 2 3 5 7 10 14 17
Number of comparisons: (n - 1) + (n - 2) + (n - 3) + ..... + 1 = n(n - 1) /
2 nearly equals to n2.
Time Complexities:
Space Complexity: