Study Guide for CS 313E Test 2 (Fall 2020) * You are responsible for material in chapters 1 through 24 in ZyBooks. You are responsible for the data structures Stacks, Queues and LinkedLists. * Define simple classes * Define an algorithm and its characteristics. Know what is meant by algorithm analysis and Big-O notation. [There are no direct questions on the Big-O notation.] * Recursion - be able to go from iterative code to recursive code - trace recursive code - given an algorithm write the recursive version of that algorithm - permutation, combination, all subsets, memoization, and back tracking - Look at Recursion-2 problems in the Java section of Coding Bat. * The questions on the test will involve the algorithms on sorting, searching (linear and binary), merging, and hashing. * You should be familiar with the following sorting algorithms - selection sort, bubble sort, insertion sort, merge sort, quick sort and radix sort. You should be able to trace each of the algorithms for a given array. For hashing, you should know how to hash and do linear probing, quadratic probing, and double hashing. * You should know Infix, Prefix, and Postfix notation. Evaluate Postfix expressions using a stack. Convert an expression in one form to another, e.g. convert an infix expression to postfix. * You should know how to use the Stack, Queue, and LinkedList data structures. You could be given a problem that determines if the parentheses, brackets, and curly braces are well balanced. * You may use any of your notes or the notes that we have on our class website. You may run your code on your computer to test it. But you may NOT communicate with another human being (other than TAs through private note on Piazza) regarding the test! * Here are some sample problems in recursion and combination. Write recursive code from recurrence relations and write the output of recursive functions given the input. Q. Write a recursive function that implements this recurrence relation f(n) = 2 * f(n - 1) + n where f(0) = 0 What is f(8)? Q. Consider the recursive function shown below. What will it return for recurse (45, 75)? def recurse (m, n): if (m == n): return m elif (m > n): return recurse (m - n, n) else: return recurse (n - m, m) * Permutation Problems (Question 2 is a challenging problem and problems of that difficulty will not be assigned on the test.) Q. A secretary writes letters to A, B, C, and D. She also prepares four envelopes addressed to A, B, C, and D. She manages to put all the letters in the wrong envelopes. Enumerate (list) all the ways she can do that. Q. You have the following books that you would like to arrange on your shelf. - War and Peace by Leo Tolstoy - Anna Karenina by Leo Tolstoy - Magic Mountain by Thomas Mann - Death in Venice by Thomas Mann - Arms and the Man by Bernard Shaw - Candida by Bernard Shaw Enumerate the different ways you can arrange the books as long as you keep the books by the same author together. Q. A, B, C, D, and E go to a ball game. A and B want to sit next to each other but C and D prefer not to. Enumerate the different ways that they can sit on the same bench. * Combination Problems Q. Home owners A, B, C, D, E, and F have all agreed to serve on the Home Owners' Association. But the Home Owners' Association just needs three people. A is willing to serve only if B serves, though B has not made that same condition. C and D both refuse to serve if the other is in the association. Enumerate the different associations that you can form. Q. A side show at Coney Island is described as follows: There were ten little dummies which you were to knock over with baseballs. The man said: "Take as many throws as you like at a cent apiece and stand as close as you please. Add up the numbers on all the men that you knock down and when the sum amounts to exactly fifty, neither more nor less you get a genuine 25 cent Maggie Cline cigar with a gold band around it." The numbers on the ten dummies were: 15, 9, 30, 21, 19, 3, 12, 6, 25, 27 What numbers in that series add up to 50?