Study Guide for CS 303E Test 3 (8 Dec 2017) The last test is cummulative but there will be greater emphasis on material that was not covered in the earlier tests. The format of Test 3 will be similar to Test 2. You will have to write short functions and do simple numerical computation, and I will give you choices. Here are topics that you will be tested on - Operators, Conditionals, Loops, Functions, Strings, Files, Lists, Recursion, Tuples, Sets, and Dictionary. Some of the problems will involve nested loops. You should also be familiar with basic algorithms on obtaining maximum and minimum, and sorting, searching and merging. You will also see questions on Binary Arithmetic. Conversions from decimal to binary, octal, and hexadecimal and vice versa. You should be familiar with the 2's complement representation of negative numbers and work with bitwise and shift operators. Review these Coding Bat problems from the Python section - Logic-2, String-2, and List-2. From the Java Section in Coding Bat look at problems in String-2, String-3, Array-2, Array-3, Recursion-1, and Recursion-2. The best way to study for this test is with friends. Sit down and work on the solutions together, especially the more challenging problems. For some of the exam topics I have given some sample questions for you to solve. Write solutions to these problems and run them on the computer. I do not have answer keys for these questions. Do more than what I given in this list from Live Lab and Coding Bat. * Dictionary and its associated functions Q. Create a function that accepts a string as an input parameter and then prints out the frequency of all the characters other than white space characters. Use a dictionary and parse the input string character by character. The character will be the key and the frequency of its occurence the value. Print all the key-value pairs at the end. Q. Given a dictionary with a unique set of keys and values, like countries and their capitals, create a dictionary where the value is the key and the key is the value, i.e. a dictionary of capitals and their countries. * Set and its associated functions Q. Write a function that accepts two lists of strings as input and returns a list that has only the strings common to both the input list. Use a sets inside the function. * List and its associated functions Q. Create a 2-D list that has 3 rows and 5 columns and populate that list with random numbers in the range 1 through 100. Q. Write a function that takes as input two 2-D list and returns True if they are the same and False otherwise. Q. Write a function that takes as input two 2-D list of the same size and returns a 2-D list that has the sum of the corresponding elements of the two lists. Q. Write a function that takes as input a 2-D list and returns a 2-D list with each row in reverse order. Q. Write a function that takes as input a 2-D list and returns a 2-D list with each column in reverse order. Q. Write a function that takes as input two 1-D list of the same size and returns a single number that is the sum of the corresponding products of the elements of the two lists. a = [1, 2, 3] b = [4, 5, 6] Your function should return 1*4 + 2*5 + 3*6 = 32 Q. Write a function that takes as input a 1-D list and returns True if it is sorted in ascending order and False otherwise. Q. Write a function that sums the rows, columns, and diagonals of a 2-D list. Q. Given a 1-D list of 3 numbers sort the list in ascending order without using the built-in sort function or loops. Q. Given a 1-D list shuffle the contents of the list. * Basic algorithms of sorting, searching, and merging Q. Consider the binary search code shown below. What is the last value that is printed for count and mid when a = [ 2, 5, 8, 9, 11, 14, 16, 19, 22, 25, 35, 41, 45, 55, 62] x = 23 def binarySearch (a, x): lo = 0 hi = len(a) - 1 count = 0 while (lo <= hi): count = count + 1 mid = (lo + hi) / 2 print count, mid if (x < a[mid]): hi = mid - 1 elif (x > a[mid]): lo = mid + 1 else: return mid return -1 * String and its associated functions Q. Write a function that takes as input two strings and returns True if the two string are anagrams and False otherwise. The strings may have spaces and punctuation marks and upper and lower characters. You are only concerned that they have the same letters (case insensitive). * File manipulations for reading, writing, and appending Q. Write a function that takes as input two strings - username and password and returns True if they match a username and password combination in a password file and False otherwise. The password file is called passwd.txt and the username and passwords are stored one pair to a line and each pair of username and password is separated by a colon. username1:password1 ... usernameN:passwordN