🎭 Abstract Data Types (Interfaces)
Array (Abstract Interface)
- Abstract Data Types
- Concrete Data Types
List
- Concrete Data Structures
Stack
- Last in, first out (LIFO)
- Operations
push(aka.append)pop
- Useful for tasks divided into sub-tasks
- Tracking tokens while parsing
- Concrete Implementation
🧑🏭 Algorithms
- Incrementally builds candidate solutions & backtracks/abandons candidate when it's no longer viable.
- Ideal for constraint satisfaction problems.
- Comparison-based
- Determines if "key" is less, equal, or greater than another.
- Typical sorting algorithm in standard libraries.
- Most optimal worst-case time complexity:
O(n log n) - Heapsort
- In-place; unstable
- Slower than quicksort in practice.
- Time complexity
- Best:
O(n)equal keys;O(n log n)distinct keys - Average / Worst:
O(n log n)
- Best:
- Auxiliary space complexity
- Worst:
O(1)
- Worst:
- Quicksort
- Divide-and-conquer / recursive algorithm; typically unstable.
- Ideal pivot point is middle value -- for guaranteed
O(n lg n)for sorted data. - Time complexity
- Best / Average:
O(n * log n) - Worst:
O(n^2)
- Best / Average:
- Auxiliary space complexity
- Naive:
O(n) - In-place:
O(log n)
- Naive:
- An array is a contiguous sequence of the same type.
- A memory buffer is (pre)allocated for all elements.
- Random access of any element (via index).
- Lookup by index:
O(1)time - Lookup by value:
O(n)time - Dynamic Array
- Occasionally resized (copies elements; typically faster than dynamic allocations required by linked list).
- Typical "array" type for scripting languages (typically with static array(s) utilized internally).
- Insertion / Deletion:
Amortized O(1)|O(n)time
- Static Array
- Cannot be resized at runtime; must re-allocate buffer & copy.
- String
- Typically a read-only array of characters.
- Variable-Length Array
- Length determined at runtime.
- Not growable; generally preferable to use a dynamic array instead because it's growable.
- Each element dynamically allocated (typically slower than occasional copies required by dynamic array).
- Complexities:
- Lookup:
O(n)time - Insertion / Deletion:
O(1)time
- Lookup:
- Design code before writing:
- To have a plan & avoid getting stuck.
- To collaborate on approach for solution.
- Because jumping straight into coding, on large projects, is a bad idea.
- Example Sorting Implementations - Neetcode
- Algorithms - Kahn Academy (Cormen/Balkcom)
- VisuAlgo - visualising data structures and algorithms through animation
Introduction to Algorithms
- Third Edition
- CLRS Solutions - walkccc
Cracking the Coding Interview
- Solutions - 6th edition
- Solutions - 5th edition
- Behavioral - prep sheet
- Coding - flow chart
- PM - interview questions
- Algorithms 1 - Stanford
- Algorithms 2 - Stanford
- BINARY TREES
- HASH TABLES
- Design Hashmap - Neetcode
- Intro to Hash Tables and Dictionaries - CS Dojo
- HEAPS
- Heaps in 3 minutes — Intro - Michael Sambol
- LOGARITHMS
- Logarithms... How? - NancyPi
log2(n) => 2x = n
- Log base2 using calculator
log2(n) = ln(n) / ln(2)
- Logarithms... How? - NancyPi
- QUICKSORT
- Complete Quicksort Overview - CS Dojo
- Quicksort algorithm - mycodeschool