●
●
●
●
●
Solving problems efficiently
Time complexity
○ Relationship between growth of input size and growth of operations execution
○ Big O Notation
■ Mathematical notation used to classify algoti to how their run time or
space requirements grow as input size grows
●
Space complexity
○ Relationship between growth of input size and growth of space needed
Logarithms
○ Inverse of exponential growth
○ Example: word search
■ Linear: start at the beginning and keep going until you find one
■ Logarithmic: start at the midpoint, if you passed check first half, rinse and
repeat
● “Binary Search”
● Requires the dataset to be “sorted”
Sorting algorithms
○ Linear scan (Selection sort(
■ Start at the beginning with a pointer, use a second selection to iterate,
find the minimum then swap with the pointer
■ Linear scan of every element (becomes n*O*(n) = O(n^2) )
○ Merge sort
■ Splits selection in halves until two values that can be sorted in constant
time
■ Merges subcollections until the entire list is sorted
■ Complexity
●
●
●
●
●
●
●
●
●
●
Have to merge log(n) sublists
Cost of merging two lists is O(n)
Therefore, total complexity is O(nlogn)
○ Most efficient sorting algorithm possible
Arrays
○ Indexed chunk of data that takes a fixed data size
○ Fixed size, cannot append/remove
Linked list
○ List of nodes that has 1) your data and 2) a pointer to the next piece of data
○ Cannot be accessed in real time
Binary Tree
○ Nodes point to 2 other nodes
○ Node with no children = leaf
○ “Binary search tree”
■ The value of the left sub-tree is less than the value of the parent
■ The value of the right is greater or equal than the value of the parent
■ Find a value (x)
● Go to the root
● If key is greater than x, go left
● Larger, go right
● Max complexity is height of tree (h)
● Workhorse that can solve most problems
Heap
○ Tree-based structure where parent bodes have greater than or equal prioriuty to
child notes
○ “Oruiruty que)
○ We only care about whats at the top
Traversals
○ “Depth first search”
■ Go as deep as possible
■ Uses a stack
● Add or remove from the or bottem
○ Breadth first seach
■ Go through levels first
■ Addo r remove from the top
Graph
○ All trees are graphs, but not all graphs are trees
○ Verticies (points) and edges (connections)
■ Connetions can be made directional
Hash-maps
○ Holy grail of data structures
○ Array of keys plus values
○ Can be added, deleted, retrieved in constant time