Commit 64326c43 authored by michael lundquist's avatar michael lundquist
Browse files

Adding some class notes.

parent f39ec133
# Linked lists
## module 3 continued
- recursion, base case
### recursion
- __Unary recursion__: when you do one recursive call in your recursive case
- see factorial
- see binary search
- __Binary recursion__: when you do two recursive calls in your recursive case
- see binary sum
- see fibonacci
- __Multiple Recursion__: when you do more than 2 recursive calls in your recursive case.
- dijkstra?
### complexity
- Constant time complexity: $c$, or $O(1)$
- $O(log(n))$
- linear time complexity: $O(n)$
- $O(n^2)$
- complexity and data structures is a thing
- omega is for best case
- theta is for average case
- big O is for worst case
- merge sort is n*log(n)
- there will be a time complexity midterm question
- see the big-O exercises
### linked lists
- This was stupid
\ No newline at end of file
# Linked list 2
- Time complexity of algorithms
- recursive
- non-recursive
## lab2
- add a visualization of the disks moving
- We can assume calling hanoi(source, tmp, dest, n-1) moves all disks up to the last disk from source to dest.
### midterm
- linked lists will be on it
- mid-term is online
### project
- get the proposal from old group
\ No newline at end of file
# Midterm review
- 2.26.19 class
- The previous year's midterms are online
- review composition, aggregation...
- composition: one class can't exist without the other
- aggregation: not as strict as composition
-
\ No newline at end of file
# notes 2_5_19
- last week:
- insertion sort
- 2 loops, O(n^2) time
- linear search
## sorting
- selection sort:
- also O(n^2)
- works by iteratively finding the smallest element, and appending it to the sorted part.
- bubble sort:
- O(n^2)
- Iterate over array swapping elements if they're in the wrong order. Keep iterating over the array until the array is in order
- heap sort
- binary trees:
- the root of the heap is always the minimum (or max) in the tree
- every node should be smaller (or large) that its children, so when you pop from the heap, you need to re-order the heap
- Bucket sort
- number and size of buckets is important
- O(n) time
- large memory footprint
- Stably sort:
- When sorting an array of arrays, sort by the last element first, then second to last...
- Radix sort
- sort on least significant bit, then second significant bit... to most significant bit
- similar to stably sort
- when we do this, we can use strings or math
### assignment
- have a user input for choosing the algorithm
### Lab 1
- work on as a group
- implement Voting application's getWinner method
## Recursion
- the stack pushes and pops recursively
- Recursion steps:
- determine the base case
- determine the recursive case.
### Merge sort
- divide and conquer
- O(n log n)
### quick sort
- also divide and conquer
- finds a pivot point, then does merge sort
- the worst case pivot is one that always pivots on 1
## exercises
- binary search
-
- english ruler
-
\ No newline at end of file
# class notes
- 3_19_19
- grading by end of week
## recap
- linked list = connected chain of nodes
## stacks n queues notes
- see what these things implement and override
### stacks
- LIFO
- only has a top pointer
- has an insert method
- push, pop, peek
- check if the stack is empty before popping
- peek returns, but doesn't remove from the stack
- a stack array can have an integer pointer
- next week depth first search
#### string parsing (in final exam)
- validate brackets with a stack by having a stack that tracks {,[,( as openers and ), ], and } as closers push on openers, pop on closers. When you pop, make sure your opener matches your closer.
- popping on an empty stack causes a failure.
- ending with elements in the stack is an error
#### math evaluation with stacks
- closing brackets means 2 pop from op stack until opening bracket.
- each pop from the op stack is 2 pops from num stack
- after an op, push back to num stack
### queues
- add = queue
- remove = dequeue
- queue has both head and tail, you add to tail, and pop from head.
-
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment