October 2025
Intermediate to advanced
485 pages
13h 2m
English
This entire discussion of benchmarking came about as a result of contrasting Mergesort with Quicksort in the previous chapter, so let’s use benchmarking to see for ourselves whether Quicksort is truly the faster algorithm.
Following is the Quicksort code from Volume 1, Chapter 13:
| | class SortableArray: |
| | |
| | def __init__(self, array): |
| | self.array = array |
| | |
| | def partition(self, left_pointer, right_pointer): |
| | pivot_index = right_pointer |
| | pivot = self.array[pivot_index] |
| | right_pointer -= 1 |
| | |
| | while True: |
| | |
| | while self.array[left_pointer] < pivot: |
| | left_pointer += 1 |
| | |
| | while self.array[right_pointer] > pivot: |
| | right_pointer -= 1 |
| | |
| | if left_pointer >= right_pointer: |
| | break |
| | else: |
| | self.array[left_pointer], ... |
Read now
Unlock full access