Searching and Sorting I Flashcards
(7 cards)
What is a Sequential (Linear) Search ?
Scans each element one by one,
Simple but time inefficient (O(n)),
Useful for unsorted arrays.
What is a Binary Search ?
Repeatedly divides the search range in half,
Efficient on sorted arrays (O(log n))
Can be implemented iteratively or recursively.
What is an Interpolation Search ?
Uses the estimated position of the search key
Optimised for uniformly distributed data (average case = O (log log n), worst case = O(n))
More precise than binary when data is evenly spaced (e.g. 1,2,3,4)
What is a Bubble Sort ?
Repeatedly swaps adjacent elements if they’re out of order,
Very inefficient - (On^2)
What is an Insertion Sort ?
Builds sorted arrays one element at a time,
Efficient for small or nearly sorted arrays,
Best = O(n), worst = O(n^2)
What is a Merge Sort ?
Recursively splits the array then merges sorted halves,
Very efficient but needs additional space,
Time complexity = O(n log n)
Space Complexity = O(n)
What is a QuickSort ?
Selects a pivot, partitions the array and recursively sorts subarrays,
Average = O(n log n)