Ontological Layer: Data Retrieval and Ordering
Searching & Sorting
Algorithms for Organizing the Chaos
The Imperative of Order
Data structures only hold information; algorithms make that information usable. To find a single element among millions requires strategy. We search linearly by brute force, or logarithmically by exploiting sorted order. We create that order by sorting—swapping, selecting, or dividing and conquering. And when pure speed is demanded, we abandon sequential search entirely, using Hashing to calculate the exact address of the data we seek.
The 13 Algorithmic Nodes
Ontological Mapping: Strategies of Retrieval and Arrangement
Linear Search
- Sequential, element-by-element check
- Requires no specific data order
- O(N) worst-case time complexity
- General purpose but slow for large sets
Binary Search
- Requires strictly sorted data
- Divides search space in half each step
- Low, Mid, and High pointers
- O(log N) worst-case efficiency
Bubble Sort
- Adjacent element comparisons
- Swaps if out of order
- Largest elements "bubble" to the end
- O(N²) complexity, simple but inefficient
Selection Sort
- Scans for absolute minimum/maximum
- Places extreme at the front/end
- Shrinks the unsorted boundary
- O(N²) complexity, fewer swaps than bubble
Insertion Sort
- Maintains a sorted prefix region
- Takes next item, shifts larger items right
- Inserts into correct sorted position
- Efficient for nearly sorted data O(N)
Merge Sort
- Divide and Conquer paradigm
- Recursively split array into halves
- Merge sorted halves back together
- Guaranteed O(N log N) complexity
Quick Sort
- Selects a Pivot element
- Partitions into [ < Pivot ] and [ > Pivot ]
- Recursively sorts partitions
- Fastest in practice, O(N²) worst-case
Heap Sort
- Converts array into a Max/Min Heap
- Extracts extreme element to array end
- Restores heap property (Heapify)
- In-place O(N log N) sort
Hashing Concept
- Bypasses sequential comparison
- Hash function computes direct index
- Key → Hash(Key) → Table Address
- Goal is O(1) constant retrieval time
Hash Collisions
- Two distinct keys map to same index
- Inevitable due to limited table size
- Load Factor = Items / Table Size
- Necessitates resolution strategies
Separate Chaining
- Each table index holds a Linked List
- Colliding keys are appended to the list
- Graceful degradation under high load
- Requires dynamic memory allocation
Open Addressing
- All elements stored directly in table
- Linear Probing (Check next adjacent slot)
- Quadratic Probing (Check i² slots away)
- Double Hashing (Use second hash func)
13 — Searching & Sorting Laboratory
These algorithms dictate how software handles volume. A poor sort choice brings a system to a halt; a good hash function makes retrieval instantaneous. Understanding exactly *why* Merge Sort outpaces Bubble Sort leads directly into the next logical step: Realm 08 and the formal Mathematics of Efficiency.