Test #2 Data Structures & Algorithms

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

How many external references are necessary when implementing a queue using a circularly-linked list? 1 none 4 2

1

Queues are used by compilers to implement recursive methods. TF?

False

Which of the following is NOT an operation that can be performed on a stack: peek insert push pop

Insert

A merge sort is used to sort an array of 1000 values in ascending order. Which of the following statements is true? The sort is fastest if the original values are in completely random order. The sort is the same, no matter what the order of the original elements. The sort is fastest is the original values are sorted from smallest to largest. The sort is fastest if the original values are sorted from largest to smallest.

The sort is the same, no matter what the order of the original elements.

Queues are rarely used in simulation programs. TF?

false

The efficiency of the selection sort depends on the initial arrangement of the data.

false

When implementing a queue using an array-based approach, it is not necessary to determine if the queue if full before adding a new item to the queue. TF?

false

Which of the following operations would you focus on in order to assess the efficiency of a sorting algorithm? multiplication addition loops comparisons

Comparisons

A referenced-based queue implementation uses a statically allocated linked-list. TF?

False

A stack is a first in first out data structure. TF?

False

According to the following statements: -- Algorithm A requires time proportional to n2 -- Algorithm B requires time proportional to nlog2n Algorithm A's time requirement (as a function of the problem size n) increases at a slower rate than algorithm B's time requirement. TF?

False

In a stack operation, new items can only be added to the bottom of the stack. TF?

False

Stacks can be implemented only using arrays. TF?

False

The binary search algorithm is a quadratic algorithm. TF?

False

The values of the growth-rate function O(log2n) grow faster than the values of the growth-rate function O(n). TF?

False

When implementing a queue using a reference-based approach, the operation dequeueAll is not needed. TF?

False

When implementing a queue, a naive array approach is more efficient in terms of memory when compared to a circular array approach. TF?

False

Suppose you are using a queueing system to simulate the movement of pallets in a warehouse. What would represent the server in the simulation? Forklift pallets Warehouse

Forklift

Which of the following would not be a good use of a stack: Keyboard buffer checking for balanced parenthesis Displaying text in reverse

Keyboard Buffer

Suppose that a selection sort of n items requires n2/2 + 5 * n/2 - 3 basic operations -- the selection sort is: O(n) O(1) O(n2) O(n2/2)

O(n2)

Given the fact that a sort of n items requires n2/2 + 5 * n/2 - 3 major operations, the sort is ______. O(n^2/2) O( n^2/2 + 5 * n/2 - 3) O(n^2) O(n)

O(n^2)

The quicksort is ______ in the worst case. O(nlog2n) O(log2n) O(n2) O(n3)

O(n^2)

Which of the following would result in an error? Popping an empty stack Pushing an item onto a empty stack peeking a full stack

Popping an empty stack

Which of the following is true of an array-based stack implementation: Uses memory more efficiently Requires an IsFull Method to check for a empty stack Size of the stack can grow dynamically

Requires an IsFull Method

Which of the following is true of implementing a stack using a linked list: The head reference for the stack points to the bottom of the stack The next reference for the bottom of the stack is null The stack cannot grow dynamically

The next reference for the bottom of the stack is null

A comparison of algorithms should focus on significant differences, not reductions in computing costs based on clever coding tricks. TF?

True

If 5 items are added to the queue, the first item to be removed from the queue is the first item that was added to the queue. TF?

True

Low-order terms can be ignored in an algorithm's growth-rate function. TF?

True

Queues are FIFO (first in first out)? TF?

True

Stacks are used by compilers to implement recursion

True

Stacks can be used to solve depth first searches on graphs. TF?

True

The deletion of an item from one-element reference based queue is a special case. TF?

True

When working with a stack, peek removes the value from the top of the stack. TF?

True

Which of the following is NOT a means of implementing a queue: linearly linked list circularly linked list linear array all of these can be used to implement a queue circularly linked lis

all of these can be used to implement a queue

Operations on a queue can be carried out at ______. its front only any position in the queue its back only both front and back

both front and back

Which of the following should algorithm analysis be independent of: data it should be independent of all of these computers specific implementation

it should be independent of all of these

When assessing the efficiency of a factorial program, which of the following operations would you focus on: muliplication addition loops comparisons

multiplication

In the worst case, the insertion sort's comparison occurs how many times? n n - 1 (n - 1)/2 n*(n - 1)/2

n*(n - 1)/2

A bubble sort requires at most how many passes to sort an array of n items? n/2 n-2 n n-1

n-1

If a stack is used by an algorithm to check for balanced braces, which of the following is true once the end of the string is reached? the stack has one { left the stack has one pair of {} left the stack is empty the stack has one } left

the stack is empty

The two types of simulations are event-driven and _______. queue driven statistically driven probability driven time driven

time driven

A queue can be used as a keyboard buffer. TF?

true

A reference-based implementation of a queue that uses a linear singly linked list would need at least ______ external references.

two

Consider the following Java array definition: int[] array = {22,18,23,16,19,26,15,13}; Suppose this list was to be sorted by the selection sort algorithm as discussed in class. What would be the arrangement of the list after the fourth pass through the array? 13 15 16 18 26 22 19 23 13 15 16 23 19 26 23 22 13 15 16 18 19 22 26 23 13 15 16 18 19 22 23 26 13 15 16 18 19 26 23 22

13 15 16 18 19 26 23 22

Consider the following Java array definition: int[] array = {22,18,23,16,19,26,15,13}; Suppose this list was to be sorted with the recursive mergeSort method demonstrated in class. How many times would the mergeSort method be invoked to successfully sort the given array? 16 15 8 1 2

15

Consider the following Java array definition: int[] array = {22,13,23,15,19,16,26,18}; Suppose this array is to be sorted with the bubble sort algorithm as discussed in class. How many comparisons would be made in order to arrange the data into ascending order? 25 7 28 64 22

25

Which of the following growth functions would represent the most inefficient algorithm for solving a problem: 2^n n^2 n log 2 n

2^n

Suppose that the following list: 71 44 47 68 18 49 73 11 24 57 33 26 was input to the (external) replacement sorting algorithm as discussed in class. How many initial "runs" would be created by the algorithm. You may assume that the sort work area allows for only four data items at any one time: 7 6 5 3 4

5

Suppose that the following list: 479 681 532 94 353 760 was input to the radix sort algorithm. What would be the arrangement of the list after the second pass of the algorithm? 94 353 479 532 681 760 479 681 532 94 353 760 532 353 760 479 681 94 760 681 532 353 94 479

532 353 760 479 681 94

Which of the following arrays represents a heap? 87 26 41 54 25 24 28 20 19 17 87 41 54 28 26 19 25 17 20 24 24 41 54 28 26 19 25 17 20 87 17 19 20 24 25 26 28 41 54 87

87 41 54 28 26 19 25 17 20 24

When implementing a stack as a linked-list, you must make sure the stack isn't full before you can push a new item onto it. TF?

False

A reference-based stack makes more efficient use of memory. TF?

True

The last item to be added to a stack is the first item to be removed from the stack. TF?

True

The pop operation throws a StackException when it tries to: delete an item from an empty stack add an item to a array-based implementation stack when it is already full add an empty item to a empty stack delete an item from an array-based implementation of a stack when it is already full

delete an item from an empty stack

Which of the following operations inserts an element at the end of the queue: peek dequeue push enqueue

enqueue

Which of the following code fragments is used to delete the item at the front of a queue represented by a circular array? front = (front+1) % MAX_QUEUE; --count; ----------------- front = front - back; --count; ---------------- front = MAX_QUEUE - front; --count; ---------------- front = (back+1) % MAX_QUEUE; --count;

front = (front+1) % MAX_QUEUE; --count;

Which of the following is the code to insert a new node, referenced by newNode, into an empty queue represented by a circular linked list? newNode.setNext(lastNode); newNode = lastNode; ----------------------- newNode.setNext(newNode); lastNode = newNode; ------------------------ newNode.setNext(lastNode); ------------------------- lastNode.setNext(lastNode); lastNode = newNode;

newNode.setNext(newNode); lastNode = newNode;


Conjuntos de estudio relacionados

˚˚˚¡™£¢∞§¶•ªº-≠œ∑´®†¥¨ˆøπ"'«åß∂ƒ©˙∆˚¬...æΩ≈ç√∫˜µ≤≥÷⁄€‹›fifl‡°·‚—űŒ„´‰ˇÁ¨ˆØ∏"'»ÅÍÎÏ˝ÓÔÒÚƸ˛Ç◊ı˜Â¯˘¿Ω≈¸˛Ç˜ÅÅ∏`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./ ~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?

View Set

4th Grade Social Studies - Ch. 1

View Set

Chapter 3: Evolution, Biodiversity, and Population Ecology EVR 1001

View Set

In Cold Blood The last to see them alive

View Set

Cardiovascular Prefixes and Suffixes Word List

View Set

unit 12 urinary system anatomy and physiology questions

View Set