COMP Final

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following are equivalent to A^t+B^t+C^t?

(A + B + C)^t (A + B)^t + C^t

Which of the following are equivalent to (A^t)(B^t)(C^t)?

(CBA)^t A^t * (CB)^t

6A What is the slope of a curve at its minimum? Enter a single number only

0

How many objects are contained within the list object [(1, 2), (3, 4), (5, 6)]

0, the list object only contains references

What is 45 in binary?

00101101

The following 4-bit numbers have had a parity bit added to give them even parity. Which have experienced an error after the parity bit was added?

00111 01011

Which of the following functions named f are definitely higher-order functions?

1) def f(a, b, c): d = a + b(c) return d 2)def f(a, b): return map(a, b)

The 4-bit number 1001 was encoded using Hamming codes as described in the videos. Which of the following codewords would be corrected to recover the original number (1001), assuming only 1 bit error could have occurred?

1101001 0001001

What is the value of the expression (1332−76)∗43 in Z256? You can use CodeSkulptor to solve this.

14

What is the product of 4x^3 and 5x^7?

20x^10 multiply coefficients and add exponents

4D How many references are there to the list that p refers to after the following code executes? p = [1, 2, 3] q = p r = q q = [1, 2, 3] s = r

3

What is the quotient of 12x^6 and 4x^2?

3x^4

What is the Hamming distance between 01101010 and 00110110? (Enter a single number only.)

4 (with margin: 0)

5B What is the sum of 3x^2 and 4x^5?

4x^5 + 3x^2

5C What is 13+10 in Z256? You should work this out by hand. Do not use a computer to figure it out.

7

After executing the following program, how many unique list objects with the value [1, 2] are there? lst1 = [1, 2] lst2 = [[1, 2], list(lst1), lst1] lst3 = list(lst2) lst3.append([1, 2]) lst4 = [] for lst in lst3: lst4.append(list(lst)) Enter a single number only.

8

What is the path via the parents from an arbitrary node n in a graph after you have run DFS on that graph starting at node s?

A path from s to n.

What is "cyclic minimization" as defined in the videos?

A process where you minimize an n-dimensional mathematical function in one dimension at a time. You "cycle" through each dimension in turn and then repeat, as necessary, until you find a minimum.

What does the following program print? def silly(num, letter="A"): return letter * num msg = silly(4) msg = msg + silly(5, "B") print(msg)

AAAABBBBB

When can you add a node to the "closed set" in A* search?

After it has been the node selected with the minimum total cost once.

As an example class, consider the following code from one of the videos: class Character: def __init__(self, name, initial_health): self.name = name self.health = initial_health self.inventory = [] def __str__(self): s = "Name: " + self.name s += " Health: " + str(self.health) s += " Inventory: " + str(self.inventory) return s def grab(self, item): self.inventory.append(item) def get_health(self): return self.health What does the self parameter represent?

An object (instance) of the Character class

In what order does A* search explore the nodes in a graph?

By choosing the node that is furthest along a path that could potentially have the shortest distance to the target node at each step.

A set is an unordered collection of distinct elements. Which of the following problem contexts represent instances of this idea?

Group of distinct cities Rooms in a building

Which of the following are true?

Hill Descent can be done without calculating the slope of the function.

What is the distance between two nodes in a graph?

If you run BFS starting at one of the nodes, the distance between the two nodes is 1 plus the distance to the parent of the other node. The length of the shortest path between those two nodes.

What is a variable in Python?

It is a reference to an object.

In the following sequence, a letter or a number indicates that you should push that value onto a stack and a * indicates that you should pop a value from the stack and print it: C O M * P * 1 4 0 * * * R O * * * C K * S * * * If the stack is initially empty, what will be printed?

MP041OROKSCC stack: a stack of elements that you push onto, and pop off the latest element within the stack. A queue on the other hand, you pop off the first element that was pushed into the queue.

Within the __init__ method, what code should you write to return the newly initialized object?

No return statement is needed in __init__.

If, at point x, the slope of the curve f(x) is m (where m is the answer to the previous question), does that mean f(x) has its minimum value at x?

No, The slope must be m for f(x) to be minimized, but every point at which the slope is m is not necessarily the minimum value.

In what order does depth first search explore the nodes in a graph? Correct!

None of the the other answers are correct

You are given a function draw_circle(center_x, center_y, radius). You would like to use this function to draw the image of a ball (with a radius of 10) in the center of a rectangle positioned at the origin whose dimensions are 480x480. Which code snippet is the best way of doing this? Note that all of these snippets yield exactly the same results.

RECT_LOC_X = 0 RECT_LOC_Y = 0 RECT_WIDTH = 480 RECT_HEIGHT = 480 RECT_CENTER_X = (RECT_WIDTH / 2) + RECT_LOC_X RECT_CENTER_Y = (RECT_HEIGHT / 2) + RECT_LOC_Y BALL_RADIUS = 10 draw_circle(RECT_CENTER_X, RECT_CENTER_Y, BALL_RADIUS)

5A What kind of error correction is used in QR codes?

Reed-Solomon

When calling a function recursively, what must be true about the arguments to the function?

The arguments passed to the recursive call must be smaller.

What is missing from the following function to make it compute factorial? def factorial(num): return num * factorial(num - 1)

The base case when num is 0. you must have a base case and a recursive case

In Reed-Solomon encoding, what is k?

The number of error correction bytes that are added to each message block.

What is the parent of an arbitrary node n in a graph after you have run BFS on that graph starting at node s?

The parent of n is a node that is one step closer (in terms of distance) to the starting node s.

What is the objective of hill descent?

To attempt to find the minimum value of a given mathematical function.

Which of the following are good reasons to create a function?

To simplify a complicated predicate in a conditional. To enable reuse of code. To keep something that might change encapsulated in one place. To isolate a complicated expression. To make the code using the function easier to understand.

How many recursive cases can a recursive function have?

Unlimited

What was meant by "Don't live with broken windows!" in the lecture?

When you find a problem in your code, fix it now and fix it correctly.

In DFS, are you guaranteed to eventually find any given end node (as long as the end node is connected to the start node)?

Yes, DFS will always be able to find every node connected to the start node

What is one advantage of structuring a data type using a class instead of just using a bunch of functions?

You can name the attributes of your data object, making your code more readable.

What is one of the primary reasons for not duplicating code?

You only need to get the code correct once.

Consider the following code: class Foods: def __init__(self, foods): self.food = foods def add(self, food): self.food.append(food) snacks = ["goldfish", "ants on a log"] lunch = Foods(snacks) lunch.add("stale crackers") dinner = Foods(snacks) dinner.add("turducken") After it executes, what list does snacks refer to? Try to reason about the code and determine the answer before running any code.

["goldfish", "ants on a log", "stale crackers", "turducken"]

filter function: returns a sequence of those elements for which the function returns a true-like value. def is_positive(n): return n > 0 print(filter( is_positive, [3, -7, 1]) ) filter( function, an_iter) function can be none

[3, 1]

map function: returns a list of the results based on the inputted function and inputted data def square(n): return n * n print(map(square, [3, 7, 1])) map(function, an_iter)

[9, 49, 1]

Every class definition should include an initializer method. What is the name of the initializer method?

__init__ (2 underscores on each side)

the result of A^-1 * A

an identity matrix

When you read a file, i.e., using netfile.read(), what is the type of the returned file contents?

bytes

One way of understanding code is to think about other code that accomplishes the same thing — i.e., given the same starting values, it returns and/or mutates the same values. This following defines one way to concatenate multiple lists. For example, list_extend_many([[1,2], [3], [4, 5, 6], [7]]) returns [1, 2, 3, 4, 5, 6, 7]) and doesn't mutate anything. def list_extend_many(lists): """ Returns a list that is the concatenation of all the lists in the given list-of-lists. """ result = [] for l in lists: result.extend(l) return result Which of the following definitions are equivalent? I.e., which always produce the same output for the same input, and never mutate the input or any global variable?

def list_extend_many(lists): result = [] for i in range(len(lists)): result.extend(lists[i]) return result def list_extend_many(lists): result = [] i = 0 while i < len(lists): result += lists[i] i += 1 return result

Which of the following functions correctly reverses a string?

def rev(string): if string == "": return "" else: return rev(string[1:]) + string[0] def rev(string): if string == "": return "" else: return string[-1] + rev(string[:-1])

If my_url names a text file with the following contents, which of the programs below will print the average of the numbers contained in the file? 10 48 283 147 9

from urllib import request data = request.urlopen(my_url) values = [] for line in data.readlines(): line = line.decode('utf-8') values.append(int(line)) average = sum(values) / len(values) print(average) from urllib import request data = request.urlopen(my_url) total = 0 count = 0 for line in data.readlines(): line = line.decode('utf-8') total += float(line) count += 1 average = total / count print(average)

Lists have a sort method that sorts the list. Try it on the following list: lst = [(3, 3), (2, 4), (5, 1)] Imagine you wanted to sort based on the second element of the tuple, so after callinglst.sort, you would likelstto be: [(5, 1), (3, 3), (2, 4)] To accomplish this, you can callsortwith akeyparameter that tells it what to use as a sort key. You must provide a function which takes one argument (which will be each list element) and return whatever you want to be the key. You would call it like this: lst.sort(key=???) What lambda expression would you replace the "???" with to get this to sort by the second element of the tuples?

lambda pair: pair[1]

How would you split the string "a, b, c" into a list of three letters (["a", "b", "c"])? Assume that the variable letters refers to the original string.

letters.split(', ') split function

Given a list data, how would you produce a list that contains the square root of all of the positive numbers in data? Assume you have a function positive available that returns True if its input is positive and False otherwise.

list(map(math.sqrt, filter(positive, data)))

Assume you have the following class and method definition, parts of which have been omitted. class MyClass: ... def my_method(self, value1, value2): """Assumes its inputs are two values and does something.""" ... my_object = MyClass() The last line defines the variable my_object as an object of MyClass class. Which of the following is proper syntax for using the method on this object?

my_object.my_method(1, 2) class object created . function within the class ( inputs for function)

5D You are writing a function that changes the size of an arbitrary shape. What is a good name for such a function?

resize_shape

Given two sets, s and t, we want a new set containing all the elements that are in one of the sets, but not both of the sets. For example, if s has the elements 1, 2, 3, 4, and t has the elements 3, 4, 5, 6, then the result should have the elements 1, 2, 5, 6.

t.symmetric_difference(s) symmetric_difference() --> Returns a set with all elements that are in exactly one of set a_set and iterable an_iter. Or the elements within each set that do not appear in both sets. example: print(set([1, 2, 3, 4, 5]).symmetric_difference(set([5, 6, 7]))) --> set([1, 2, 3, 4, 6, 7])

In Reed-Solomon encoding, what is the formula for the generator polynomial?

∏i=0k−1(x−2i)


Conjuntos de estudio relacionados

ABNORMAL AND GROUP BEHAVIOR [Test]

View Set

W11 - Distributions to Shareholders (Theory)

View Set

life of pi test author's note - ch. 14

View Set

SIE practice quiz part 1 (sec 1-3)

View Set

CR 201: Qualities of Effective Teachers

View Set

Ch. 4 - Type of Insurance Policies

View Set