Questions from book quizes c189

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

The number of nodes in a full binary tree of height h is:

2h - 1

Which of the following best describes sequential hashing?

A function is applied to a search key associated with some information to be stored to map the key to slots in an array to use when inserting or retrieving data with the key.

Which of the following is the best definition of the space complexity of a computer program?

A measure of the asymptotic growth rate of the program's memory utilization as the size of the computational problem is increased.

Which of the following is the best definition of the time complexity of a computer program?

A measure of the asymptotic growth rate of the program's running time as the size of the computational problem is increased.

Which of the following would best be modeled using a bag?

A shopping cart used in a web store checkout facility

Which of the following sequences would result from a level-order traversal of the following binary tree? A / \ B C / \ / \ D E F G

A, B, C, D, E, F, G

Which of the following sequences would result from a pre-order traversal of the following binary tree? A / \ B C / \ / \ D E F G

A, B, D, E, C, F, G

Which of the following best describes the bag abstract data type?

An unordered collection of objects that can contain duplicates

Which of the following sequences would result from an inorder traversal of the following binary tree? A / \ B C / \ / \ D E F G

D, B, E, A, F, C, G

Which of the following sequences would result from a post-order traversal of the following binary tree? A / \ B C / \ / \ D E F G

D, E, B, F, G, C, A

Consider a card game where some cards are initially dealt, then during each play, a player selects a card from either the top or bottom of the remaining deck, and discards a card to be placed at the top of bottom of the remaining deck. Which of the following ADTs would best model the deck of cards for this game?

Deque

Consider a list implemented as a linked chain with head and tail pointers. True or False: It is cheaper to insert at the front of the list than the end because you have to traverse the list to find the end to insert at the end.

False

True or False: A binary tree is one where each node is encoded as a binary integer.

False

True or False: A leaf node of a tree can have a non-empty sub-tree.

False

True or False: A node in a binary tree can have 3 children

False

True or False: An algorithm with worst-case time complexity of O(n3) will be always slower than an algorithm that solves the same problem but with O(n2) worst-case time complexity, for any given instance of the problem.

False

True or False: In the model of sorting by comparisons, comparing two elements is the primary means of determining the order of elements, but other properties of the data may be used when it is more efficient to do so.

False

True or False: Inserting a new node into a linked chain is expensive because it is necessary to traverse the chain to find the end of the chain to insert the new node there.

False

True or False: Inserting an element into a sequentially allocated list is always cheaper than inserting into a list built with linked allocation because you do not have to manipulate links in the chain.

False

True or False: Removing an element from a bag with linked allocation is cheaper than removing an element from a bag implemented as a fixed-size array.

False

True or False: When inserting an element into a sorted list implemented as a linked chain, it is always necessary traverse the entire chain to look for larger elements that must remain in the list after the newly inserted element.

False

True or False: the time complexity to search for an element in a list implemented as a sorted chain is O(log(n)).

False

Which of the following are true about Merge sort? The worst-case time complexity of Merge sort is O(nlog(n)) The worst-case time complexity of Merge sort is O(n2) The average-case time complexity of Merge sort is O(nlog(n)) The average-case time complexity of Merge sort is O(n2)

I and III only

Which of the following are true about Quicksort? The worst-case time complexity of Quicksort is O(nlog(n)) The worst-case time complexity of Quicksort is O(n2) The average-case time complexity of Quicksort is O(nlog(n)) The average-case time complexity of Quicksort is O(n2)

II and III only

Rear → A, B, C, D ← Front Starting from an empty queue, which of the following sequence of operations would leave the queue in the above state:

Insert(A), Insert(B), Remove(A),Insert(C), Insert(D), Insert(C), Remove(B), Insert(B), Remove(C), Insert(A)

Which of the following is not true of a bag that is implemented using a fixed size array for storage allocation?

Inserting an element into the bag is an expensive operation

Consider the following pseudo-code to print in sorted order an array A of size n having no duplicate elements 1. If A has only a single element, then it is already sorted, so exit. Otherwise, perform the following steps. 2. Let k = floor(n/2) 3. Recursively execute this algorithm on the sub-arrays A[1..k] and A[k+1 .. n] 4. Let i = 1; 5. Let j = k+1; 6. repeat if A[i] < A[j] then begin print A[i]; i = i+1; end; else begin print A[j]; j = j+1; end; until (i == k) or (j == n); 7. while (i < k) do print A[i]; i = i + 1; end; 8. while (j < k) do print A[j]; j = j + 1; end; 9. exit;

Merge sort

Which of the following describes the best-case time complexity for inserting an element into a sorted list of size n implemented as a linked chain?

O(1)

Which of the following represents the worst-case time complexity for inserting a new element into a bag implemented with linked allocation?

O(1)

If a bucket hash structure is holding n elements and the size of the largest bucket is k, then what is the worst-case time complexity to retrieve an item from the hash structure?

O(k)

If n elements are inserted into a binary search tree resulting in a complete binary tree, what is the worst-case time complexity to look up an element?

O(log(n))

If n elements are inserted into a binary search tree, what is the worst-case time complexity to look up an element?

O(n)

Which of the following describes the average-case time complexity for inserting an element into a sorted list of size n implemented as a linked chain?

O(n)

Which of the following describes the worst-case time complexity for inserting an element into a sorted list of size n implemented as a linked chain?

O(n)

Consider a card game where some cards are initially dealt, then during each play, a player selects a card from the top of the remaining deck, and discards a card to be placed on the bottom of the remaining deck. Which of the following ADTs would best model the deck of cards for this game?

Queue

Consider the following algorithm to sort an array A of size n that has no duplicate elements If A has only a single element, then it is already sorted, so exit. Otherwise, perform the following steps. Select an element a of the array at random Exchange elements of the array so that when done, for some k, A[k] = a, A[i] < a whenever i < k, and A[j] > a whenever j > k Recursively execute this algorithm on the sub-arrays A[1..k-1] and A[k+1 .. n] This algorithm is an example of which of the following sorting algorithms?

Quicksort

Given an object SL of type Sorted List, and an element e, which of the following would not be a method in the class definition of the Sorted List ADT?

Sort(SL)

Suppose a binary search tree is implemented with a node having fields for key, info, left sub-tree, and right sub-tree. Consider the following pseudo-code to search for a key K in binary search tree T, and return the info stored for that key, or return not_found if not found. Assume the return keyword not only returns a value for the function call but also exits from the function and returns to the caller of the function. Function lookup(K, T) begin if T is null then return(not_found) else if (T.key = K) then return(T.info) else if (K < T.key) then return(lookup(K, T.left)) else return(lookup(K, T.right)); end; Which of the following is true?

The lookup function will correctly locate the info associated with a search key while traversing through the minimum number of nodes required to successfully lookup the item

Which of the following is true about a bag implemented using linked allocation?

The storage is allocated as needed by linking new slots into the bag storage when elements are added

Consider the following pseudo-code to insert an element x into a sorted list implemented as sorted array, A: for i = 1 to sizeof(A) if A[i+1] > x then A[i] = x; Which of the following is true:

This will not correctly insert the new element into the list and may also generate a runtime error

Consider searching a list for an element that is smaller than all elements in the list. True or False: if the list is a sorted chain the search will be faster than if the list were an unsorted chain.

True

Suppose a class List is implemented as a linked chain with instance variable head as the head pointer and has nodes of type listnode with two instance variables, info, to store the information of the node, and next to store the next item in the list. Consider the following pseudo-code fragment to insert a new node at the front of the list Procedure insert( I : string, L : list) New_node = new listnode; New_node.info = I; New_node.next = L.head; L.head = New_node; End; True or False: This is a correct implementation for inserting a new element at the front of a list.

True

True or False: A binary tree node is generally implemented as a class with instance variables for data stored in the node, and class references to tree nodes for the left and right sub-tree.

True

True or False: A queue is an appropriate structure to use to receive requests for a service.

True

True or False: All data items that map to a given bucket when a hash function is applied are stored in the bucket.

True

True or False: Bucket hashing involves using a hash function to map a key value to one of a number of buckets to hold the data.

True

True or False: Data items stored in a hash bucket are stored as a linked chain.

True

True or False: Deques support both last-in-first out and first-in-first-out behavior of elements moving in an out of the structure.

True

True or False: Hash functions are generally selected using a criterion of minimizing collisions.

True

True or False: Hashing is an efficient method to implement a Dictionary ADT when it is not necessary to maintain the entries in sorted order.

True

True or False: Linear probing involves a linear search through the hash table starting from the location with index corresponding to a hash value of a data item being inserted or retrieved.

True

True or False: Linear probing would not be required for sequential hashing if a perfect hash function were available.

True

True or False: The List ADT differs from a Stack or Queue by supporting insertion or removal of elements anywhere in the list.

True

True or False: The height of a tree is always greater than the height of a sub-tree of any node of the tree.

True

True or False: The root node of a tree has no parents.

True

True or False: When retrieving data from bucket hash structure, the hash function is applied to the search key to identify the bucket containing the item, and then a linear search is done to locate the key in the bucket.

True

True or False: the time complexity to search an element using binary search in a sorted array is O(log(n)).

True

create new stack(S); read an input character into C; while not end of file do begin if C == '(' then push C on stack S; else if C == ')' then begin if S is empty then begin print "Parentheses do not match"; exit; end; // if else pop top element off stack S; end; // else if read an input character into C; end; // while if S is empty then print "Parentheses match!" else print "Parentheses do not match."; exit; True or False: This is a correct algorithm to check an input file stream for matching parentheses.

True

Which of the following is true about a binary search tree?

a binary search tree has nodes with search keys obeying the property that all keys in the left sub-tree of a node are less than the key value of the node and all keys in the right sub-tree of the node are greater than the key value of the node

Which of the following best describes a collision when hashing is used?

a collision occurs when the hash function returns the same value for two or more items

Question 7 : Which of the following is not an example of a tree structure? This task contains the radio buttons and checkboxes for options. The shortcut keys to perform this task are A to H and alt+1 to alt+9.

a highway map

Which of the following statements about a deque is false?

deques use a double-linked structure to support inserting and removing elements at any point in the structure

To print out the data in a binary search tree in an order that is sorted by the search key, which traversal would be used?

in-order

When a sequential hash table is used to implement a Dictionary ADT, which of the following best describes the role of linear probing?

linear probing is used to resolve collisions during both insertion and retrieval of data to the hash table

for i = 1 to n for j = 1 to n2 sum = sum + j end end Which of the following is the number of additions performed by the algorithm?

n3

Which of the following would not make sense as a method for a bag class?

pixelCount()

The following pseudo-code fragment implements which type of binary tree traversal? Procedure Traverse(T) if (T != null) then { visit(root(T)); Traverse(T.left); Traverse(T.right); } End Traverse;

pre-order traversal

Which of the following is true of a queue?

queues obey a first-in-first-out rule for moving elements in and out of the queue

Which of the following is not true of a stack?

stacks always obey a first-in-first-out rule for elements moving in and out of the stack

Suppose A is an array of n elements and suppose swap(i,j) is a function that swaps the values in the ith and jth position of array A. A call to swap(k,k) has no effect on the array for any index value k. Consider the following pseudo-code. for i = 1 to n min = i for j = i to n if A[j] < A[min] then min = j end swap(min, i) end Which of the following is true?

the pseudo-code implements selection sort

Which of the following is true for sorting a collection of n elements?

the time complexity of selection sort is O(n2) for all cases

Which of the following is false about stacks of size n?

the worst-case time complexity to pop an element off a stack is O(n)

Which of the following is false about a deque of size n?

the worst-case time complexity to remove an element from either end is O(n)

Which of the following is false about queues of size n?

the worst-case time complexity to remove an element from the queue is O(n)

Consider the following pseudo-code for a function lookup to search for a integer k in a list implemented as an unsorted array A. The function will return the index in the array for the element if it is found. If there are duplicate values in the list, the function should return the largest index for an array slot containing the element. The function should return -1 if the element is not found. Function lookup(k : integer) rtn_ val = -1; for j = 1 to sizeof(A) if (A[j] == k) then rtn_val = j; return(rtn_val); end; Which of the following is true:

this is a correct implementation of the lookup function and performs the minimum number of equality tests for k to achieve the result for all inputs

Consider the following pseudo-code for a function lookup to search for a integer k in a list of unique elements implemented as a sorted array A. The function will return the index in the array for the element if it is found, or return -1 if not found. Function lookup(k : integer) rtn_ val = -1; for j = 1 to sizeof(A) if (A[j] == k) then rtn_val = j; return(rtn_val); end; Which of the following is true:

this is a correct implementation of the lookup function, but for some, though not all inputs, performs more than the minimum number of equality tests to achieve the result

Consider the following pseudo-code for a function lookup to search for a integer k in a list of unique elements implemented as an unsorted array A. The function will return the index in the array for the element if it is found, or return -1 if not found: Function lookup(k : integer) for j = 1 to sizeof(A) if (A[j] == k) then return(j) else return(-1); end; Which of the following is true:

this is not a correct implementation of the lookup function

When implementing a queue by sequential allocation using a circular buffer, the reason to leave one slot unused, so that the queue is viewed as full when all but one slot has been allocated is:

to distinguish between the condition of queue empty and queue full

Which of the following best describes the purpose of the Dictionary ADT?

to provide an abstract interface for a structure used to associate information with a search key and retrieve the information by providing the search key

When a bucket hash structure is used, what is the purpose of the buckets?

to segregate data by hash value so that each bucket holds all the data with the same hash value


Kaugnay na mga set ng pag-aaral

Connecting With God- 1 and 2 Corinthians

View Set

5 Postulates of the Kinetic Molecular Theory (KMT)

View Set

Chapter 10 Smartbook Research Methods in Psychology

View Set

Jumpstart Construction Management Ch. 1-8

View Set