|
Main, Syllabus, Office hours |
Schedule |
Slides |
Daily |
Homework |
Code |
Exams |
Exam 1 | Exam 2 | Final Exam |
General information for exams:
- rules during Exam
- IDs will be checked. Make sure to bring your ID.
- SMART WATCH, tablets, are not allowed in the exam. REMOVE YOUR smart watch
- more logistics information will be added closer to the exam.
- The Cheat sheet (1 page) from the Slides page will be provided by the instructor, along with the exam
- You can bring a scientific calculator (e.g. to use for the index calculations for bucket sort)
- Scantron not needed.
- "How should I study for this exam? What should I focus on?"
- Understand and know how to solve problems from the listed Weekly Quizzes. Some problems will be simmilar to those.
- Review and understand what we covered in class.
- Master writing code for the listed functions
exam in person, in the classroom, during lecture time
Extra resources:
Code - Given the function signature, continue to write code for
- binary search:
int binary_search(int val, int N, int * A)
- insertion sort:
void insertion_sort(int N, int * A)
- Trees code from slides on BST:
-
TreeNodePT search(TreeNodePT tree, int val)
-
TreeNodePT insert(TreeNodePT tree, int newVal)
-
int count(TreeNodePT tree)
// count number of nodes in tree
- traversals (print the data from the nodes of the tree)
-
void inorderPrint(TreeNodePT tree)
-
void preorderPrint(TreeNodePT tree)
-
void postorderPrint(TreeNodePT tree)
- (Remember to handle cases when the tree is NULL for all these functions.)
Topics:
- time complexity of loops and if statements: Theta, dominant term(s), best case/worst case where applicable.
- time complexity - short and long answers. For a long answer, be able to fill in all the steps for a detailed solution (like in the hw). E.g. for nested loops fill in all the information for all loops .
- Growth of functions and summations
- Θ, O, Ω, o,ω,
- order functions by their growth,
- e.g. know that if f(n) =Θg(n))=> f(n) = O(g(n)), but not viceversa
- see practice problems above
- be able to compare strings using alphabetical order
- sorting - insertion sort, count sort, radix sort, bucket sort:
- stable?, adaptive?,
- time complexity, space complexity, data moves,
- be able to show the data after each iteration of the [outer/inner] loop without seeing the code (see practice problems).
- Know when (for what data and requirements) is an algorithm applicable and when not. When would you choose one algorithm over another (e.g. depending on system limitations for memory, or time requirements or some specific distribution of the data)?
- If given code for a variation of one of the sorting algorithms, be able to analyze it: Is it stable? Is it adaptive? What time and space complexity does it have? Is it a direct or indirect sort?
- for bucket sort study both formulas for computing the index: the one used in the homework, floor((elem-min)*N/(1+max-min)) and also the easier one : floor(elem*N)
- Binary search
- Indirect sort for insertion sort. E.g. given Data array, fill in values for the Index array after indirect sorting. Why/when would we use indirect sort?
- binary trees: traversals (inorder, preorder, postorder, level order)
- binary search trees : search,
- Trees:
- tree theory
- binary trees, binary search trees, time and space complexity
-
2-3-4 trees - are NOT part of this exam.
- Not included (not tested in the quiz):
- proving that an algorithm is correct;
- selection sort;
- writing code for any algorithm not explicitly mentioned in the Code bullet
Practice problems:
- W-quizzes
- Understand and know how to solve problems similar to those in Homework 1.
- PRACTICE time complexity of loops. Here are solutions to some of those problems, but they are in the old format (no table). I plan to rewrite at least some of these solutions in teh new format, but meanwhile, you can use them to check your final TC for each loop: Solution to problems A6-A16 except A15 (pdf, docx)
- Growth of functions, summations ( Solution )
- insertion sort, indirect sorting, binary search ( Solution) - NOTE that selection sort is mentioned in some problems, but it is NOT covered this semester.
- count sort, radix sort, bucket sort practice, (Solution ) - Problem NCS3 (about the formula for mapping numbers from [A,B] to [X,Y]) will not be part of the exam.
- Trees:
- Topics:
- 2-3-4 Trees
- Heaps: build heap (bottom up, top down)
- top-k
- heapsort
- Stacks
- Queues
- Hash Tables
- Greedy: Job Scheduling, Knapsack
- Dynamic Programming: Job Schedulling, 0/1 Knapsack, Fibonacci - covered until and including on 3/26
Material covered on Thursday 3/28 will NOT be in the exam.
- Coding for the specific functiosn listed below:
- from FIFO Queues:
-
bool put(Queue * Q, int val)
-
bool get(Queue * Q, int* ret)
- from Stacks
-
struct stack_array newStack(int cap)
-
void destroy(struct stack_array * S)
-
void push(struct stack_array* myStack, int newItem)
-
int pop(struct stack_array * myStack )
- from Knapsack, Job Scheduling, Fibonacci, Stair Climbing
-
int knapsack01(int W, int n, int * v, int * w)
(0/1 Knapsack iterative solution)
-
int js_iter(int* v, int*p, int n)
(Job Scheduling - iterative/bottom up solution)
- Practice problems:
- W-quizzes
- Heaps (Solution)
- Stacks, queues (Solution)
- Hashing (Solution) ;
- Hash table resources: youtube video on Hash Tables and Hash Functions and lecture discussion
- Gredy, DP practice ( Solution) - only the Job Scheduling and Knapsack (greedy and DP) problems are for this exam. Edit DIstance (ED), Longest Common Subsequence (LVS) and Longest Increasing Subsequence (LIS) are NOT part of this exam.
- Update 3/31/24, 4:15pm: corrected typo in solution for KP1 c) from min to max: sol[i][j] =
min max{ sol[i-1][j], sol[i-1][ j-weight[i] ]+value[i] }
- Update 4/1/24, 4:45am - fixed typo in pages 14,15 (from slides Knapsack, Job Scheduling, Fibonacci, Stair Climbing) in table that gives the problem statement it said W=17, but in the table where the solution should be filled up it did not have column 17 (last column was 16). I fixed the problem statement to say W=16. Thanks to Dev for spotting this problem.
- Topics:
- Dynamic programming: Edit Distance (ED), Longest Common Subsequence (LCS) and Longest Increasing Subsequence (LIS), counting paths in a 2D matrix
- Graphs and all the Graph-related topics we covered
- directed, undirected
- degree of a vertex, (out degree, in degree for directed graphs)
- representation: adjacency list, adjacency matrix (and space requirement for each representation),
- BFS, DFS,
- edges (tree, backward ),
- detect if a directed graph is acyclic or not,
- topological sorting,
- Strongly Connected Components ,
- Minimum Spanning Trees - solved with the table of dist/pred as in class/slides
- Shortest Path (Shortest Path Spanning Tree, All-pairs shortest paths) - solved with the table of dist/pred as in class/slides
- Time and space complexity and application for each algorithm.
- The colors and notations used in the slides are referenced in the exam. If a question on that topic is in the exam, it will use the colors from the slide, e.g. WHITE/GRAY/BLACK for nodes.
- Mergesort - algorithm, simulation of it on an array of numbers, time and space complexity. Given code, be able to reason about it or modify it.
- Recurrences
- code <=> recurrence formula
- Master Theorem
- Tree method for solving recurences:
- using the tree method to derive time complexity for Mergesort
- given recurrences, be able to give tree information at level i (number of nodes at level i, problem size for a node at level i, local time complexity for a node at level i) and number of levels in the tree.
- Quicksort - algorithm, simulation of it on an array of numbers, time and space complexity. Updated 4/30/24: required only for section 002, not for section 001.
- QuickSelect (return k-th smallest item) - is not covered in the exam for any section.
- Code
- int editDistance(char * word1, char * word2) - from hw4 solution
- int lengthOfLIS(int* nums, int numsSize) - from your hw3part2 solution
- DFS(G) - code from hw or pseudocode from slides.
- DFS_visit(G,u,...) - code from hw or pseudocode from slides.
- void mergesort(int * A, int left, int right) - from slides
- void Merge(int * A, int left, int middle, int right) - this can be code, or the pseudocode from slides
- Practice problems