COP 3530

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

How can the performance of the in and remove functions be described in the two bag implementations? a. they take linear time b. the performance is logarithmic according to the size of the bag c. the performance is exponential according to the size of the bag d. they take constant time

A

In a breadth-first traversal of a graph, what type of collection is used in the generic algorithm? a. queue b. set c. heap d. stack

A

The design and implementation of a collection class consists of two steps. What is the first step? a. choose an appropriate data structure b. test the method using sample data c. document the class using docstrings d. write the code for the defined methods

A

Timing an algorithm with different problem sizes A. Can give you an idea of the algorithms run-time behavior on a particular hardware platform and a particular software platform B. Can give you a general idea of the algorithms run-time behavior

A

What is the last line of the output when the following code is executed? x = 2for exp in range (5):print ("%2d.0" % x**exp) a. 16.0 b. 16 c. 8.0 d. 32

A

What is the precondition to using the pop method on a queue? a. the queue must not be empty b. the queue must not be full c. the queue must first be resized d. the queue must be full

A

What is the resulting postfix expression from the following infix expression? (12 + 5) * 2 - 3 a. 12 5 + 2 * 3 - b. 12 5 2 + 3 - * c. 12 5 + 2 3 * - d. 12 5 2 + * 3 -

A

What keyword is used to make a multiway if statement? a. elif b. elseif c. then d. else

A

What method does Python's list type use to increase the size of the underlying array? a. append b. increase c. augment d. size

A

Which Python function allows you to obtain information about a module, data type, method, or function? a. help b. doc c. list d. info

A

Which comparison operation returns True if variable x is not equal to variable y? a. x != y b. x neq y c. x <> y d. x .ne. y

A

Which is true about binary search trees? a. they can support logarithmic searches b. they don't work well for sorted collections c. each node in the right subtree of a given node is less than that node d. they cannot support logarithmic insertions

A

Which method is specific to a set compared to a bag? a. __sub__ b. add c. remove d. __str__

A

Which of the following is true about stacks? a. access is restricted to just one end b. they are analogous to a row of books on a shelf c. most implementations allow access to the middle d. items are always added to the bottom

A

A binary search assumes that the data are A. Arranged in no particular order B. Sorted

B

A selection sort makes at most A. n2 exchanges of data items B. n exchanges of data items

B

Counting instructions A. Can demonstrate the impracticality of exponential algorithms with large problem sizes B. Provide the same data on different hardware and software platforms

B

Each level in a completely filled binary call tree has A. The same number of calls as the level above it B. Twice as many calls as the level above it

B

For a given set s, which method returns True if item is in s, or False otherwise. a. s.__iter__(item) b. s.__contains__(item) c. s = set() d. S1.__sub__(s2)

B

Generally speaking, it is better to A. Tweak an algorithm to shave a few seconds of running time B. Choose an algorithm with the lowest order of computational complexity

B

In graph terms, what is a path that begins and ends at the same vertex? a. a simple path b. a cycle c. an undirected path d. a directed path

B

In the Bag class defined in the chapter, what is one of the purposes of the sourceCollection argument in the __init__ method? a. to define source code for the method b. to create a bag with the contents of another collection c. to delete the contents of an existing collection d. to add data to an existing bag collection

B

In the algorithm to evaluate a postfix expression, what does the algorithm do when an operand is encountered? a. pop the operand from the stack b. push the operand onto the stack c. push an operator onto the stack d. pop the operator from the stack

B

In the following code for the __init__ method for the linked binary search tree, what is the missing code? def __init__(self, sourceCollection = None):<missing code> AbstractCollection.__init__(sourceCollection) a. self.leaf = root b. self.root = None c. sourceCollection.__init__(AbstractCollection) d. self.root = sourceCollection

B

In the following code that defines the push method for the array-based stack, what is the missing code? def push (self, item): <missing code> self.size += 1 a. item = self.items[self.size + 1] b. self.items[len(self)] = item c. items[size] = len(self.item) d. self.items += 1

B

In the implementation of the AbstractDict class, which four methods have the same implementation for all dictionaries? a. keys, values, __add__, __eq__ b. keys, values, entries, get c. get, __add__, keys, __init__ d. entries, values, __init__, __str__

B

The expressions O(n), O(n2), and O(kn) are, respectively A. Logarithmic, linear, and quadratic B. Linear, quadratic, and exponential C. Exponential, linear, and quadratic

B

The recursive Fibonacci function makes approximately A. n2 recursive calls for problems of a large size n b. 2n recursive calls for problems of a large size n

B

Under which circumstance can an instance variable be moved to an abstract class? a. when it directly modifies the underlying data structure b. when it refers to the same type of data structure c. when different data structure types are referenced by the variable d. when it is unique to a particular concrete class

B

What action does the following code perform assuming the Node class defined in Chapter 4? ​ head = Node(newItem, head) ​ a. appending an item to the end of a linked list b. insertion of an item at the beginning of a linked list c. replacing an item at the beginning of a linked list d. deletion of an item in a linked list

B

What can you do if items in a priority queue cannot use the comparison operators? a. remove them in FIFO order b. user a wrapper class c. put them in the back of the queue d. remove them from the queue

B

What is a group of zero or more items that can be operated on as a unit? a. array b. collection c. organization d. grouping

B

What is the formula for determining the number of nodes in a full binary tree where H is the height of the tree? a. 2H + 1 b. 2H + 1 - 1 c. 2H - 1 + 1 d. 2H + 1

B

What is the minimum sum of all weights in a spanning tree of a weighted graph? a. spanning forest b. minimum spanning tree c. topological spanning tree d. shortest path spanning tree

B

What is the syntax for the calling the __init__ method in the ArrayBag class from the ArraySortedBag class? a. self.init(ArrayBag, sourceCollection) b. ArrayBag.__init__(self, sourceCollection) c. ArrayBag.self(__init__, sourceCollection) d.__init__.ArrayBag(self, sourceCollection)

B

What is the value of aList after the following code is executed? aList = [1, 2, 3] aList.remove(2) a. [3] b. [1, 3] c. [1, 2] d. [1]

B

Which of the following is NOT an example of a list? a. words on a document b .a jar of marbles c. a recipe d. a file on a disk

B

Which of the following is NOT true after the initialization step in Dijkstra's algorithm? a. the vertex in a row's parent cell is either the source vertex or undefined b. the shortest path from the source to a vertex is found and the vertex's cell is marked in the included list c. the cells in the included list are all False, except for the cell that corresponds to the row of the source vertex in the results grid d. the distance in a row's distance cell is either 0, infinity, or a positive number

B

Which of the following is NOT true of a priority queue? a. when items are added, they are assigned an order of rank b. items of higher priority are removed in FIFO order c. items of equal priority are removed in FIFO order d. items of higher priority are removed before those of lower priority

B

Which of the following is an area of memory from which the Python virtual machine allocates segments of various sizes for all new data objects. a. virtual memory b. object heap c. call stack d. memory partition

B

Which of the following lists Python units of abstraction from smallest to largest? a. modules, functions, methods, classes b. functions, methods, classes, modules c. modules, classes, methods, function d. classes, methods, functions, modules

B

Which statement tests if a singly linked node variable named myItem has been initialized? a. if myItem is Null: b. if myItem != None: c. if myItem = None: d. if myItem is not Null:

B

Which symbol type is NOT found in an EBNF? a. metasymbols b. hypersymbols c. terminal symbols d. nonterminal symbols

B

An example of an algorithm whose best-case, average-case, and worst-case behaviors are the same is A. Sequential search B. Quicksort C. Selection sort

C

Assume x is equal to 5 and y is equal to 0. Which comparison operation returns True? a. x > 0 and None b. x == y or y c. (x > y) and x d. y < 5 and y

C

In the linked implementation of a stack, what type of helper function simplifies the __iter__ method? a. random b. sequential c. recursive d. binary

C

The best-case behavior of insertion sort and modified bubble sort is A. Exponential B. Quadratic C. Linear

C

The following code copies the data from a specified source collection in the LinkedBag __init__ method. What is the missing code? ​ for item in sourceCollection: <missing code> ​ a. add(item.self) b. self.item = source.item c. self.add(item) d. self.item(add)

C

What is the performance value of the array-based implementations of sets and dictionaries? a. On b. O(1) c. O(n) d. O(n2)

C

What is the value of r after the following code executes? myList = [2, 3, 5, 7, 11] yourList = list(myList) r = yourList is myList a. None b. True c. False d. [2, 3, 5, 7, 11]

C

What method is called when the in operator is used on a sorted bag? a. __iter__ b. add c. __contains__ d. __init__

C

What type of operation is the following code performing? probe = head while probe != None and targetItem != probe.data: probe = probe.next if probe != None: probe.data = newItem return True else: return False a. sum of all items b. deletion c. replacement d. insertion

C

When you finish writing the abstract class, what must the subclasses do to use it? a. copy the code to the subclass file b. nothing, the abstract class is automatically included in the subclass c. import the abstract class d. reference the abstract class in their __init__ method.

C

Which Python function returns the total number of items in a collection? a. count b. sizeof c. len d. total

C

Which of the following is the best array length to reduce the probability of collisions given the set [8, 6, 18, 9, 14, 23]? a. 8 b. 9 c. 11 d. 12

C

Which statement allows a programmer to run a module as a standalone program or import it from the shell? a. while main != _module b. if self == "main()": c. if __name__ == "__main__": d. do _module(main)

C

With respect to memory, what happens when an object is no longer needed? a. the data block is marked as deleted and is unavailable to other objects b. the size of the array holding the object is reduced by 1 c. the garbage collector returns the object's space to the free list d. the disk block is marked as unused

C

How is creating a subclass of an existing class different from copying the code from the existing class to a new file? a. no methods need be created or modified b. the name of the subclass is in parentheses of the class header c. you don't need an __init__ method d. delete all the methods that don't have to change

D

In the following code for the pop method for a linked queue implementation, what is the missing code? def pop(self): oldItem = self.front.dataself.front = self.front.nextif self.front is None:self.rear = None<missing code> return oldItem a. self.size += 1 b. self.front = self.rear c. self.rear -= 1 d. self.size -= 1

D

The number of edges connected to a vertex describes which of the following? a. a complete graph b. the neighbor of a vertex c. whether a graph is connected d. the degree of a vertex

D

What is the number of nodes in a full binary tree with a height of 4? a. 47 b. 19 c. 23 d. 31

D

What type of collection is a queue? a. random b. parallel c. geometric d. linear

D

Where is the cursor positioned when a list iterator is opened on a non-empty list? a. at the position of the length of the list minus 1 b. it is undefined c. immediately after the first item d. immediately before the first item

D

Which of the following is NOT a type of precondition when implementing a list iterator? a. the next operation cannot be run if hasNext returns False b. a next operation must be run before each mutation c. mutations cannot be run on the list itself d. consecutive mutator methods are required

D

Which of the following statements accesses the second column in the third row of a two-dimensional array? a. twoDim[2][3] b. twoDim[1][2] c. twoDim[4][3] d. twoDim[2][1]

D

A collection contains at least one item. True False

False

A grammar in a programming language consists of a vocabulary, syntax rules, and a list of operators. True False

False

Array-based binary trees are the easiest to define and implement. True False

False

Because of their linear structure, stacks can only be implemented using linked structures. True False

False

For a linked implementation of a list, a singly linked structure allows movement to the next node or the previous node. True False

False

In computer science, collections are also called objective data types (ODTs). True False

False

Indenting code that should be executed when an if statement evaluates as true makes your program easier to read, but the indentation is not necessary. True False

False

Items in a list must be sorted to make sense. True False

False

The AbstractSet class is a subclass of AbstractBag. True False

False

The __iter__ method is identical in the ArrayBag and LinkedBag classes. True False

False

The entries in a dictionary consist of a key, a value, and an index. True False

False

The heap sort algorithm builds a heap from a set of data and then repeatedly removes the leaf item and adds it to the end of a list. True False

False

The map, filter, and reduce functions can only be used on list collections. True False

False

The operation of removing an item at the end of a linked structure is constant in time and memory. True False

False

To avoid stack overflow, the stack algorithm should raise an error if an item is added to a full stack. True False

False

Two strings that are anagrams will return a unique integer value when the sum of the ASCII values is calculated. True False

False

When a list's append method results in memory wasted beyond a threshold, the size of the underlying array is decreased. True False

False

While desirable, testing is not a critical part of software resource development. True False

False

A class that uses lists can use the methods defined in the AbstractCollection class. True False

True

A graph is a set of edges and vertices such that each edge connects two vertices. True False

True

A min-heap is a binary tree in which each node is less than or equal to both of its children. True False

True

A set is a built-in Python collection type. True False

True

A token in the postfix expression evaluation algorithm is an operand or operator. True False

True

An abstract class captures the common features and behavior of a set of related classes. True False

True

An example of a process or model that can be graphed is the links between pages on the Internet. True False

True

An instance variable that refers to an integer in two different related classes is a likely candidate to be moved to an abstract class. True False

True

Array-based implementations of sets and dictionaries do not perform well. True False

True

Both classes, LinkedStack and LinkedQueue, use a singly linked Node class to implement nodes. True False

True

By using a circular array implementation, you can simultaneously achieve good running times for both add and pop. True False

True

In Python, _MyVar15 is a valid variable name. True False

True

In a tree, the root item has no parent item. True False

True

In an adjacency matrix, a 1 is used to represent an edge between two vertices. True False

True

In computer science, process scheduling can be handled by simple or priority queues. True False

True

In the array implementation of a list, the index-based operation __getitem__ uses the subscript operator on the array variable. True False

True

Repeated application of finding the minimum spanning tree for all the components in a graph yields a minimum spanning forest for a graph. True False

True

Software bags can grow as more items are added, or they can shrink as items are removed. True False

True

Strings are compared using ASCII ordering. True False

True

The array implementation of a queue must access items at the logical beginning and the logical end. True False

True

The easiest way to take advantage of inheritance is to use it to customize an existing class. True False

True

The items in a list are logically contiguous, but need not be physically contiguous in memory. True False

True

The operator in a postfix expression follows the operands. True False

True

Time performance is improved if you double the size of the array when you need to increase its size. True False

True

To access a two-dimensional array, you use two subscripts. True False

True

To determine equality of two collections, use the == operator. True False

True

To find the shortest path, you can use a wighted graph and sum the edge of the weights between two vertices. True False

True

To start a traversal of a linked structure, initialize a variable to the structure's head pointer. True False

True

Unlike a simple iterator, a list iterator supports movement to previous positions, directly to the first position, and directly to the last position. True False

True

Use the comparison operator != to check if one value is not equal to another value. True False

True

When a class is customized using inheritance, the two classes should have a similar interface. True False

True

When using a circular array implementation for a queue, you maintain a count of the items in the queue to determine if it is full or empty. True False

True

With a set, the difference and subset operations are not symmetric. True False

True

With a stack, you always access the item that has been most recently added. True False

True

You can use a for loop on any collection. True False

True

You should always try to hide the implementing data structures behind a wall of method calls on the object being implemented. True False

True

f you print the string "Hello, it is a very \nice day", there will be two lines of output. True False

True


Kaugnay na mga set ng pag-aaral

Fundamentals of Business Final Exam 2023

View Set

Chapter 6: Analyzing the Audience, COMM 1010 CHP. 6, Chapter 6, public speaking chapter 6

View Set