Types-of-Sorting-in-Database-Structure-and-Algorithms.pdf

10 views 10 slides Nov 13, 2024
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

A Sorting Algorithm is used to rearrange a given array or list of elements in an order. Sorting is provided in library implementation of most of the programming languages.

Basics of Sorting Algorithms:
Introduction to Sorting
Applications of Sorting
Sorting Algorithms:
Comparison Based : Selection ...


Slide Content

Types of Sorting in
Database Structure
and Algorithms
Sorting algorithms are fundamental in computer science, organizing data
efficiently. They play a crucial role in database management and data
processing. Understanding various sorting techniques is essential for
optimizing performance in diverse applications.
by Arya M

Introduction to Sorting
Algorithms
1
Definition
Sorting algorithms arrange data elements in a specific order,
typically ascending or descending.
2
Importance
They enhance data retrieval efficiency and are fundamental
to many computer science applications.
3
Categories
Sorting algorithms are broadly classified into comparison-
based and non-comparison-based techniques.

Comparison-Based Sorting
Algorithms
1
Key Concept
These algorithms compare
elements to determine their
relative order in the sorted
output.
2
Time Complexity
Most comparison-based sorts
have an average time
complexity of O(n log n).
3
Common Examples
Bubble Sort, Selection Sort, Insertion Sort, Quick Sort, and Merge
Sort.

Bubble Sort
1
Compare Adjacent
Bubble Sort repeatedly steps through the list, comparing
adjacent elements and swapping them.
2
Bubble Up
Larger elements "bubble up" to the end of the list with each
iteration.
3
Repeat
The process is repeated until no more swaps are needed,
indicating the list is sorted.

Selection Sort
1
Find Minimum
Selection Sort finds the minimum element in the unsorted
portion of the array.
2
Swap
It swaps this minimum element with the first unsorted
element.
3
Repeat
The process continues until the entire array is sorted in
ascending order.

Insertion Sort
Start
Insertion Sort begins with the
second element, considering the
first as sorted.
Compare
It compares the current element
with previous elements, shifting
them if necessary.
Insert
The current element is then
inserted into its correct position
in the sorted portion.
Repeat
This process continues until all
elements are in their proper
sorted positions.

Quick Sort
Divide
Quick Sort selects a pivot element and
partitions the array around it.
Conquer
It recursively sorts the sub-arrays on
either side of the pivot.
Combine
The sorted sub-arrays are combined to
produce the final sorted array.

Merge Sort
1
Divide
Merge Sort divides the unsorted list into n sublists, each
containing one element.
2
Conquer
It repeatedly merges sublists to produce new sorted sublists
until there is only one.
3
Combine
The final merged sublist is the sorted list, combining
efficiency with stability.

Non-Comparison-Based
Sorting Algorithms
1
Key Concept
These algorithms don't
compare elements directly,
often using numerical
properties for sorting.
2
Time Complexity
They can achieve linear time
complexity, outperforming
comparison-based sorts in
specific scenarios.
3
Examples
Counting Sort, Bucket Sort, and Radix Sort are common non-
comparison-based algorithms.

Radix Sort
1
Least Significant Digit
Radix Sort starts by sorting elements based on their least
significant digit.
2
Iterate
It continues sorting based on each digit, moving towards the
most significant.
3
Final Sort
After processing all digits, the list is completely sorted in
linear time.