|
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.
- Headphones not allowed.
- Caps not allowed. If you have a reason why you have to wear one, talk to the instructor beforehand.
- 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 BASIC calculator (without data storage, except a single value like that accessed with M+/M-/MR/MC). You may need it 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 similar to those.
- Study the topics and practice problems from the Exams page.
- Study the hw problems.
- Study material covered in class (examples done in class, discussions from class).
- Make sure you are familiar with the format for the solutions for the problems. They will be worded in the exam the same way as in past assessments and examples (WQ, Hw, class examples, slides, sample problems posted on the Exams page). You should not be in the case where you do not know what you are supposed to fill in a table.
- Note that some tables in exam may have MORE rows/columns than needed so that you use as many as you need and not be guided by the number of rows or columns in your solution.
- Master writing code for the functions listed in the Code section for each exam. We will give some partial credit, but not as much and not if the logic is wrong. There is a 95% chance of having a coding problem in each exam and they will be from the list in the Code bullet.
- Know space and time complexity for all algorithms.
- Know how to solve TC for code (loops with tables), and for recursive functions with the tree method and the Master Theorem method (after they are covered). Be able to write the recurrence formula for a piece of code (after recurrence formulas are covered).
- Rules and logistics:
- students must take the exam for their section.
- either no calculator or at most a basic calculator allowed. This will be decided closer to the exam.
- Code - Given the function signature, continue to write code for
- basic/"building block" algorithms over strings, 1D arrays, 2D arrays
- find min or max. E.g.
int get_min(int *arr, int N)
- sum or product over array values. E.g.
int sum_over_array(int *arr, int N)
- answer none/some/all questions. E.g.,
int no_negatives(int arr[], int N)
return 1 if every number is 0 or higher. Else (if at least one number is negative) return 0 .
- check if one string is a substring of another string
- binary search:
int binary_search(int val, int N, int * A)
// use the variable names from arguments
- insertion sort:
void insertion_sort(int * arr, int sz)
// use the variable names from arguments
- indirect sorting (using an array of pointers to strings, or an array of indexes) (- because it was part of the hw)
- individual components of count sort:
- counting keys
- prefix sum (also known as cummulative sum)
-
void Mergesort(int *A, int left, int right)
- from slides . This is just the Mergesort function. The code/pseudo code for Merge() function is not on this list.
- pseudocode that was covered in lecture (can be found on the Quicksort document) for:
void Quicksort(int *A, int start, int end)
and
int Partition(int *A, int start, int end)
- Topics
- logs that you must be able to answer without a calculator. Remember that lg() = log_2().
- lg for: 1,2,4,8,16,32,64,128,256
- log_3 for: 1,3,9,27,81
- log_4 for 1,4,16,64
- log_5 for: 1,5,25,125
- log_6 for: 1,6,36
- log_7 for: 1,7,49
- log_8 for: 1,8,64
- log_9 for: 1,9,81
- log_10 for: 1,10,100, 1000,10000, (any power of 10)
- time complexity (for loops, if statements, functions): 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
- Recurrences
- code => recurrence formula (Given code, be able to write the recurrence formula)
- Tree method for solving recurences:
- using the tree method to derive time complexity for Mergesort and other recursive functions
- 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.
-
?? Master Theorem - to be decided if it will be included. Will not be included.
- be able to compare strings using alphabetical order
- sorting - selection sort. Be able to show array after each next min value is put in place, as done in class.
- sorting - insertion sort, count sort, radix sort, bucket sort, merge sort, quicksort. For each of these algorithms know all the requirements listed below:
- 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: 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?
- To be decided:
QuickSelect (return k-th smallest item)
- Not included (not tested in the quiz):
- proving that an algorithm is correct;
- writing code for any algorithm not explicitly mentioned in the Code bullet
- QuickSelect
- Master Theorem
Practice problems:
- W-quizzes
- Understand and know how to solve problems similar to those in Homework 1.
- PRACTICE time complexity of loops, and Solution to a couple of problems (pdf, docx)
- Growth of functions, summations ( Solution )
- insertion sort, indirect sorting, binary search ( Solution)
- count sort, radix sort, bucket sort practice, (Solution ) - Problem NCS3 (about the formula for mapping numbers from [A,B] to [X,Y]) will probably not be part of the exam.
- Merge sort, Quick sort (Solution)
- Recurrences ( Solution ) - Master Theorem will not be part of this exam.
exam in person, in the classroom, during lecture time for each section.
No calculator - updated 3/30 at 9:52pm
students must take the exam for their section.
Code
Topics:
- topics from exam 1 - Added 03/25, 1:10pm
- know what sorting algorithm to use in a specific case and what it's time complexity is (e.g. se insertion sort of data is almost sorted or if need O(1) space, use Merge sort if need guaranteed TC of NlgN) - Added 03/25, 1:10pm
- still need to know the log calculations from exam 1 (e.g. log_2(32) = ???) - Added 03/25, 1:10pm
- Θ, O, Ω, o,ω - as they apply to analysis of code. E.g. search or insert is O(height), but print tree is Θ(N)- Added 03/25, 1:10pm
- 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 .
- Recurrences
- code <=> recurrence formula
- Master Theorem
- Amortized TC calculations - See video in Canvas and W4 quiz. - Updated 3/30, at 10:10am
- Stacks
- Queues
- Heaps: build heap (bottom up, top down)
- top-k - find the top-k largest items in an array. Both methods: 1) using a max-heap, 2) using a min-heap
- heapsort
- Trees:
- binary trees: traversals (inorder, preorder, postorder, level order).
- binary search trees : search,
- binary search trees : search, insert, range of values in a subtree of a BST, performance of a BST - will be in exam 2 (These topics were covered on or before Tuesday 2/25) - Updated 2/26, 6:45am
-
valid path in a BST, min, max, orderwise predecessor/successor, rotations (left and right rotations at a node). Be able to answer/simulate these for a tree on paper and also know the TC and SC of the methods that implement them. - To be voted on Thursday 2/27 if they will be in Exam 2 or Final exam - Updated 2/27, 6:45am Removed from this exam according to vote. Moved to the Final Exam.
- tree theory (full tree, complete tree, nearly complete tree and their properties)
- binary trees, binary search trees, time and space complexity
- 2-3-4 trees - not part of Exam 2 (will be part of the Final exam)
Practice problems:
- Code
-
int hash(char *s, int M)
-
hash function from slides that computes a hash value for a string using a process similar to the base conversion for numbers. - Updated 4/7/25 at 10:32am
-
int hash(char *s, int M, int a)
- same as above, but with a passed as an argument. - Updated 4/7/25 at 10:32am
-
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)
-
int Fib_iter(int N)
( iterative version that uses array )
-
int Fib(int N)
( recursive version , but not memoized)
- code for the LCS algorithm (pseudocode) and backtracking algorithm (pseudocode) from slides.
- basic/"building block" algorithms
- old: all "basic algorithms" from Exam 2
- new: basic algorithms over 2D arrays (e.g. find min, max, sum). Be able to iterate over the entire 2D array or over just one row or just one column.
- Practice problems
- Topics:
- Past topics:
- TC of loops (with tables) as in Exam1 and Exam 2
- Recurrences
- code <=> recurrence formula
- Master Theorem
- Tree method/tree table
- sorting, linear and binary search as components to other methods. Know the TC and SC of linear search, binary search and insertion sort (good when data is almost sorted) and a sorting alg that has good TC performance (e.g. mergesort with O(NlgN) TC and O(N) SC) .
- BST - valid path in a BST, min, max, orderwise predecessor/successor, rotations (left and right rotations at a node). Be able to answer/simulate these for a tree on paper and also know the TC and SC of the methods that implement them.
(The tree topics that were part of exam 2, e.g. inorder traversal, are NOT part of the Final exam.)
- 2-3-4 trees
Summary for 2-3-4 trees and Hash Tables, prepared by Carl
- Hash tables
- youtube video on Hash Tables and Hash Functions and lecture
- Given a hash function, be able to compute the index for hashing a given key (for integers and for strings)
- separate chaining and open addresing (linear probing, +3 rehash, quadratic hashing, double hashing)
- primary clustering, secondary clustering (
- load factor and resizing a hash table
- operations in hash tables: search, insert, delete,
- Greedy: Job Scheduling, Knapsack
- Dynamic Programming: Job Schedulling, 0/1 Knapsack, Fibonacci, counting paths in a 2D matrix, Edit Distance (ED), Longest Common Subsequence (LCS) and Longest Increasing Subsequence (LIS),
- 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.