0% found this document useful (0 votes)
5 views13 pages

Introduction to Sorting Algorithms

The document provides an overview of sorting algorithms, specifically Bubble Sort and Selection Sort, detailing their definitions, workings, advantages, and disadvantages. Both algorithms are simple and in-place but inefficient for large datasets with a time complexity of O(n²). The document concludes that while these algorithms are useful for educational purposes, more advanced algorithms are preferable for practical applications.

Uploaded by

BHAVY PATEL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views13 pages

Introduction to Sorting Algorithms

The document provides an overview of sorting algorithms, specifically Bubble Sort and Selection Sort, detailing their definitions, workings, advantages, and disadvantages. Both algorithms are simple and in-place but inefficient for large datasets with a time complexity of O(n²). The document concludes that while these algorithms are useful for educational purposes, more advanced algorithms are preferable for practical applications.

Uploaded by

BHAVY PATEL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Name: Chaudhari Devarshkumar Mukeshbhai

Enrollment No: 2301031030037


Rollno: 102
Division: A
Semester: 5th
Introduction to Sorting Algorithms
• Definition: Sorting algorithms arrange elements in a list in a
specific order.
• Importance: Sorting improves efficiency in searching and data
management.
• Examples of use cases in daily applications (e.g., databases,
search engines).
What is Bubble Sort?
• Definition: A simple comparison-based sorting algorithm.
• Working: It repeatedly steps through the list, compares
adjacent elements, and swaps them if they are in the wrong
order.
• Stable: Maintains the relative order of equal elements.
• In-place: Doesn't require extra storage.
Example of Bubble Sort
• Initial Array: [4, 2, 3]

• Pass 1:
• Compare 4 and 2 → Swap: [2, 4, 3]
• Compare 4 and 3 → Swap: [2, 3, 4]
• End of Pass 1: [2, 3, 4]

• Final Sorted Array:


• After one pass, the array is sorted: [2, 3, 4].
Bubble Sort: Pseudocode
for each element in the list
for each element not yet sorted
if current element > next element
swap them

 Explain the simplicity of the algorithm with each step.


Bubble Sort Advantages & Disadvantage
• Advantages:
– Simple and easy to implement.
– Requires minimal additional memory (in-place sorting).
– Works well on small or nearly sorted datasets.

• Disadvantages:
– Very slow for large datasets (O(n²) time complexity).
– Inefficient compared to more advanced algorithms.
What is Selection Sort?
• Definition: Another comparison-based sorting algorithm.
• Working: It repeatedly selects the smallest element from the
unsorted portion and swaps it with the first unsorted element.
• Not stable: It may change the relative order of equal elements.
• In-place: No additional memory needed.
Selection Sort Example
• Initial Array: [3, 1, 2]

• Pass 1:
• Find the minimum: 1 (index 1)
• Swap with first element (3):
• Array: [1, 3, 2]
• Pass 2:
• Find the minimum in the remaining array: 2 (index 2)
• Swap with second element (3):
• Array: [1, 2, 3]
• Final Sorted Array:
•The array is now sorted: [1, 2, 3].
Selection Sort: Pseudocode
for each element in the list
find the minimum element in the unsorted part
swap it with the first unsorted element

 Explain how it reduces the need for many swaps compared to


Bubble Sort.
Time Complexity Comparison
• Bubble Sort:
– Best Case: O(n) (Already sorted list)
– Average & Worst Case: O(n²)
• Selection Sort:
– Best, Average, Worst Case: O(n²)
– Selection Sort is generally more efficient in terms of swaps, but
both are inefficient for large datasets.
Selection Sort Advantages & Disadvantage
• Advantages:
– Simple and easy to implement.
– Performs fewer swaps compared to Bubble Sort.
– In-place sorting with minimal memory usage.

• Disadvantages:
– Inefficient for large datasets (O(n²) time complexity).
– Slower than more advanced algorithms like Quick Sort or Merge
Sort.
Conclusion

• Bubble Sort and Selection Sort are simple but inefficient for large
datasets.
• Both have a time complexity of O(n²).
• Bubble Sort swaps adjacent elements, while Selection Sort selects
the smallest element and swaps.
• Useful for learning basic sorting, but advanced algorithms are
better for real-world use.

You might also like