_____________________________________ CS 202 (FALL 2019) - EXAM 2 OUTLINE _____________________________________ 1 C Programming =============== 1.1 Keywords ~~~~~~~~~~~~ Know ALL the keywords, and what they do. 1.2 Loops and Control Flow ~~~~~~~~~~~~~~~~~~~~~~~~~~ Should know / be able to do the following: - Differences between the different types of loop (for and while) and control flow (if/else/else if, switch, break, continue) statements and when to use them - Evaluation of boolean expressions - Use preprocessor directives - #include, #ifndef, #define, #if 1.3 Operators and Expressions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Know ALL the operators and their meaning. Given a C expression, evaluate it. 1.4 Functions Every Citizen Should Know ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Study the functions in the file, except process management / threads / synchronization. - Understand why you might use each function, the meaning of the parameters, and the meaning of the return values. 1.5 Memory ~~~~~~~~~~ Should know / be able to do the following: - Where a variable is stored in program memory, give examples of each. - Describe program memory and its components - Functions to dynamically allocate memory, and when to use them 1.6 Write a program ~~~~~~~~~~~~~~~~~~~ You may be asked to write a small program that demonstrates your knowledge of the topics mentioned above. In particular any questions similar to those on the programming assessment are fair game. 2 Data Structures and Algorithms ================================ 2.1 Asymptotic Complexity ~~~~~~~~~~~~~~~~~~~~~~~~~ Should know / be able to do the following: - Given a program loop, give the time complexity in Big O notation. * Example: worst/base-case running time of the following pseudocode in terms of n. A = array of n #'s total = 0 for i = 0 .. len(A) for j = i .. len(A) for k = j .. len(A) total += A[i] * A[j] * A[k] * Example: worst/base-case running time of the following pseudocode in terms of n. B = BST, not necessarily balanced, with n nodes total. count_neg(B) if (B == NULL) return 0 t = count_neg(B->left) if (B->data < 0) t = t + 1 + count_neg(B->right) return t - Given two time complexities in Big O notation, tell which is faster or slower. Be able to use the rules of thumb (polynomials outgrow poly-logarithms, exponentials outgrow polynomials, highest power in a polynomial dominates eventually) * Example: Place the following in their proper big-O order from smallest to largest (here ** means exponentiation) - 10n, 5n*log(n), n**1.1, 10**6 * n**0.5, (log(n))**11, 1.1**(sqrt(n)), n**3 - 100n**2 - 1000n + 5 * Example: Write down 10 different big-O functions that are each different in terms of big-O, and put them in big-O order from smallest to largest. * Example: Consider f(n) = 5*n and g(n) = n*n + 10. Either prove that f(n) = o(g(n)), or give some evidence for why you would think this is true. Hint - try increasing values of n, and plot f(n) / g(n). 2.2 Data Structures ~~~~~~~~~~~~~~~~~~~ Should know / be able to do the following: - Runtime of the operations for each data structure we have discussed. - Given some scenario, give the best data structure to use and explain why. * Example: What is the best data structure for storing a waiting list of students if we are gauranteed that the # students is <= 10 at all times. * Example: Give a situation where it is better to use a hash table than a balanced binary search tree, and why. * Example: Give a situation where it is better to use a balanced binary search tree than a hash table, and why. * Example: Suppose you are supposed to take census data that will be 350,000,000 different people, and for each person you will get their age, id #, and income. If your only task is to compute the average income, total income, and top 5 incomes in the dataset, which of the following would be more efficient to store the data: balanced binary search tree with income as key, unsorted array? * Example: For the census dataset, give an example of a query to the dataset that would be a reason you would want it stored in a balanced binary search tree as opposed to other data structures. * Example: For the census dataset, give an example of a goal so that storing the data in a sorted array would be the best solution. - Describe (via words or pseudo code) how a given operation is implemented for a given data structure. 2.3 Linked Lists ~~~~~~~~~~~~~~~~ Should know / be able to do the following: - Advantages and drawbacks of using a linked list - Variants of linked list (doubly linked, etc) and their advantages. * Example: give pseudocode for the delete operation for a singly linked list when you are given a pointer to the node you wish to delete. (Same but for doubly linked.) * Example: give a reason to use a singly linked rather than a doubly linked list (pros for singly-linked versus doubly-linked). - Implementation of stack / queue and when to use them * Example: give pseudocode for pushing and popping onto a stack that is stored as an array. - Code for traversing a linked list 2.4 Hash Tables ~~~~~~~~~~~~~~~ Should know / be able to do the following: - What a hash function is, simple example * Example: define a reasonable hash function for text, and compute the hash value for the strings "cab" and "dag". * Example: define a reasonable hash function for integers, and compute the hash value for the values 123 and 6473. - Terminology: hash, key, value, bucket, collision, chaining - Compare and contrast methods of handling collisions * Example: give limitations when using a hash table that handles collisions by chaining. what is a work-load that would be particularly good (or bad) for a hash table that handles collisions by chaining (e.g., many deletes versus very few deletes). 2.5 Binary Search Trees ~~~~~~~~~~~~~~~~~~~~~~~ Should know / be able to do the following: - Differences between inorder, postorder, and preorder tree traversal, when to use them * Example: Given the following BST, write down the order nodes would be printed if printed by an inorder traversal. (also for postorder, preorder). * Example: What traversal is used to print a BST in order from least to greatest? From greatest to least? * Example: Consider a tree for evaluating an arithmetic expression. Which type of tree traversal is used to evaluate the expression? - Given some scenario, give the best traversal method for the problem, e.g. delete the entire tree, copy the tree, etc. 2.6 AVL Trees ~~~~~~~~~~~~~ Should know / be able to do the following: - The ins and outs of the AVL method of balancing the tree - Given a list of integers, draw what the tree looks like after they have all been inserted - Given a tree, is it AVL? * Example: Given an AVL tree, perform a delete operation and perform rebalancing if needed * Example: What is the best/worst-case running time for a sequence of operations? * Example: Give an example of a sequence of operations where an AVL tree is less efficient than a plain old non-balancing BST.