Notes/UNB/Year 5/Semester 2/CS3383/Lecture Notes.md

39 lines
2.5 KiB
Markdown
Raw Permalink Normal View History

2025-01-08 13:50:24 -04:00
### Running Time
Most Algorithms transform input objects into output objects. The running time typically grows with the input size. Average case time is often difficult to determine. We focus on the worst case running time, as it's easier to analyze and its crucial to applications such as games, finance, and robotics.
### Space Complexity
In algorithms, you need to think about the amount of space, memory, that you need to compute the algorithm.
### Algorithm Structure?
2025-01-08 14:20:02 -04:00
Need to think about how complex an algorithm is in implementation, the simpler the better. Code organization is also important in the structure.
### Fibonacci
Algorithm which uses array to store previous fib numbers vs one which uses constant number of variables to compute the sequence. Space complexity varies between the two between one being O(n) and one is O(1).
2025-01-10 14:17:23 -04:00
The naive recursive solution for this problem is very bad. By using multiple return values we can make the recursive algorithm equal to the non-recursive algorithm.
### Counting Primitive Operations
The algorithm described is a simple implementation to find the max value of an array containing only numbers
By inspecting the pseudo-code, we can determine the maximum number of primitive operations executed by an algorithm, as a function of the input size.
Looking at the number of times n is used, in the worst case scenario, we can see a for loop, as well as other stuff? ending up with a number of operations of 8n-2, with a big O of O(n)
### Relatives of Big O,
- Big Omega
2025-01-14 08:38:50 -04:00
- Big Theta - If this is n squared, it means big omega and big o are also n squared.
## GO over slides for Jan 13th as I missed first half
### Greedy Algorithms
Greedy algorithms always optimize for the current best chest, ignoring any possible better outcomes in the future.
This can work in cases where a problem has a greedy property.
### Making Change Problem
2025-01-15 13:41:37 -04:00
In the case where the denominations are always larger/equal to 2 of the smaller denominations then it makes sense when giving change, to simply give the largest coin available.
2025-01-15 13:59:38 -04:00
### Fractional Knapsack Problem
Given a set S of n items, with each item i having a positive benefit factor, b, and a positive weight, w.
Goal: Choose items with maximum total benefit but with weight at most W.
If we are allowed to take factional amounts, then this is the fractional knapsack problem. The objective is to maximize the benefit given the amount divided by the weight, with the constraint that the amount is less than the total amount W.
2025-01-22 13:41:46 -04:00
### Interval Partitioning: Greedy