Save
...
2.1 Algorithms
2.1.3 Searching and Sorting Algorithms
Understanding the following standard sorting algorithms
Save
Share
Learn
Content
Leaderboard
Share
Learn
Cards (39)
What is a sorting algorithm?
Arranges elements in order
Sorting is a prerequisite for advanced algorithms like binary
search
Which sorting algorithms have a higher time complexity but are simpler to implement?
Bubble Sort and Insertion Sort
Bubble Sort and Insertion Sort are examples of
stable
algorithms.
In Bubble Sort, the algorithm stops when no more
swaps
are needed.
In Insertion Sort, the current element is inserted into the
sorted
portion.
Sorting algorithms improve the
efficiency
of data access.
True
Bubble Sort has a space complexity of
O(1)
Merge Sort has a space complexity of
O(n)
How many passes are required in Bubble Sort to sort a list completely?
Depends on the list
Insertion Sort is efficient for large lists.
False
Selection Sort is a stable sorting algorithm.
True
Why is sorting data important for efficiency?
Many algorithms work better
Insertion Sort
builds the final sorted array one item at a time.
True
Quick Sort is an unstable algorithm because the pivot selection can change the relative order of equal
elements
Steps of Bubble Sort in order:
1️⃣ Compare the first two elements
2️⃣ If the first is greater, swap them
3️⃣ Move to the next pair
4️⃣ Repeat until the end of the list
5️⃣ Repeat passes until no swaps are needed
Steps of Insertion Sort in order:
1️⃣ Start with the second element
2️⃣ Compare with sorted portion from right to left
3️⃣ Insert into correct position
4️⃣ Shift larger elements to the right
5️⃣ Repeat for unsorted portion
In Quick Sort, a
pivot
element is chosen to partition the array.
What is the time complexity of Bubble Sort?
O(n^2)
What is the time complexity of Merge Sort?
O(n log n)
Steps of Bubble Sort
1️⃣ Compare the first two elements of the list
2️⃣ If the first element is greater than the second, swap them
3️⃣ Move to the next pair of elements (second and third)
4️⃣ Repeat steps 2-3 until you reach the end of the list in this pass
5️⃣ Repeat these passes until no more swaps are needed
Steps of Insertion Sort
1️⃣ Start with the second element in the list
2️⃣ Compare the current element with elements in the sorted portion
3️⃣ Insert the current element into its correct position
4️⃣ Repeat steps 1-3 for each element in the unsorted portion
In Selection Sort, the minimum element is swapped with the first element of the
unsorted
portion.
Steps of Merge Sort
1️⃣ Split the list into two equal halves
2️⃣ Recursively sort each half
3️⃣ Merge the two sorted halves
Quick Sort is a stable sorting algorithm.
False
What is the role of the pivot in Quick Sort?
Divide the array
Sorting data improves its
organization
and accessibility.
True
Match the sorting algorithm with its description:
Bubble Sort ↔️ Swaps adjacent elements
Insertion Sort ↔️ Builds sorted array one item
Merge Sort ↔️ Divides, sorts, and merges
Quick Sort ↔️ Uses a pivot to partition
Bubble Sort is a
stable
sorting algorithm.
True
Merge Sort requires more space than
Bubble Sort
.
True
Bubble Sort is efficient for large lists.
False
Insertion Sort maintains a
sorted
and an unsorted portion of the list.
True
Merge Sort recursively divides the array into two
halves
.
Bubble Sort is a stable sorting algorithm.
True
Merge Sort is a stable sorting
algorithm
.
True
Insertion Sort maintains a
sorted
and an unsorted portion of the list.
What is the primary action of Selection Sort in each pass?
Find the minimum element
What strategy does Merge Sort use to sort a list?
Divide and conquer
Steps of Quick Sort
1️⃣ Choose a pivot
2️⃣ Partition the array based on the pivot
3️⃣ Recursively sort sub-arrays