COP3530 CHP 07 to CHP 12

Ace your homework & exams now with Quizwiz!

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

Answer: a. linear

Which of the following is the topmost node in a tree and does not have a parent? Answers: a. root b. child c. interior node d. leaf

Answer: a. root

What is the returned value and the state of the queue after the operation is executed? Current queue state: x a z b q.peek() Answers: a. x, x a z b b. b, x a z b c. b, x a z d. x, a z b

Answer: a. x, x a z b

In the code for the inorder method for a binary search tree, what is the missing code? def inorder(self):lyst = list()def recurse(node):if node != None:<missing code> lyst.append(node.data)recurse(node.right)recurse(self.root)return iter(lyst) Answers: a. return(node.data) b. recurse(node.root) c. recurse(node.left) d. return iter(self.root)

Answer: c. recurse(node.left)

Which of the following is NOT a common application for a binary tree? Answers: a. search tree b. expression tree c. stack d. heap

Answer: c. stack

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

Answer: d. hypersymbols

Which type of binary tree traversal visits the tree's root node, the left subtree and then the right subtree? Answers: a. inorder traversal b. postorder traversal c. unordered traversal d. preorder traversal

Answer: d. preorder traversal

A Python list structure and its methods implement a stack perfectly. True False

False

A small load factor and an array length that is a prime number increases the chances for a hashing collision. True False

False

A topological order assigns a rank to each edge such that the vertices go from lower-to higher-ranked edges. True False

False

All graphs, except weighted graphs, are collections of vertices connected by edges. True False

False

Dijkstra's algorithm consists of two steps: the initialization step and the execution step. True False

False

In Python's dict type, values are inserted or replaced at a given location using the index operator {}. True False

False

In the implementation of the lister iterator on a doubly linked list, the method hasNext returns False if the cursor is less than the backing store's length. True False

False

The standard Python hash function always returns a unique positive integer. True False

False

The two fundamental operations supported by queues are pop and insert. 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

When converting from infix form to postfix form, parentheses are added to the equation. True False

False

With trees, each item, including the first and last, have a distinct successor. True False

False

A disk's surface is divided into concentric tracks, and each track is further subdivided into sectors. True False

True

An access, an insertion, or a removal of a node in vine-like tree with N nodes and a height of N - 1 would be linear in the worst case. True False

True

In the hashing implementation of a dictionary, the data field of each node in a chain contains an Entry object. True False

True

In the implementation of a graph, the len function returns the number of the graph's vertices. True False

True

One of the types of symbols used by an EBNF is metasymbols. True False

True

Python supports multiple inheritance, so a class can have more than one parent class. True False

True

Queues are linear collections. 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

When items are added to a priority queue, they are assigned an order of rank. 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 stack, you always access the item that has been most recently added. True False

True

For a key value of 93 and a hashing function of key % 46, what is the index into the array? Answers: a. 1 b. 47 c. 46 d. 2

a. 1

In the following code for the add method for a linked queue implementation, what is the missing code? def add(self, newItem):newNode = Node(newItem, None)if self.isEmpty():self.front = newNodeelse:self.rear.next = newNode<missing code> self.size += 1 Answers: a. self.rear = newNode b. self.front = self.next c. self.rear.prev = None d. self.rear -= 1

a. self.rear = newNode

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

a. the garbage collector returns the object's space to the free list

For key values of 84 and 108 and a hashing function of key % 12, what is the result? Answers: a. indexes of 0 and 1 b. a collision c. indexes of 12 and 14 d. indexes of 7 and 9

b. a collision

Which of the following is NOT a process for which a graph can serve as a model? Answers: a. the routes between rooms in a building b. a road map between hotels a town c. a line at a movie theater d. the paths that data can travel in a network

c. a line at a movie theater

In the following code for the __iter__ method in the ArrayList class, what is the missing code? def __iter__(self):cursor = 0while cursor < len(self):yield self.items[cursor]<missing code> Answers: a. self.items[cursor+1] = self.item[cursor] b. cursor -= 1 c. cursor += 1 d. self.items[cursor] = self.item[cursor-1]

c. cursor += 1

What type of traversal occurs in the binary search trees __iter__ method? Answers: a. sequential b. inorder c. preorder d. postorder

c. preorder

When using a stack to evaluate the balance of brackets and parentheses in an expression, what is the final step? Answers: a. at the end of the expression, if the stack is full, the brackets balance b. at the end of the expression, if the stack is empty, the brackets do not balance c. at the end of the expression, if a final closing bracket is found, the brackets balance d. at the end of the expression, if the stack is empty, the brackets balance

d. at the end of the expression, if the stack is empty, the brackets balance

Which of the following is NOT true after the initialization step in Dijkstra's algorithm? Answers: a. the distance in a row's distance cell is either 0, infinity, or a positive number b. 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 c. the vertex in a row's parent cell is either the source vertex or undefined d. the shortest path from the source to a vertex is found and the vertex's cell is marked in the included list

d. the shortest path from the source to a vertex is found and the vertex's cell is marked in the included list

The depth-first traversal of a graph uses a queue as the collection in the generic algorithm. True False

False

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

False

The maximum amount of work that it takes to access a given node in a full binary tree is O( N). True False

False

The most common type of CPU scheduling technique is called last in, first-out. True False

False

The operator in an infix expression follows the operands. True False

False

The peek method in a heap implementation returns the bottom most item in the heap. True False

False

The peek operation on a queue returns the item at the back of the queue without removing it. True False

False

The push operation for a stack raises an error if the stack is empty. True False

False

What are the two fundamental operations of a queue? Answers: a. insert, pop b. insert, push c. push, add d. add, pop

Answer: d. add, pop

The dictionary constructor has two optional collection arguments: a collection of keys and a collection of corresponding values. True False

True

The first step in evaluating a postfix expression is to scan the expression from left to right. True False

True

The index-based function get returns the ith element of a given list. True False

True

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

True

The pop operation for a stack raises an error if the stack is empty. True False

True

The structure of a queue lends itself to either an array implementation or a linked implementation. True False

True

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

Answer: a. 12 5 + 2 * 3 -

Referring to the keysToIndexes function, what is the result of the following statement? keysToIndexes([39, 18, 4, 51, 6, 28], 17) Answers: a. [5, 1, 4, 0, 6, 11] b. [6, 2, 5, 1, 7, 12] c. [4, 2, 3, 1, 5, 10] d. [7, 3, 6, 2, 8, 13]

Answer: a. [5, 1, 4, 0, 6, 11]

For key values of 84 and 108 and a hashing function of key % 12, what is the result? Answers: a. a collision b. indexes of 12 and 14 c. indexes of 0 and 1 d. indexes of 7 and 9

Answer: a. a collision

In the code for the __sub__ method for the AbstractSet class, what is the missing code? def __sub__(self, other):difference = type(self)()for item in self:if not item in other:<missing code> return difference Answers: a. return(item) b. difference.add(item) c. difference.remove(item) d. intersection.add(item)

Answer: b. difference.add(item)

What is true about how lists are indexed? Answers: a. indices increase in both movement directions b. indices decrease to the left and increase to the right c. indices decrease in both movement directions d. indices decrease to the right and increase to the left

Answer: b. indices decrease to the left and increase to the right

What is the operation that adds items to a stack? Answers: a. get b. push c. pop d. set

Answer: b. push

Which of the following is true about a standard queue? Answers: a. removals are done from the rear of the queue b. the item that has been waiting the longest is popped next c. the items are popped in LIFO order d. the item that has been waiting the shortest is popped next

Answer: b. the item that has been waiting the longest is popped next

In the supermarket simulation, which of the following would be a property of a Cashier object? Answers: a. assigns customers to cashiers b. generates new customer objects c. a queue of customer objects d. a variable to track when service is received

Answer: c. a queue of customer objects

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

Answer: c. linear

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 Answers: a. self.items += 1 b. items[size] = len(self.item) c. self.items[len(self)] = item d. item = self.items[self.size + 1]

Answer: c. self.items[len(self)] = item

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

Answer: c. the garbage collector returns the object's space to the free list

Which of the following is true about a standard queue? Answers: a. the items are popped in LIFO order b. removals are done from the rear of the queue c. the item that has been waiting the longest is popped next d. the item that has been waiting the shortest is popped next

Answer: c. the item that has been waiting the longest is popped next

Which of the following is true about a max-heap? Answers: a. each node is less than or equal to its children b. the smallest item is in the root node c. the largest nodes are nearer to the root d. the largest items are in the leaves

Answer: c. the largest nodes are nearer to the root

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

Answer: d. 2^(H + 1) - 1

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

Answer: d. access is restricted to just one end

When considering an insertion into a set using a hash function and linear probing, which of the following is defined as the position where the item should go if the has function works perfectly? Answers: a. zero index b. probe index c. absolute index d. home index

Answer: d. home index

What is the operation that adds items to a stack? Answers: a. pop b. set c. get d. push

Answer: d. push

What is the first step in the algorithm to evaluate an arithmetic expression? Answers: a. transform the expression from postfix form to infix form b. calculate the result from the postfix expression c. calculate the result from the infix expression d. transform the expression from infix form to postfix form

Answer: d. transform the expression from infix form to postfix form

Recursive list processing became one of the building blocks of a movement in software development called abstract programming. True False

False

The add operation for a queue adds a node at the head of the structure. True False

False

A file system is similar to a binary search tree. True False

False

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

False

A hashing function acts on a given key by returning its absolute position in an array. True False

False

A list supports manipulation of items at only the head and tail within a linear collection. True False

False

A simple path in a graph is one in which a path passes through the same vertex at least twice. True False

False

Initially, when a list iterator is opened on a non-empty list, the cursor's position is immediately after the first item in the list. True False

False

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

False

List positions are usually counted from 0 to the length of the list plus 1. True False

False

ith trees, each item, including the first and last, have a distinct successor. True False

False

The adjacency list supports finding all the vertices adjacent to a given vertex more efficiently than the adjacency matrix. True False

True

A spanning tree has the fewest number of edges possible while still retaining a connection between all the vertices in the component. True False

True

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

True

Removing a vertex also entails removing any edges connecting it to other vertices. True False

True

The __sub__ method of the set class returns a set containing items in s1 that are not in s2. True False

True

What is the performance behavior of a linked adjacency list for determining whether an edge exists between two vertices? Answers: a. linear with the length of the list b. logarithmic with the total number of vertices c. O(N2) where N is the number of vertices d. constant time

a. linear with the length of the list

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

a. the queue must not be empty

If vertex Penguins can reach vertex Capitals and vertex Capitals can reach vertex Islanders, but none of them can reach vertices Sharks or Ducks, what can you say about the set of vertices Penguins, Capitals, and Islanders? Answers: a. the set is a connected component b. the set describes a complete graph c. the vertices in the set are all adjacent to each other d. the set describes a connected graph

a. the set is a connected component

The smallest sum of edge weights between two vertices describes which of the following? Answers: a. the shortest path b. topological order c. maximum spanning tree d. topological sort

a. the shortest path

How do a list iterator and a for loop differ? Answers: a. a list iterator only allows sequential movement through the list b. a list iterator allows movement directly to the last position c. a for loop allows movement to previous positions d. a for loop allows movement directly to the first position

b. a list iterator allows movement directly to the last position

If a list contains the items x y z and the cursor is currently undefined, what happens when hasNext() is executed? Answers: a. a value of False is returned and the cursor is positioned before the first item b. a value of False is returned c. a value of True is returned and the cursor is positioned after the last item d. a value of True is returned

b. a value of False is returned

What strategy does the hashing implementation of a dictionary use? Answers: a. quadratic probing b. bucket/chaining c. linear probing/bucket d. a binary search tree

b. bucket/chaining

In the code for the __iter__ method for the ArrayDict class, what is the missing code? def __iter__(self):cursor = 0while cursor < len(self):yield self.items[cursor].key<missing code> Answers: a. return(self.items[key]) b. cursor += 1 c. return(self.items[cursor]) d. cursor -= 1

b. cursor += 1

Which of the following is NOT a common application for a binary tree? Answers: a. heap b. stack c. search tree d. expression tree

b. stack

Which of the following is true about an undirected graph? Answers: a. there is a source vertex and a destination vertex b. their edges do not indicate direction c. a graph-processing algorithm can move in only one direction along an edge that connects two vertices d. there can be multiple edges connecting any two vertices

b. their edges do not indicate direction

What are the two fundamental operations of a queue? Answers: a. insert, pop b. insert, push c. add, pop d. push, add

c. add, pop

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

c. consecutive mutator methods are required

What is the function of the PVM? Answers: a. converts methods to subroutines b. links a Python program to imported modules c. executes a python program from bytecodes d. compiles Python code into assembly language

c. executes a python program from bytecodes

What can be described as the assignment of a rank to each vertex in a graph such that the edges go from lower-to higher-ranked vertices? Answers: a. directed acyclic graph b. shortest-path problem c. topological order d. sparse graph

c. topological order

What is the value of set S after the following operations? S = set([3, 9, 6])S.add(6)S.add(4)S.remove(6) Answers: a. {3 9 6 4} b. {3 9 6} c. {3 9 4} d. {3 4 6 9}

c. {3 9 4}

When using a stack to evaluate the balance of brackets and parentheses in an expression, what is the first step? Answers: a. pop opening brackets onto the stack while scanning the expression b. pop closing brackets onto the stack while scanning the expression c. push closing brackets onto the stack while scanning the expression d. push opening brackets onto the stack while scanning the expression

d. push opening brackets onto the stack while scanning the expression

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

d. the degree of a vertex

What is the first step in the algorithm to evaluate an arithmetic expression? Answers: a. calculate the result from the infix expression b. transform the expression from postfix form to infix form c. calculate the result from the postfix expression d. transform the expression from infix form to postfix form

d. transform the expression from infix form to postfix form


Related study sets

Ch7: Flexible Budgets, Direct-Cost Variances, and Management Control

View Set

Communication 100 exam 1 study guide

View Set

Chapter 49. Mythical Impressions: Program Music at the End of the Nineteenth Century

View Set

Foundations Chapter 20: Communicator & Chapter 16: Documenting, Reporting & Informatics

View Set

Workplace Hazards / Toxicology / Ergonomics / Safety Assessment

View Set