1. T/F: - The base case for a recursive function that takes as input a list will always be []. - If we ran the following code, 10 would be printed: def mystery(x): x = 2 x = 10 mystery(x) print(x) - DFS will always explore the left-most path first. 2. Given the following perceptron, fill in the table below for the output from this perceptron for the inputs. a -> 1 ----| V b -> -1 -> in ^ c -> 0.5---| T = -0.5 a b c ----- 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 3. Write a recursive function count_even that takes as input a list and returns the number of even elements in that list. You may NOT use any loops (for or while). >>> count_even([1, 2, 3, 4, 5]) 2 4. Each of the following attempt to make a 2 by 2 matrix of 1s. State for each one whether we would have aliasing problems, i.e. running m[0][0] = 10 after constructing the matrix would change more than one entry. a. m = [[1, 1], [1, 1]] b. m = [[1, 1]]*2 c. m = [] for i in range(2): m.append([1, 1]) d. row = [] for i in range(2): row.append(1) m.append(row) m.append(row) e. m = [[1]*2, [1]*2] 5. Draw the resulting memory diagram (i.e. objects and references as arrows) after the following statements are executed: a = 10 b = [1, 2, 3, 4, 5] c = a d = c 6. Consider a state space where state the starting state 's' has next states [a, b, c] and state 'a' has next states [s, d, e]. Assuming the goal state exists somewhere further down in the state space is DFS guaranteed to find the goal state? Is BFS guaranteed to find the goal state? 7. Why do we generally use DFS instead of BFS for solving state-space search problems? 8. More T/F: - Assuming the state-space is finite (and given enough time) DFS and BFS will return the same goal state. - If m is a matrix (list of lists), m[1] represents the first row of the matrix. - Informed search will find the goal state faster than uninformed search. 9. Write a function called matrix_transpose that takes as input a matrix (list of lists) and transposes the matrix, that is, the rows of the returned matrix are the columns of the input matrix. You may assume that the matrix has the same number of rows and columns (i.e., is square). For example: >>> m = [[1, 2], [3, 4]] >>> matrix_transpose(m) [[1, 3], [2, 4]] 10. Create a perceptron with two inputs that would compute the following function: in1 in2 out ------------- 0 0 1 0 1 1 1 0 1 1 1 0 11. Given the following class: class Pet: def __init__(self, name, type): self.name = name self.type = type self.hungry = False def eat(self): self.hungry = False def play(self): self.hungry = True def same_type(self, other_pet): return self.type == other_pet.type def __str__(self): hungry = "hungry" if not self.hungry: hungry = "not " + hungry return self.name + " of type " + self.type + " and is " + hungry and the following instances of the class: dog = Pet("Charlie", "dog") cat = Pet("Lucy", "cat") cat2 = Pet("Leo", "cat") What would be printed out if we ran the following statements (in order): i. print(dog) ii. cat.play() print(cat) iii. print(cat.same_type(cat2))