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

Sorting_Algorithms

Uploaded by

Mohd Faizan Alam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Sorting_Algorithms

Uploaded by

Mohd Faizan Alam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Sorting Algorithms

What is Sorting?
• Sorting is the process of arranging data in a specific order, such as
ascending or descending.

Common Sorting Algorithms


1. Bubble Sort

◦ Repeatedly swaps adjacent elements if they are in the wrong


order.
◦ Time Complexity:
▪ Best: O(n)
▪ Worst: O(n²)
▪ Average: O(n²)

2. Selection Sort

◦ Finds the smallest element and places it at the beginning.


◦ Time Complexity:
▪ Best: O(n²)
▪ Worst: O(n²)
▪ Average: O(n²)

3. Insertion Sort

◦ Builds a sorted array one item at a time.


◦ Time Complexity:
▪ Best: O(n)
▪ Worst: O(n²)
▪ Average: O(n²)

Advanced Sorting Algorithms


1. Merge Sort

◦ Divides the array into halves, sorts them, and merges them.
◦ Time Complexity:
▪ Best: O(n log n)
▪ Worst: O(n log n)
▪ Average: O(n log n)

2. Quick Sort

◦ Uses a pivot to partition the array and sorts recursively.


◦ Time Complexity:
▪ Best: O(n log n)
▪ Worst: O(n²)
▪ Average: O(n log n)

Applications of Sorting

• Organizing data for binary searches.


• Arranging data for efficient merging and filtering.
• Enhancing visualization techniques.

You might also like