πŸ”’ Array β€” Complete Topic Index

Parent: DSA Master Index


πŸ“¦ Subtopics

#SubtopicFileKey Concepts
1Array Basics01-basics/Declaration, traversal, CRUD, memory
2PHP Array Functions02-php-array-functions/map, filter, reduce, sort + when to use
3Sorting Algorithms03-sorting/All 12 algorithms, complexity, use cases
4Searching04-searching/Linear search, binary search, patterns
5Two Pointers05-two-pointers/Pair problems, duplicates, reverse
6Sliding Window06-sliding-window/Fixed/variable window, subarray problems
7Prefix Sum07-prefix-sum/Range queries, running totals
8Interview Questions08-interview-questions/Top 30 questions with solutions

🧠 Array β€” Big Picture

Array
 β”œβ”€β”€ Static Operations        β†’ Access O(1), Insert/Delete O(n)
 β”œβ”€β”€ Traversal Patterns       β†’ Single loop, nested loop, while
 β”œβ”€β”€ Sorting                  β†’ 12 algorithms (see subtopic 3)
 β”œβ”€β”€ Searching                β†’ Linear O(n), Binary O(log n)
 β”œβ”€β”€ Two Pointers             β†’ O(n) solutions for O(nΒ²) problems
 β”œβ”€β”€ Sliding Window           β†’ Subarray / substring problems
 └── Prefix Sum               β†’ Precompute for O(1) range queries

⏱️ Time Complexity Cheat Sheet

OperationArrayNotes
Access by indexO(1)Direct memory address
Search (unsorted)O(n)Linear scan
Search (sorted)O(log n)Binary search
Insert at endO(1) amortizedPHP arrays are dynamic
Insert at middleO(n)Shift elements
Delete at middleO(n)Shift elements
SortO(n log n)Best general-purpose

🎯 Interview Pattern Recognition

See these keywords β†’ Think this:

Keyword in QuestionTechnique to Use
"subarray of size k"Sliding Window (Fixed)
"longest subarray with..."Sliding Window (Variable)
"pair that sums to X"Two Pointers
"duplicates"Hash Map or Two Pointers
"sorted array, find..."Binary Search
"range sum", "prefix"Prefix Sum
"sort this array"Quick Sort / PHP sort()
"frequency of elements"Counting Sort / Hash Map
"rotate array"Two Pointers (reverse trick)
"merge two sorted arrays"Merge Sort technique