0% found this document useful (0 votes)
38 views

Analysis & Design of Algorithms

This document provides an introduction to sorting algorithms. It discusses that sorting is an important problem in computer science as it is the first step in many algorithms. There are many sorting algorithms to choose from, and key factors that help decide which one to use include the number of elements, whether there are duplicates, and available resources. Sorting algorithms can be classified based on computational complexity, memory usage, whether they are recursive, and whether they are stable or in-place. The document then provides brief descriptions of common sorting algorithms like selection sort, bubble sort, insertion sort, and merge sort. It also defines what a stable sorting algorithm and an in-place sorting algorithm are.

Uploaded by

Krisha Davda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Analysis & Design of Algorithms

This document provides an introduction to sorting algorithms. It discusses that sorting is an important problem in computer science as it is the first step in many algorithms. There are many sorting algorithms to choose from, and key factors that help decide which one to use include the number of elements, whether there are duplicates, and available resources. Sorting algorithms can be classified based on computational complexity, memory usage, whether they are recursive, and whether they are stable or in-place. The document then provides brief descriptions of common sorting algorithms like selection sort, bubble sort, insertion sort, and merge sort. It also defines what a stable sorting algorithm and an in-place sorting algorithm are.

Uploaded by

Krisha Davda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Analysis & Design of Algorithms

I nt r o d uc t i o n t o
• Prepared by:-
Sorting
Sagar Virani

Assistant Professor

Computer Engineering
Department

VVP Engineering College


Introduction to Sorting
• Sorting is the fundamental algorithmic problem in
mathematics and computer science.
• It puts elements in a certain order.
• The most common used orders are numerical and
lexicographical (alphabetical) order.
• Efficient sorting is important to optimize the use of other
algorithms, as it is the first step in most of them.
• There are many sorting algorithms but knowing which one
to use depends on the specific problem at hand.
Introduction to Sorting
Factors that help decide the sort to use are:
• How many elements needed to sort?
• Will there be duplicate elements in the data?
• If yes, does their order need to be maintained after sorting?
• What do we know about the distribution of elements?
• Partially sorted
• Totally random
• Almost sorted
• What resources are available for executing sorts?
• More memory
• More processors
Introduction to Sorting
Sorting algorithms are often classified using different metrics:
• Computational complexity
 Based on worst, average and best-case behavior
 Acceptable behavior – O(n lgn)
 Unacceptable behavior – O(n2)
• Memory usage
 In-place
 Not in-place
• Recursion
 Recursive
 Non-recursive
• Stability
 Stable
 Not stable
Sorting Algorithms
Covered in the Syllabus:
• Selection Sort
• Bubble Sort
• Insertion Sort
• Shell Sort
• Heap Sort
• Counting Sort
• Radix Sort
• Bucket Sort
• Merge Sort
• Quick Sort
Stable Sort
• Stable sorting algorithms maintain the relative order of records

with equal keys (i.e. values).

• That is, a sorting algorithm is stable if whenever there are two

records R and S with the same key and with R appearing before S

in the original list, R will appear before S in the sorted list.

Input List Sorted List

9 2 7 5 2 4 3 6 2 2 3 4 5 6 7 9

R S R S
In-place Sort
• An in-place algorithm is an algorithm that does not need an extra
space and produces an output in the same memory that contains the
data by transforming the input ‘in-place’.
• However, a small constant extra space used for variables is allowed.
• This space is O(log n), though sometimes anything in O(n).
Any Questions?

You might also like