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 ...
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 Sort, Bubble Sort, Insertion Sort, Merge Sort, Quick Sort, Heap Sort, Cycle Sort, 3-way Merge Sort
Non Comparison Based : Counting Sort, Radix Sort, Bucket Sort, TimSort, Comb Sort, Pigeonhole Sort
Hybrid Sorting Algorithms : IntroSort, Tim Sort
Library Implementations:
qsort() in C
sort() in C++ STL
Arrays.sort() in Java with examples
Collections.sort() in Java with Examples
Sort a List in Python
Sorting in JavaScript
Easy Problems on Sorting:
Check if an array is Sorted
Sort an array of two types
Sort a String
Sort Each Row of a Matrix
Sort a Matrix
Sort a Linked List
Sort in Wave Form
Sort by Frequency
Sort from Different Machines
Check if any two intervals overlap
Missing elements of a range
Sort by set bits counts
Sort even and odd placed in different orders
Sorting Big Integers
Sort strings by lengths
Merge Two Sorted Arrays
Sort when two halves are sorted
2 Sum - Pair in a Sorted Array
Intersection of two sorted arrays
Union of two sorted arrays
Meeting Rooms
Medium Problems on Sorting:
Minimum Increments to Make Unique
Merge Overlapping Intervals
Minimum Platforms
Closest Pair of Elements
Closest Pair of Points
Chocolate Distribution Problem
Min and Max Amount to Buy All
Three Way Partitioning
Sort an array of 0s, 1s and 2s
Sort a linked list of 0s, 1s and 2s
Inversion count
K-th Smallest Element
K Smallest Elements
3 Sum - Find Any
3 Sum - Closest Triplet
Smallest Difference Triplet from Three arrays
Merge K Sorted Arrays
Merge K Sorted Linked Lists
Min Unsorted Subarray to make array sorted
Sort a nearly sorted array
Sort n numbers in range from 0 to n^2 – 1
Sort an array of 1 to n
Sort according to order defined by another
Maximum intervals overlap
Permutation with worst Case of Merge Sort
Minimum swaps to make two arrays identical
Permute two arrays such that all pair suns are greater than K
Bucket Sort To Sort an Array with Negative Numbers
Convert an Array to reduced form using Vector of pairs
Check if array can be sorted with conditional swapping of adjacent
4 Sum - Find Any
[More problems an 4 Sum are in Hard Section]
Hard Problems on Sorting:
Merge Without Extra Space
Top K Frequent Elements
3 Sum - Distinct Triplets
4 Sum - Distinct Quadruples
4 Sum - All Quadruples
4 Sum - Closest Quadruple
Surpasser Counts in an Array
Count distinct occurrences as a subsequence
Minimum consecutive number subsets
Minimum swaps for Binary Tree to BST
K-th smallest element after removing some integers from natural numbers
Max frequency diff such greater freq item is also is also greater
Min swaps to reach permuted array with at most 2 positions left swaps allowed
Making Array Elements Same
Sort an array after applying an equation
Array of strings in
Size: 1.86 MB
Language: en
Added: Nov 13, 2024
Slides: 10 pages
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.