DSA – Arrays, Searching & Sorting
Array Basics
Ordered, fixed-size collection of same-type elements, contiguous in memory
Index range: (direct access via subscript )
Size formula:
Core Array Operations
Traversal: visit each element once (read, print, process)
Insertion at position
• If → append • Else shift right from , place new item, updateDeletion at position
• Save , shift left , decrement
2-D & Multidimensional Arrays
Represented as rows & columns:
Memory layouts
• Row-major: store rows consecutively
• Column-major: store columns consecutivelyRagged arrays: rows of unequal length
Searching Algorithms
Linear (Sequential) Search
Scan from first to last element
Works on unsorted arrays
Complexity: best , worst , average ⇒
Binary Search
Requires sorted array
Repeatedly halve search range using middle element
Complexity: worst ⇒
Sorting Algorithms
Selection Sort
Repeatedly select smallest remaining element and swap into place
comparisons, swaps
Bubble Sort
Repeatedly swap adjacent out-of-order pairs; large items “sink”
Worst comparisons & swaps; best (already sorted)
Insertion Sort
Insert each element into its correct place within sorted prefix
Worst , best (nearly sorted)
Merge Sort (Divide & Conquer)
Recursively split array, sort halves, merge
Time , extra space
Quick Sort (Divide, Partition, Conquer)
Partition around pivot into < pivot, = pivot, > pivot; recurse on subarrays
Average ; worst (e.g., already sorted with bad pivot)
Radix Sort
Non-comparison sort; group items by each digit/character from least to most significant
Time for digits; high memory overhead, suited to linked lists
Complexity Comparison (Key Results)
Quadratic sorts (Selection, Bubble, Insertion): worst-case; only viable for small or nearly sorted data
Efficient comparison sorts: Merge & Quick (avg) , Heap sort (not detailed) also
Search: use Binary search on sorted data for speed; otherwise Linear search