Data structures
- A
- Queues A queue works like a line for an amusement park ride -- people enter at the end of the queue and leave from the front (FIFO: first in, first out).
- Stacks A stack works like a stack of plates -- plates are added and removed from the the top of the stack (LIFO: last in, first out).
Use for:
- Arrays Use for constant time lookup, linerar insertion/removal
- Singly LinkedLists Constant time insert, linear time lookup and removal
- Doubly LinkedLists Constant time insert/removal, but each node takes up a little more space
- Trees Constant time insert/removal, but each node takes up a little more space
Instantiation Style | Pro's | Con's |
---|---|---|
Functional | You believe your solution to be fully complete and meeting the specified requirements. | |
Functional-shared | Your solution is well on its way to being complete, but you ran out of time or can't remember exactly how to do one particular aspect. You believe anyone who understands the problem well would endorse your solution as the right one, and know pretty clearly how to finish up any last touches. | |
Prototypal | You have the right idea and were heading in a good direction. Covers everything between Mostly Complete and Attempted. | |
Pseudoclassical | You were very challenged by the prompt and had trouble making any significant progress on the problem, but wrote at least one meaningful line of code that appears to be a genuine attempt. |
Def algorithm - The system or plan you use to arrive at a solution
- As the size of the problem gets bigger, the cost might grow quickly/slowly/not at all.
- Time complexity - Mathematical comparison between different plans, or algorithm.
- Cheat sheet- bigocheatsheet.com - An approximation of time complexity, describes worst-case performance for large n.
Name | Big-O Notation | Operations for n items | Approach | Example |
---|---|---|---|---|
Constant | O(1) | 1 | Compare first & last numbers | Array lookup, hash table insertion |
Logarithmic | O(log n) | 1 | Def | Def |
Linear | O(n) | 2n | Find largest & smallest numbers | Finding index of an element in an array |
Quadratic | O(n^2) | n^2 | Constant time operation inside two nested for-loops. | |
Exponential | O(c^n) | n^2 | Def | Guessing an n-character long password |