🥥 Basic Sorts | Data Structures & Algorithms
Hayden Smith Learning
0:00 / 0:00
🥥 Basic Sorts | Data Structures & Algorithms
3 080 просмотров · 5 лет назад
Hayden Smith Learning
3,44 тыс. подписчиков
3 080 просмотров · 5 лет назад
#DataStructures #Algorithms #Sorting #ComputerScience
This video covers three foundational sorting algorithms: Bubble Sort, Selection Sort, and Insertion Sort. Presented by Hayden Smith, this lecture explains the mechanics and performance characteristics of these simple, O(n²) sorts.
🛁 Bubble Sort
Bubble Sort repeatedly steps through a list, comparing adjacent pairs of elements and swapping them if they are in the wrong order. This process is repeated until the list is sorted.
Time Complexity: O(n²) in the worst and average cases, but O(n) in the best case (if the list is already sorted).
Adaptive: Yes, its performance improves on partially sorted data.
Stable: Yes, it preserves the relative order of equal elements.
✨ Selection Sort
Selection Sort works by dividing the list into a sorted and an unsorted part. It repeatedly finds the smallest element in the unsorted part and swaps it with the first element of the unsorted part, thereby growing the sorted section.
Time Complexity: O(n²) in all cases (worst, average, and best).
Adaptive: No, its performance does not improve on partially sorted data.
Stable: No, it does not guarantee the original order of equal elements.
🃏 Insertion Sort
Insertion sort also builds the final sorted list one item at a time. It iterates through the input elements and, for each element, it finds the correct position in the already-sorted part of the list and inserts it there.
Time Complexity: O(n²) in the worst and average cases, but O(n) in the best case.
Adaptive: Yes.
Stable: Yes.
View the full playlist: • Data Structures & Algorithms