CIS-344 Midterm Review

Ace your homework & exams now with Quizwiz!

Consider this function declaration, what kind of recursive function is this? void quiz(int i) { if (if > 1) { quiz(i/2); quiz(i/2); } print("*"); }

non-tail recursive

When a recursive function call is made, an activation record for this function is:

pushed onto the runtime stack.

Which operation is not supposed in constant time by any type of linked list implementation?

Access and deletion of an item that is in a random location (may be the 10th or 100th item) in the list.

For the array implementation of the stack, if "top" stays at the front of the array, what is the worst-case cost of a single push operation (in Big Oh notation)?

O(n)

What is the time complexity of the following program segment? for (i=n; i>0; i=i-2) sum++;

O(n)

What would be the running time for merging two linked lists into a single linked list?

O(n)

What is the time complexity in Big Oh for the program segment below? for (i=1; i<=n; i++) for (j=n; j<=1; j--) print "*";

O(n^2)

What is the time complexity in Big Oh for the program segment below? for (i=1; i<n; i++) for(j=1; j<=i^2; j++) print "*";

O(n^3)

Linked lists always have overhead when considering the space consumption. T/F

True

What happens when an array-based queue is implemented as a circular queue? (choose all that apply) A. If front advances past the last array position, it is reset to the first array position. B. If rear advances past the last array position, it is reset to the first array position. C. Neither A nor B

A & B

A singly linked list with _ elements will occupy the same amount of space as a 250 element array list when each data element cost 1 byte and each reference also cost 1 byte.

125

After applying the following to an empty queue, the front of the queue is (add pic)

2

Stack X is an empty stack. Please write down the contents of X after tracking the activities below step by step. X.push(3); X.push(5); Y1 = X.pop(); X.push(6); X.push(4); Y2 = X.pop(); Y3 = X.peek();

3, 6

After applying the following to an empty queue, the rear of the queue is: (add pic)

4

After applying the following to an empty stack, which element will be the "top"? (put pic in)

5

Queue X is an empty queue. Please write down the contents of X after tracking the activities below step by step. X.enqueue(3); X.enqueue(5); Y1 = X.dequeue(); X.enqueue(6); X.enqueue(4); Y2 = X.peek(); Y3 = X.dequeue();

6, 4

What will Y be after the following operations? (put pic in)

7

For the doubly linked list implementation of the stack to perform efficiently (time wise), where are the pushes and pops performed? (Choose ALL that apply) A. Push in front of the head element, pop the head element. B. Push after the tail element, pop the tail element. C. Push after the tail element, pop the head element. D. Push in front of the head element, pop the head element.

A & B

Which of the following operations has the lowest running time in a Queue (assume there's no direct method provided for that purpose, you may need an additional temporary queue in order to find the answer): A. Finding the number of elements in the queue (assuming there's no size method for the queue). B. Printing the content of the queue. C. Checking if an element x is present in the queue.

All of the above

If a header node is used, which of the following indicates a list with one item? A. header != null B. none of the given expressions indicates a list with one item correctly C. header != null && header.next != null D. header != null && header.next != null && header.next.next == null

B

The Unix editor vi allows searching in both directions, with wraparound if necessary. If the sequence of lines is stored as a linked list, which of the following is most reasonable? A. Doubly linked list B. Circular doubly linked list C. Singly linked list D. Circular singly linked list

B

Which of the following is not true? Iterators would be useful if you wanted to... A. Sort nodes of a linked list. B. Insert a new link at the beginning of a list. C. Swap two links at arbitrary locations. D. Delete all links with a certain key value.

B

Which of the following operations has the lowest running time in a Stack? (assume that only Stack interface options are available; some operations may require use of an additional temporary stack) (Choose the BEST answer): A. Deleting the element at the bottom of the stack. B. Swapping the top two elements of the stack. C. Checking is an element x is present in the stack. D. Both A and C

B

For array based stack, if top is set to stay at the front of the array,

Both push and pop will involve shift, results in O(n) time complexity.

What is the size of the queue when the queue is implemented as an array if first == last + 1? A. The queue cannot be determined B. The queue is empty C. The queue is full D. The answer cannot be determined

C

Which problem does the algorithm below present? (add pic)

Cannot always go to base case

Which of the following is an example of queue application? A. "Back" button in a web browser. B. Jobs sent to printer C. Undo button in an editor D. Server processing requests

Correct Answer(s): B & D

What kind of change will "list.next.next = list.prev.prev.prev" make to the list? (add pic) A. No change will be made B. Node 1's next points to 4 C. Node "2"'s next points to 4 D. Node 1's next points to 3

Correct Answer: A

When a function call is executed, which information is NOT saved in the activation record? A. Current depth of recursion. B. Location where the function should return when done. C. Parameters D. Local variables

Correct Answer: A

Which expression indicates the queue is empty when using a circular array to implement a queue? A. first == last == -1 B. first == 0

Correct Answer: A

What kind of change will "list.next = list.prev.next" make to the list? (add pic) A. No change will be made. B. Node 1's next points to 1. C. Node "2"'s next points to 4. D. Node 1's next points to 3

Correct Answer: B

Which data structure is used by the compiler to implement recursion? A. Priority queue B. Stack C. Queue D. List

Correct Answer: B

Which of the following operations has the lowest running time in a Stack (some may require extra stack)? A. Deleting the element at the bottom of the stack. B. Swapping the top two elements of the stack. C. Checking if an element x is present in the stack. D. A & B

Correct Answer: B

Consider the following function, what is printed by the call test_a(4)? (add pic) A. 0 2 4 B. 2 4 C. 0 2 D. 4 2 0

Correct Answer: D

Which of the following operations has the least running time in a queue? A. Deleting the element at the rear of the queue. B. Finding the number of elements in the queue. C. Checking if an element x is present in the queue. D. All of the above have identical worst case running time.

Correct Answer: D

Which of the following operations has the least running time in a stack? A. Deleting the element at the bottom of the stack. B. Checking if an element x is present in the stack. C. Finding the number of elements in the stack. D. All of the above have identical worst case running time.

Correct Answer: D

The header node: A. Simplifies deletion B. Simplifies insertion C. Uses only constant extra space D. All of the above

D

Characteristic of queues:

FIFO

For any given algorithm, the best case is always when n=1 since this will always take the least amount of time? T/F

False

Assuming you have a current points to the next-to-last node in a singly linked list, what will be the time complexity of removing the last item in the list?

O(1)

The time cost for accessing a random element in an array-based list is (in Big Oh notation):

O(1)

What is the time complexity in Big Oh for the program segment below? a = 2^n; b = 50000;

O(1)

What is the time complexity in Big Oh term for the program below? x = y^3;

O(1)

If you were to place elements on a collection and wanted to preserve the order, which structure should you use?

Queue (FIFO)

Queue X is an empty queue. Please write down the contents of Y1, Y2, and Y3 after tracking the activities below step by step. Your answer must clearly state the contents for each variable. X.enqueue(3); X.enqueue(5); Y1 = X.dequeue(); X.enqueue(6); X.enqueue(4); Y2 = X.peek(); Y3 = X.dequeue();

Y1 = 3, Y2 = 5, Y3 = 5

Stack X is an empty stack. Please write down the contents of Y1, Y2, and Y3 after tracking the activities step by step. X.push(3); X.push(5); Y1 = X.pop(); X.push(6); X.push(4); Y2 = X.pop(); Y3 = X.peek();

Y1 = 5, Y2 = 4, Y3 = 6

Consider the following declaration, what is the ground/base case?

i <= 1


Related study sets

Chapter 3: Describing Data: Numerical Measures

View Set

Respiratory Part 3: Arterial Blood Gases MS II

View Set

Combo with "HLTH 1100 chapter 1" and 16 others

View Set

Microeconomics Quiz 10 (Ch. 8 and Info.)

View Set

Rigid-Body Dynamics HW Reading Questions

View Set

Chapter 12: Endoplasmic Reticulum

View Set