CS 2114 Exam 2

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

Select the correct code to complete the following method: /** * Calculate the product of integers between a given index in an array and the first value of 0 * before that index. If there is no value of 0 in the array before the given index, then calculate * the product of the integers between the given index and the beginning of the array. The value * at the given index is included in the product. * So parameters values [2,3,6,0,1,5] and i=4 should return 1, * but values [2,3,6,0,1,5] and i=2 should return 36 * @param values * @param i * @return product of integers from the ith index of values down to a 0 value in the array * or the beginning of the array * @precondition i is not greater than values.length */ public static int examMethod2(int[] values, int i) { if ((values[i] == 0) || (i < 1) ) return 1 ; else return (values[ i ] * examMethod2(values, i - 1)) ; }

Answer 1: ((i < 0) || (values[i] == 0)) Answer 2: 1 Answer 3: (values[ i ] * examMethod2(values, i - 1))

public static final class LinkedQueue<T> implements QueueInterface<T> {private Node<T> firstNode;private Node<T> lastNode;public LinkedQueue() {firstNode = null;lastNode = null;}...public class Node<E> {private E data; // Entry in bagprivate Node<E> next; // Link to next nodepublic Node(E dataPortion) {this(dataPortion, null);} // end constructorpublic Node(E dataPortion, Node<E> nextNode) {....} // end constructorpublic E getData() {.... }public Node<E> getNext() {....}public void setNext(Node<E> newNext) {....}}}} // end LinkedQueue Below is an secondPriorityEnqueue method. If something is enqueued, it normally goes to the back of the queue, but in this method it will be set immediately after the first element in the queue. For example, if you had a linked queue that looked like: (firstNode) 1 --> 2 --> 3 (lastNode) and you ran secondPriorityEnqueue(4) the result would be: (firstNode) 1 --> 4 --> 2 --> 3 (lastNode) Select to fill in the missing code: public void secondPriorityEnqueue(T newEntry) {Node<T> newNode = new Node<T>(newEntry);if (isEmpty()) {lastNode = newNode;firstNode = newNode;} else {newNode.setNext(firstNode.getNext()); [ Select ] ["firstNode.setData(newEntry);", "newNode.setData(newEntry);", "newNode.setNext(newNode);", "firstNode.setNext(newNode);", "firstNode.setNext(newEntry);"] if ( [ Select ] ["lastNode == null", "firstNode == null", "firstNode + 1 == lastNode", "lastNode == firstNode", "newNode == null"] )lastNode = newNode;}} There are two completion questions associated with this scenario, each worth 5 pts.

Answer 1: firstNode.setNext(newNode); Answer 2: lastNode == firstNode

Use this senario to answer the following questions: Case Study - e-Commerce solution (online storefront) for ABC Ltd. You are required to produce a design for an e-commerce solution (online storefront) for the retail company ABC Ltd. This design must take the form of a UML class diagram. High-level requirements have been provided below. ABC will use the solution to promote and sell the thousands of products listed in ABC's product catalog. Though ABC expects to add other products in the near future the catalog currently includes books, DVDs, music CDs, apparel, consumer electronics, beauty products, kitchen items, jewelry, watches, garden items, and toys. Potential customers must be able to visit the online storefront to: Search or browse ABC's product catalog View product details (including description, price, customer ratings and reviews, etc.) Manage their shopping cart (add products to cart, remove products, etc.) In addition, registered customers must be able to login, manage their user account, check out/place orders, and submit reviews of items previously purchased. To register a customer user must complete and submit an online registration form, providing ABC with their email address, password, and one or more of each of the following, phone number, shipping address, billing address, and payment details. ABC's customer service, order fulfillment, and other employee users must also be able to use the system to support business operations. Which of the following inheritance relationships are appropriate for this scenario's design? (Select all which apply) Note: You may assume that the arrows used depict an inheritance relationship a) Customer and Employee as subclass of User b) Apparel, Book, and Watch, as subclasses of User c) User and Employee as subclasses of Customer d) Apparel, Book, Consumer Electronics, DVD, etc. as subclasses of Product

Apparel, Book, Consumer Electronics, DVD, etc. as subclasses of Product

Java uses quicksort and mergesort under the hood for built-in sorting of arrays and lists. These algorithms have efficiency: a) O(1) b) O(n) c) O(log n) d) O(n log n) e) O(n^2)

O(n log n)

What is the big Oh of the following code snippet? for (int i = 1; i < n; i *= 2) { System.out.println("Value " + i + "is" + values[i]); } a) O(1) b) O(logn) c) O(n) d) O(n^2)

O(n^2)

What would be the contents of a deque that started empty after the following code executes: addBack( "Mazda3"); addFront("Chevrolet Sonic"); addBack("Ford Fiesta"); addBack("Honda Fit"); a) "Chevrolet Sonic", "Mazda3", "Ford Fiesta", "Honda Fit" b) "Mazda3", "Chevrolet Sonic", "Ford Fiesta", "Honda Fit" c) "Honda Fit", "Ford Fiesta", "Chevrolet Sonic", "Mazda3" d) "Chevrolet Sonic", "Ford Fiesta", "Mazda3", "Honda Fit"

a) "Chevrolet Sonic", "Mazda3", "Ford Fiesta", "Honda Fit"

After the following statements execute, what item is at the front of the queue? QueueInterface zooDelivery = new LinkedQueue();zooDelivery.enqueue("lion"); zooDelivery.enqueue("tiger"); zooDelivery.enqueue("cheetah"); String next = zooDelivery.dequeue(); next = zooDelivery.dequeue(); zooDelivery.enqueue("jaguar"); a) "cheetah" b) "jaguar" c) "tiger" d) "lion"

a) "cheetah"

Which of the following would correctly complete the isEmpty() method for a linked implementation of a deque in all cases Public boolean isEmpty() { return < fill in code here >; } a) (firstNode == null) && (lastNode == null) b) (firstNode == null) c) (lastNode == null) d) (firstNode == lastNode)

a) (firstNode == null) && (lastNode == null) b) (firstNode == null) c) (lastNode == null)

Consider the following method: public int examMethod(int n) { if (n == 1) return 1; else return (n + this.examMethod(n-1)); } Which of the following inputs will cause a non-terminating recursion? a) 0 b) 1 c) 20 d) 30,000 e) None of the above

a) 0

How many times will F be called if n = 5, ignoring F(5) itself? public static long F(int n) { if (n == 0) return 0; if (n == 1) return 1; return F(n-1) + F(n-2); } a) 14 b) 12 c) 7 d) 5

a) 14

The questions to follow are based on the Case Study described below. Case Study - Vending Machine You have been hired to produce a high-level software design for a Vending Machine application. This design must take the form of a UML class diagram. Your client has asked you to use good examples of actual vending machines as inspiration for your software design. With respect to other requirements your client has indicated that the physical vending machine would be similar in form, behavior, and features to the machine depicted in the images below. Consider the software design for a Vending Machine that: a) both loads and dispenses from the front b) requires the tracking of the contents of each product's "tray" With respect to the data structure design decision, which statement is true? a) A Stack would be an appropriate data structure for this application b) The fields and methods of a Tree would best suit the needs of this application c) A Set would be an appropriate data structure for this application d) This application does not require any data structures

a) A Stack would be an appropriate data structure for this application

To remove the node in position k, which of the following is needed? a) A reference to the node in position k - 1 b) A reference to the node in position k c) A reference to the node in position k + 1 d) A reference to the last node

a) A reference to the node in position k - 1

Which of the following is more restrictive? a) ArrayList<Integer> myList; b) Array<? super Integer> myList;

a) ArrayList<Integer> myList;

Select the most accurate steps to remove a node that contains a designated element. a) Find the node that contains the designated element, get a reference to the node before it, reset the next reference of the node before it to be the node after it b) Find the node that contains the designated element, get a reference to the node after it, reset the next reference of the node after it to be the last node c) Find the node that contains the designated element, change its data to be the same as the data in the last node, remove the last node d) Find the node before the one that contains the designated element, get a reference to the node before that one and reset its next reference to the node that contains the designated element

a) Find the node that contains the designated element, get a reference to the node before it, reset the next reference of the node before it to be the node after it

Queue behavior is typically referred to as: a) First-In, First-Out b) Just-in-Time c) Last-In, First-Out d) First Come, First Served

a) First-In, First-Out

Which combination of statements are True? Statements: I. The question mark (?) is a wildcard or placeholder, representing an unknown type II. In the statement "? extends MyClass", the ? represents a subtype of MyClass where MyClass represents an Upper Bound III. In the statement "? extends MyClass", the ? represents a supertype of MyClass where MyClass represents a Lower Bound a) I and II b) I and III c) II and III d) All of the above

a) I and II

Given fields: private Node firstNode; // Reference to first node private int numberOfEntries; And the following code: private void displayChain(Node curr) { if (curr != null) { System.out.println(curr.get Data()); displayChain(curr.get Next()); } } Indicate how each private helper member method would print a non-empty chain... a) In order b) In reverse order c) Neither

a) In order

How would the following code print the array? public static void displayArray(int[] array, int first, int last) { System.out.print(array[first] + " "); if (first < last) displayArray(array, first + 1, last); } a) In order b) In reverse order c) Neither

a) In order

How would the following code print the array? public static void displayArray(int[] array, int first, int last) { if (first <= last) { displayArray(array, first, last - 1); System.out.print(array[last] + " "); } } a) In order b) In reverse order c) Neither

a) In order

Which of the following is true about a doubly linked chain implementation of a list with sentinel nodes? a) It takes more space b) It improves the algorithmic efficiency of adding an element to the middle of a list c) It makes the code executed for adding a new value to the list the same whether the list is empty, has one items, or many items. d) It stores more data

a) It takes more space c) It makes the code executed for adding a new value to the list the same whether the list is empty, has one items, or many items.

A stack is... a) LIFO (last in first out) b) FIFO (first in first out) c) Peek

a) LIFO (last in first out)

What does the compare method of a comparator object return when the first parameter is less than the second? a) Less than 0 b) Greater than 0 c) 0 d) True e) False

a) Less than 0

Keeping track of lastNode in addition to firstNode a) Makes enqueue operations O(1) b) Makes dequeue operations O(n) c) Causes lastNode to need to be updated every time an item is dequeued d) Causes lastNode to need to be updated if the only item in the queue is dequeued e) Casues lastNode to need to be updated every time an item is enqueued f) Causes lastNode to need to be updated only when the first item is enqueued

a) Makes enqueue operations O(1) d) Causes lastNode to need to be updated if the only item in the queue is dequeued e) Casues lastNode to need to be updated every time an item is enqueued

Based on the deque class shown in the videos. Given the following member method: public void addToFront(T newEntry) { DLNode newNode = new DLNode(null,newEntry,firstNode); if (isEmpty()) { lastNode = newNode; } else { firstNode.setPrev(newNode); } firstNode = newNode; } If "Jeep Wrangler" is passed as a parameter to newEntry. What will the prev field of the node containing "Jeep Wrangler" reference? a) Null b) firstNode c) lastNode d) firstNode and lastNode

a) Null

If an algorithm requires 7 basic operations for an algorithm with a problem size of n, the algorithm complexity is... a) O(1) b) O(7) c) O(n) d) O(7n)

a) O(1)

If the top of the stack is the last element in the array what is the complexity for pop() in big Oh notation? a) O(1) b) O(n) c) O(logn) d) O(n^2)

a) O(1)

If the top of the stack is the last element in the array what is the complexity for push(newEntry) in big Oh notation? a) O(1) b) O(n) c) O(logn) d) O(n^2)

a) O(1)

In a circular array-based implementation of a queue, what is the performance when the dequeue operation ? a) O(1) b) O(logn) c) O(n) d) O(n^2)

a) O(1)

In a circular fixed-size array-based implementation of a queue, what is the efficiency performance of the dequeue operation ? a) O(1) b) O(n^2) c) O(logn) d) O(n)

a) O(1)

In a linked chain implementation of a queue, the performance of the enqueue operation is a) O(1) b) O(logn) c) O(n) d) O(n^2)

a) O(1)

Suppose QueueADT is implemented using a singly linked chain. What is the lowest Big-Oh time complexity that can be achieved for an enqueue method?: a) O(1) b) O(log2 n) c) O(n) d) O(n^2) e) none of the above

a) O(1)

What is the time complexity for adding an entry to a fixed-sized array-based bag ADT? a) O(1) b) O(n) c) O(n^2) d) negligible

a) O(1)

What is the time complexity for adding an entry to a linked-based bag ADT? a) O(1) b) O(n) c) O(n^2) d) negligible

a) O(1)

What is the big-Oh complexity of getEntry(position) on a list that is implemented with a singly linked chain with only a head reference and size field? a) O(n) b) O(logn) c) O(1) d) O(n^2)

a) O(n)

Assume all variables are declared and initialized as needed. What is the running-time efficiency of the following code in terms of Big-O? for (int i = 0; i <= n; i++){ for (int j = 0; j <= n; j++){ System.out.print(i * j * k); } } a) O(n^2) b) O(n^3) c) O(nlogn) d) O(n^2logn)

a) O(n^2)

What item is at the front of the deque after these statements are executed? DequeInterface waitingLine = new LinkedDeque(); waitingLine.addToFront("Jack"); waitingLine.addToBack("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToFront("Sam"); String name = waitingLine.getFront(); name = waitingLine.getBack(); a) Sam b) Adam c) Rudy d) Jack

a) Sam

A recursive function causes an infinite recursion (run-time error) if: a) The base case is never executed or does not exist b) It has no recursive call c) None of the stated reasons d) All of the stated reasons

a) The base case is never executed or does not exist

The following references can be used to add an item to position k in a linked chain implementation of a list: a) The node containing the item in position k - 1 b) The node containing the item in position k c) The node containing the item in position k + 1 d) The last node

a) The node containing the item in position k - 1

Which of these is a traditional measure for the cost of a sorting algorithm? a) The number of swaps b) The amount by which the values are out of order c) The number of records d) The memory size

a) The number of swaps

The questions to follow are based on the Case Study described below. Case Study - Vending Machine You have been hired to produce a high-level software design for a Vending Machine application. This design must take the form of a UML class diagram. Your client has asked you to use good examples of actual vending machines as inspiration for your software design. With respect to other requirements your client has indicated that the physical vending machine would be similar in form, behavior, and features to the machine depicted in the images below. Which of the following could be considered appropriate functional requirements for the Vending Machine? Select all that apply. a) The system shall allow users to select a product to purchase b) The system shall dispense a product c) The system shall allow customers to register for an account d) The system shall process a payment e) The system shall notify users when a payment has been processed f) The system shall update product quantity after successfully dispensing a product

a) The system shall allow users to select a product to purchase b) The system shall dispense a product d) The system shall process a payment e) The system shall notify users when a payment has been processed f) The system shall update product quantity after successfully dispensing a product

The questions to follow are based on the Case Study described below. Case Study - Vending Machine You have been hired to produce a high-level software design for a Vending Machine application. This design must take the form of a UML class diagram. Your client has asked you to use good examples of actual vending machines as inspiration for your software design. With respect to other requirements your client has indicated that the physical vending machine would be similar in form, behavior, and features to the machine depicted in the images below. Consider the Vending Machine software design. With respect to a relatively loosely coupled design which incorporates MVC, which of the following would be the preferred arrangement? a) The view would include a field reference to the Controller, the reference would be passed via the View's constructor b) The View would include a field reference to the Model, the reference would be passed via the View's constructor c) The Model would include a field for a reference to the View, the reference would be passed via the Model's constructor d) The Model would include a field for a reference to the Controller, the reference would be passed via the Model's constructor

a) The view would include a field reference to the Controller, the reference would be passed via the View's constructor

A ListIterator provides a superset of the functionality that an Iterator provides. a) True b) False

a) True

An enhanced for statement can be programmed using a call to the iterator() method and calling the hasNext() and next() methods of the returned iterator. a) True b) False

a) True

Every recursive method must have a base case or a stopping condition. a) True b) False

a) True

In order to be able to sort, the key values must define a total order... a) True b) False

a) True

Is the following statement True or False? Statement: Bounded type parameters allows developers to restrict the types that can be used as type arguments in a parameterized type. a) True b) False

a) True

Is the following statement True or False? Statement: To declare generic methods we write methods using the format methodModifiers <genericTypeParameters> returnType methodName(methodParameters) a) True b) False

a) True

One good general-purpose solution to the problem of getting a key from a record is to store Key/Value pairs in the search structure a) True b) False

a) True

Selection sort is simple, but less efficient than the best sorting algorithms. a) True b) False

a) True

Sometimes, using recursion enables you to give a natural, straightforward solution for a program that would otherwise be difficult to solve. a) True b) False

a) True

The next method needs to be called for each time the remove method is called in order to avoid an exception being thrown. a) True b) False

a) True

The problem with using a ".key()" method to get the key from a record is that we can't use this same method to get different fields for different searches a) True b) False

a) True

Use this senario to answer the following questions: Case Study - e-Commerce solution (online storefront) for ABC Ltd. You are required to produce a design for an e-commerce solution (online storefront) for the retail company ABC Ltd. This design must take the form of a UML class diagram. High-level requirements have been provided below. ABC will use the solution to promote and sell the thousands of products listed in ABC's product catalog. Though ABC expects to add other products in the near future the catalog currently includes books, DVDs, music CDs, apparel, consumer electronics, beauty products, kitchen items, jewelry, watches, garden items, and toys. Potential customers must be able to visit the online storefront to: Search or browse ABC's product catalog View product details (including description, price, customer ratings and reviews, etc.) Manage their shopping cart (add products to cart, remove products, etc.) In addition, registered customers must be able to login, manage their user account, check out/place orders, and submit reviews of items previously purchased. To register a customer user must complete and submit an online registration form, providing ABC with their email address, password, and one or more of each of the following, phone number, shipping address, billing address, and payment details. ABC's customer service, order fulfillment, and other employee users must also be able to use the system to support business operations. Consider an initial design which includes a User, Customer, and Employee class arranged in a hierarchy where Customer and Employee are subclasses of User. Which of the following are good examples of field combinations for the User and Customer class? a) User Class - email, username, password Customer Class - billingAddress, shippingAddress, paymentOption b) User Class - billingAddress, shippingAddress, paymentOption Customer Class - email, password c) User Class - department, username, orders Customer Class - shoppingCart, password

a) User Class - email, username, password Customer Class - billingAddress, shippingAddress, paymentOption

In which cases are the time complexities the same for Bubble Sort (as the algorithm is presented in this module)? a) Worst, Average, and Best b) Worst and Average c) Worst and Best d) Best and Average

a) Worst, Average, and Best

Which of the following best describes the 2 key components of a recursive method: a) a base case and a recursion case b) a case that takes a parameter and goes on forever c) a recursion case that gets called repeatedly with the same parameter d) 2 recursion calls each with different parameters e) An if statement and a while loop

a) a base case and a recursive case

The fact that an iterator keeps its place within a list is a... a) benefit because it saves work and improves efficiency b) risk because the data flow may change direction c) benefit because the last item always stays the same d) risk because the next item may not be needed

a) benefit because it saves work and improves efficiency

If an ArrayQueue is stored an array contents with 1 unused element, which of the following are true (select all that apply): a) contents.length -1 indicates the capacity of the queue b) The number of elements in the queue will always be contents.length c) If size represent the number of elements in the arrayqueue then its range is 0 <= size < contents.length d) If size represents the number of elements in the arrayqueue then its range is 0 <= size <= contents.length

a) contents.length -1 indicates the capacity of the queue c) If size represent the number of elements in the arrayqueue then its range is 0 <= size < contents.length

Give the following code: public void countDown(int leadTime, String message) { System.out.println(leadTime + "..."); if (leadTime > 0) countDown(leadTime - 1, message); else System.out.println(message); } If client code calls countDown(5,"GAMEOVER"), what is the order of the subsequent method calls? a) countDown(4,"GAMEOVER"), countDown(3,"GAMEOVER"), countDown(2,"GAMEOVER"), countDown(1,"GAMEOVER"), countDown(0,"GAMEOVER") b) countDown(4,"GAMEOVER"), countDown(3,"GAMEOVER"), countDown(2,"GAMEOVER"), countDown(1,"GAMEOVER") c) countDown(0,"GAMEOVER"), countDown(1,"GAMEOVER"), countDown(2,"GAMEOVER"), countDown(3,"GAMEOVER"), countDown(4,"GAMEOVER") d) countDown(1,"GAMEOVER"), countDown(2,"GAMEOVER"), countDown(3,"GAMEOVER"), countDown(4,"GAMEOVER")

a) countDown(4,"GAMEOVER"), countDown(3,"GAMEOVER"), countDown(2,"GAMEOVER"), countDown(1,"GAMEOVER"), countDown(0,"GAMEOVER")

Which of the following would remove the Node referenced by the non-null variable curr from items, a non-empty doubly linked list with sentinel nodes firstNode and lastNode? Assume that curr has access to methods getPrevious(), setPrevious(Node n), getNext(), and setNext(). Also, items has access to getSize(). a) curr.getPrevious().setNext(curr.getNext()); curr.getNext().setPrev(curr.getPrev()); b) if (list.getSize() == 1){ curr.getPrevious().setNext(curr.getNext()); curr.getNext().setPrev(curr.getPrev()); lastNode = firstNode; } else { curr.getPrevious().setNext(curr.getNext()); curr.getNext().setPrev(curr.getPrev()); } c) curr.getPrevious().setNext(curr.getNext()); d) curr.getNext().setPrev(curr.getPrev());

a) curr.getPrevious().setNext(curr.getNext()); curr.getNext().setPrev(curr.getPrev());

public static void displayArray3(int[] array, int first, int last) { if (first === last) System.out.println(array[first] + " "); else { int mid = (first + last) / 2; displayArray3(array, first, mid); displayArray3(array, mid + 1, last); } An initial call to displayArray3 has parameter values of 0 and 20 for first and last respectively: displayArray3(myArray, 0, 20). Which is the correct sequence of subsequent calls? a) displayArray3(myArray, 0, 10) displayArray3(myArray, 0, 5) displayArray3(myArray, 0, 2) b) displayArray3(myArray, 0, 10) displayArray3(myArray, 11, 20) displayArray3(myArray, 0, 5) c) displayArray3(myArray, 0, 5) displayArray3(myArray, 5, 10) displayArray3(myArray, 11, 20) d) displayArray3(myArray, 11, 20) displayArray3(myArray, 10, 0) displayArray3(myArray, 10, 5)

a) displayArray3(myArray, 0, 10) displayArray3(myArray, 0, 5) displayArray3(myArray, 0, 2)

@Override public T removeFront() { T front = getFront(); firstNode = firstNode.getNext(); if(firstNode == null) { lastNode = null; } else { firstNode.setPrev(null); } return front; } Select all of the following that will happen if removeFront() is called on a deque with 1 item? a) firstNode and lastNode will become null b) firstNode.next will be returned c) lastNode.prev will be returned d) firstNode.data will be returned e) lastNode.data will be returned

a) firstNode and lastNode will become null d) firstNode.data will be returned e) lastNode.data will be returned

Use this scenario to answer the following questions: Case Study - e-Commerce solution (online storefront) for ABC Ltd. You are required to produce a design for an e-commerce solution (online storefront) for the retail company ABC Ltd. This design must take the form of a UML class diagram. High-level requirements have been provided below. ABC will use the solution to promote and sell the thousands of products listed in ABC's product catalog. Though ABC expects to add other products in the near future the catalog currently includes books, DVDs, music CDs, apparel, consumer electronics, beauty products, kitchen items, jewelry, watches, garden items, and toys. Potential customers must be able to visit the online storefront to: Search or browse ABC's product catalog View product details (including description, price, customer ratings and reviews, etc.) Manage their shopping cart (add products to cart, remove products, etc.) In addition, registered customers must be able to login, manage their user account, check out/place orders, and submit reviews of items previously purchased. To register a customer user must complete and submit an online registration form, providing ABC with their email address, password, and one or more of each of the following, phone number, shipping address, billing address, and payment details. ABC's customer service, order fulfillment, and other employee users must also be able to use the system to support business operations. Which of the following are possible methods for a Customer class? a) getShippingAddress(), getBillingAddress(), placeOrder() b) setPassword(), getShoppingCart(), setProductPrice(), editProductReview() c) registerAccount(), addPaymentsDetails(), sortProductsByType(), searchCatalogForProduct() d) addProductToCatalog(), updateProductTitle(), setProductPrice(), updateStockInventory()

a) getShippingAddress(), getBillingAddress(), placeOrder()

When adding a node newNode to a linked list referenced by head, what code would be the branch for the case that the list is empty? a) head = newNode; b) head.next = newNode; c) curr = newNode; d) prev.next = newNode;

a) head = newNode;

How would the following code print the array? public static void displayArray(int[] array, int first, int last) { if (first < last) displayArray(array, first + 1, last); System.out.print(array[first] + " "); } a) in reverse order b) in order c) neither

a) in reverse order

Given the following code: public static int powerOf5(int exponent) { if (exponent == 0) return 1; else return 5 * powerOf5(exponent -1); } what is powerOf5(-2)? a) infinite recursion b) 1 c) -25 d) 25 e) -125

a) infinite recursion

In the worst case, the total number of comparisons for Selection Sort is closest to: a) n^2/2 b) n^2 c) n d) n^2/4 e) n-1

a) n^2/2

A risk of multiple iterators... a) one iterator makes a change that another doesn't know about b) they run into each other c) one removes another inadvertently d) they may both return the same value when next() is called

a) one iterator makes a change that another doesn't know about

Which of the following are true for a list ADT? a) ordered b) no duplicates c) sorted d) items can be replaced e) items can be replaced

a) ordered d) items can be replaced

Use this senario to answer the following questions: Case Study - e-Commerce solution (online storefront) for ABC Ltd. You are required to produce a design for an e-commerce solution (online storefront) for the retail company ABC Ltd. This design must take the form of a UML class diagram. High-level requirements have been provided below. ABC will use the solution to promote and sell the thousands of products listed in ABC's product catalog. Though ABC expects to add other products in the near future the catalog currently includes books, DVDs, music CDs, apparel, consumer electronics, beauty products, kitchen items, jewelry, watches, garden items, and toys. Potential customers must be able to visit the online storefront to: Search or browse ABC's product catalog View product details (including description, price, customer ratings and reviews, etc.) Manage their shopping cart (add products to cart, remove products, etc.) In addition, registered customers must be able to login, manage their user account, check out/place orders, and submit reviews of items previously purchased. To register a customer user must complete and submit an online registration form, providing ABC with their email address, password, and one or more of each of the following, phone number, shipping address, billing address, and payment details. ABC's customer service, order fulfillment, and other employee users must also be able to use the system to support business operations. Which of the following are appropriate methods for inclusion in the design of this scenario? Check all that apply. a) placeOrder() b) sendOrderInvoice() c) sendOrderCancellationNotice() d) sortProductsByPrice() e) submitProductReview()

a) placeOrder() b) sendOrderInvoice() c) sendOrderCancellationNotice() d) sortProductsByPrice() e) submitProductReview()

Which of the following methods requires the creation of a new node? a) public void add(T newEntry); b) public void add(int newPosition, T newEntry); c) public T remove(int givenPosition); d) public T replace(int givenPosition, T newEntry); e) public T getEntry(int givenPosition); f) public boolean contains(T anEntry);

a) public void add(T newEntry); b) public void add(int newPosition, T newEntry);

This sorting algorithm starts by finding the smallest value in the entire array. Then it finds the second smallest value, which is the smallest value among the remaining elements. Then it finds the third smallest value, the fourth, and so on. a) selection sort b) insertion sort c) bubble sort d) quick sort e) merge sort

a) selection sort

In the demonstrated linked-chain implementation of a StackADT, when a node is popped from the stack... a) the original first node will no longer be referenced b) the original first node will have a new value c) the second to last node will now be the top d) all of the above

a) the original first node will no longer be referenced

In the linked chain implementation of a queue, the chain's first node contains... a) the queue's front entry b) the queue's back entry c) both a & b d) none of the above

a) the queue's front entry

public class RecursiveMath ... public int fib (int a) { if (a < 2) return a; else return fib(a-1) + fib(a-2); } ... } Given the above definition, what is the result of executing the following? RecursiveMath bill = new RecursiveMath(); int x = bill.fib(-1); a) x is set to -1 b) x is set to undefined c) The code does not terminate d) The code cannot be executed, because it won't compile e) None of the above

a) x is set to -1

What is the running time of Insertion Sort when the input is an array where all record values are equal? a) Θ(n) b) Θ(n^​n​​) c) Θ(n​^2​​) d) Θ(logn) e) Θ(nlogn)

a) Θ(n)

What is the average-case time for Bubble Sort (as the algorithm is presented in this module) to sort an array of n records? a) Θ(n^​2​​) b) Θ(logn) c) Θ(n) d) Θ(nlogn) e) Θ(n^​n​​)

a) Θ(n^​2​​)

If the coke guy put a soda with "Bro" into the front of the vending machine, followed by "Sidekick" and "Better Half," in what order will the machine users receive the cokes? a) "Bro" "Sidekick" "Better Half" b) "Better Half" "Sidekick" "Bro"

b) "Better Half" "Sidekick" "Bro"

What would be the contents of a deque that started empty after the following code executes: addFront( "Mazda3"); addFront("Chevrolet Sonic"); addFront("Ford Fiesta"); removeBack(); addBack("Honda Fit"); a) "Ford Fiesta", "Chevrolet Sonic", "Mazda3", "Honda Fit" b) "Ford Fiesta", "Chevrolet Sonic", "Honda Fit" c) "Mazda3", "Ford Fiesta", "Honda Fit" d) "Chevrolet Sonic", "Ford Fiesta", "Honda Fit"

b) "Ford Fiesta", "Chevrolet Sonic", "Honda Fit"

What condition to use to test whether an array based queue with one unused location is full. a) ((backIndex + 2) % array.length - 1) == frontIndex b) ((backIndex + 2) % array.length) == frontIndex c) frontIndex == backIndex d) ((backIndex + 1) % array.length) == frontIndex e) ((backIndex + 1) % array.length - 1) == frontIndex

b) ((backIndex + 2) % array.length) == frontIndex

For large values of n which statement is true? a) (n2 + n) / 2 behaves like n b) (n2 + n) / 2 behaves like n^2 c) (n2 + n) / 2 behaves like n/2 d) all of the above

b) (n2 + n) / 2 behaves like n^2

The following sequence of operations is performed on a queue: enqueue(1), enqueue(2), dequeue, enqueue(1), enqueue(2), dequeue, dequeue, dequeue, enqueue(2), dequeue. The values will be output in this order: a) 2, 1, 2, 2, 1 b) 1, 2, 1, 2, 2 c) 2, 2, 1, 1, 2 d) 1, 2, 1, 1, 2 e) 2, 1, 2, 2, 2 f) 2, 2, 1, 2, 2

b) 1, 2, 1, 2, 2

Approximately how many recursive calls would our Towers of Hanoi pseudo code algorithm make given a tower with 11 disks? a) 11^2 b) 2^11 c) 11 d) Log11

b) 2^11

Given a recursive algorithm to calculate the the nth fibonacci number that makes 2 recursive calls. Approximately how many recursive calls would it make to calculate the 7th fibonacci number? The fibonacci series is a series of numbers in which each number is the sum of the two preceding numbers. Here's the beginning of the sequence: 1, 1, 2 , 3, 5, 8 a) 7^2 b) 2^7 c) 7 d) Log7

b) 2^7

Based on the insertion sort code traced in the demo for a linked chain. Given a linked chain containing 8 -> 4 -> 32 -> 16 -> 256 -> 64 -> 128, what is the state of the linked chain at the end of the second time through the while loop in insertionSort? a) 8 -> 4 -> 32 -> 16 -> 256 -> 64 -> 128 b) 4 -> 8 -> 32 -> 16 -> 256 -> 64 -> 128 c) 4 -> 8 -> 16 -> 32 -> 256 -> 64 -> 128 d) 4 -> 8 -> 16 -> 32 -> 64 -> 256 -> 128 e) 4 -> 8 -> 16 -> 32 -> 64 -> 128 -> 256

b) 4 -> 8 -> 32 -> 16 -> 256 -> 64 -> 128

Given the following code: public void demoRecursion(int value) { if (value > 25) System.out.print (80 - value); else demoRecursion(value * 2); } What is the output for demoRecursion(5)? a) 0 b) 40 c) 25 d) 80

b) 40

Given the following code: public void demoRecursion(int value) { if (value > 25) System.out.print (80 - value); else demoRecursion(value * 2); } What is the output demoRecursion(1)? a) 0 b) 48 c)50 d) 32

b) 48

Given the following code: public static void displayArray(int[] array, int first, int last) { System.out.print(array[first] + " "); if (first < last) displayArray(array, first + 1, last); } With the call displayArray3 ({4,5,6,7,8,9,10,11},0,7), how many recursive calls would be made? a) 3 b) 7 c) 14 d) 22

b) 7

@Override public T removeFront() { T front = getFront(); firstNode = firstNode.getNext(); if(firstNode == null) { lastNode = null; } else { firstNode.setPrev(null); } return front; } What will happen if removeFront() is called on an empty deque? a) Null will be returned b) An EmptyDequeException will be thrown c) An EmptyQueueException will be thrown d) firstNode.data will be returned e) lastNode.data will be returned

b) An EmptyDequeException will be thrown

Which of these is the best definition for a stable sorting algorithm? a) An algorithm that always gives the right answer b) An algorithm that does not change the relative ordering of records with identical keys c) An algorithm that always gives the same order for duplicate keys from run to run d) An algorithm that is as fast as the best one known

b) An algorithm that does not change the relative ordering of records with identical keys

Use a list containing exercise objects: bicep curls, burpees, lunges, overhead presses, planks, push-ups, sit-ups, squats, tricep dips. What would be the state of the iterator after a first call to next()? a) Before bicep curls b) Between bicep curls and burpees c) Between burpees and lunges d) Between sit-ups and squats e) Between squats and tricep dips f) After tricep difps

b) Between bicep curls and burpees

Insertion sort on an array is requires (select all that apply): a) Comparison of each unsorted item to all the currently sorted items b) Comparison of each unsorted item to enough currently sorted items to find its insertion point c) Comparison of each unsorted item to its neighbor until finding its insertion point d) Shifting of all sorted items to make room for subsequently unsorted items e) Shifting of sorted items above each unsorted item's insertion point

b) Comparison of each unsorted item to enough currently sorted items to find its insertion point e) Shifting of sorted items above each unsorted item's insertion point

A class that implements Iterator will have a compile time error if it does not implement a remove method... a) True b) False

b) False

Every recursive method must have a return value. a) True b) False

b) False

In order to do an exact-match search, the key values must define a total order a) True b) False

b) False

One good general-purpose solution to the problem of getting a key from a record is to define a special method such as ".key()" a) True b) False

b) False

Selection Sort (as the code is written in this module) is a stable sorting algorithm. Recall that a stable sorting algorithm maintains the relative order of records with equal keys. a) True b) False

b) False

{Most programming languages will let us re-define "<" and ">" to handle comparison of arbitrary objects| We can generally rely on "<" and ">" to let us compare arbitrary record types} a) True b) False

b) False

It is an error to push data onto a(n) _______ stack. a) Linked b) Full c) Empty d) Array-based e) Initialized

b) Full

Given fields: private Node firstNode; // Reference to first node private int numberOfEntries; And the following code: private void displayChain(Node curr) { if (curr.getNext() != null) displayChain(curr.getNext()); System.out.println(curr.get Data()); } Indicate how each private helper member method would print a non-empty chain... a) In order b) In reverse order c) Neither

b) In reverse order

Given fields: private Node firstNode; // Reference to first node private int numberOfEntries; And the following code: private void displayChain(Node curr) { if (curr != null) { displayChain(curr.getNext()); System.out.println(curr.get Data()); } } Indicate how each private helper member method would print a non-empty chain a) In order b) In reverse order c) Neither

b) In reverse order

How would the following code print the array? public static void displayArray(int[] array, int first, int last) { System.out.print(array[last] + " "); if (first < last) displayArray(array, first, last - 1); } a) In order b) In reverse order c) Neither

b) In reverse order

How would the following code print the array? public static void displayArray(int[] array, int first, int last) { if (first < last) displayArray(array, first + 1, last); System.out.print(array[first] + " "); } a) In order b) In reverse order c) Neither

b) In reverse order

With respect to the declaration ArrayList<? super Customer> myCustomer; Which of the following is True? a) In the statement "? super Customer", the ? is a placeholder that represents a subtype of Customer where Customer represents an Upper Bound b) In the statement "? super Customer", the ? represents a Customer type or a super type of Customer, where Customer is considered to be the Lower Bound

b) In the statement "? super Customer", the ? represents a Customer type or a super type of Customer, where Customer is considered to be the Lower Bound

When using the runner technique on a singly linked chain to insert an item in order, both prev and curr nodes are used in order to (select all that apply): a) Reverse the order of the items b) Insert an item before the node that curr references c) Loop through the items in the chain to find the insertion location d) Have access to multiple nodes in order to swap them

b) Insert an item before the node that curr references c) Loop through the items in the chain to find the insertion location

For an array implementation of a list, the worst case efficiency of replace(index, newEntry) is: a) O(n2) b) O(1) c) O(n) d) O(log n)

b) O(1)

If the top of the stack is the first entry of the array what is the complexity for pop() in big Oh notation? a) O(1) b) O(n) c) O(logn) d) O(n^2)

b) O(n)

If the top of the stack is the first entry of the array what is the complexity for push(newEntry) in big Oh notation? a) O(1) b) O(n) c) O(logn) d) O(n^2)

b) O(n)

What is the worst-case complexity for searching a linked-based bad ADT for a particular entry? a) O(1) b) O(n) c) O(n2) d) negligible

b) O(n)

What technique is often used to prove the correctness of a recursive method? a) Proof by contradiction b) Proof by mathematical induction c) Proof by communitivity d) Proof by diagonalization

b) Proof by mathematical induction

Based on the deque class shown in the videos. What does this code most likely do: firstNode = firstNode.getNext(); if (firstNode == null) lastNode = null; else firstNode.setPreviousNode(null); a) Removes the first node from a singly linked chain b) Removes the first node from a doubly linked chain c) Iterates through a singly linked chain d) Iterates through a doubly linked chain

b) Removes the first node from a doubly linked chain

What item is at the front of the deque after these statements are executed? DequeInterface waitingLine = new LinkedDeque(); waitingLine.addToFront("Jack"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); String name = waitingLine.getFront(); a) Jack b) Rudy c) Larry d) Sam

b) Rudy

What item is at the front of the deque after these statements are executed? DequeInterface waitingLine = new LinkedDeque();waitingLine.addToFront("Jack"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); String name = waitingLine.getBack(); a) Jack b) Rudy c) Larry d) Sam

b) Rudy

Which statement best characterizes Selection Sort (as the code is written in this module)? Recall that a stable sorting algorithm maintains the relative order of records with equal keys. a) Selection Sort is not stable b) Selection Sort is not stable, but minor modifications it could be made so c) Selection Sort is stable

b) Selection Sort is not stable, but minor modifications it could be made so

Chris implements a standard sorting algorithm that sorts the numbers 64, 25, 12, 22, 11 like so: 64 25 12 22 11 11 25 12 22 64 11 12 25 22 64 11 12 22 25 64 11 12 22 25 64 Which sorting algorithm is this? a) Insertion sort b) Selection sort c) Bubble sort d) Merge sort

b) Selection sort

Defining a record's key field is a property of: a) The records b) The context of the search c) Both d) Neither

b) The context of the search

@Override public T removeFront() { T front = getFront(); firstNode = firstNode.getNext(); if(firstNode == null) { lastNode = null; } else { firstNode.setPrev(null); } return front; } Select all of the following that will happen if removeFront() is called on a deque with 3 items? a) firstNode and lastNode will become null b) The first node the three will be removed c) The last node of the three will be removed d) firstNode.data will be returned e) lastNode.data will be returned

b) The first node the three will be removed d) firstNode.data will be returned

Which value of a stack is accessible? a) The rear item b) The top item c) The highest-valued item d) The lowest-valued item e) The bottom item f) The root g) The front item

b) The top item

The order of the input records has what impact on the number of comparisons required by Insertion Sort (as presented in this module)? a) There is a constant factor difference b) There is a big difference, the asymptotic running time can change c) None

b) There is a big difference, the asymptotic running time can change

In a recursive function, what is the maximum number of recursive calls allowed? a) n (where n is a parameter passed to the function) b) There is no fixed maximum c) 1 d) 2

b) There is no fixed maximum

Based on ListInteface.java, an attempt to remove and item from an empty list will a) Return null b) Throw an IndexOutOfBoundsException c) Set the length of the list to -1 d) Return the same item

b) Throw an IndexOutOfBoundsException

In which cases are the growth rates the same for Insertion Sort? a) Worst, Average, and Best b) Worst and Average only c) Best and Average d) Worst and Best only

b) Worst and Average only

For the list, [40, 50, 20, 30], what will the array look like after the second pass of selection sort? a) [10, 20, 40, 30] b) [20, 30, 40, 50] c) [10, 20, 30, 40] d) [20, 30, 50, 40]

b) [20, 30, 40, 50]

You've got a class that holds two ints and that can be compared with other IntPair objects: class IntPair { private int a; private int b; public IntPair(int a, int b) { this.a = a; this.b = b; } public int compareTo(IntPair other) { if (a < other.a) { return -1; } else if (a > other.a) { return 1; } else { if (b == other.b) { return 0; } else if (b > other.b) { return -1; } else { return 1; } } } } Let's denote new IntPair(5, 7) as [5 7]. You've got a list of IntPairs: [3 7], [4 6], [3 4] You sort them using IntPair.compareTo. What is their sorted order? a) [3 4], [3 7], [4 6] b) [3 7], [3 4], [4 6] c) [4 6], [3 7], [3 4] d) [4 6], [3 4], [3 7]

b) [3 7], [3 4], [4 6]

Suppose you are trying to choose between an array and a singly linked list to store the data in your program. Which data structure must be traversed one element at a time to reach a particular point? a) an array b) a linked list c) both d) neither

b) a linked list

Where does a queue add new items? a) at the front b) at the back c) randomly d) in the middle

b) at the back

Use a list containing exercise objects: bicep curls, burpees, lunges, overhead presses, planks, push-ups, sit-ups, squats, tricep dips. What would a first call to next() return? a) Null b) bicep curls c) burpees d) squats e) tricept dips f) NoSuchElementException

b) bicep curls

Stack A has entries a, b, c (in that order with a on top), while Stack B is initially empty. When an entry is popped out of stack A, it can be printed immediately or pushed to stack B. When an entry is popped out of stack B, it can only be printed. Which of the following permutations of a, b, c is not possible to print? a) a b c b) c a b c) b c a d) b a c

b) c a b

Select the best choice below to fill in the blanks: When a __________ implements Comparable, the __________ named ____________ must be implemented. a) method, class, compareTo b) class, method, compareTo c) generic, object, compareTo d) generic, type, compareTo

b) class, method, compareTo

Consider a generic method declared as depicted below, with type parameter <T extends Number> and two method parameters both of type T: public <T extends Number> void specialMethod(T first, T second) a) client code can provide any value for the type parameter T b) client code can only type Number of any subclass of Number for the type parameter for T c) None of the above

b) client code can only type Number of any subclass of Number for the type parameter for T

To efficiently remove a node at the end of a linked chain implementation of a queue with a tail reference requires a... a) traversal b) extra reference in the node pointing to the previous node c) none of the above

b) extra reference in the node pointing to the previous node

Given that a doubly-linked chain exists in memory as represented below. firstNode references the first node in the linked chain which contains the data "D" and lastNode references the last node in the linked chain which contains the data "N". firstNode → "D" ⇄ "E" ⇄ "S" ⇄ "I" ⇄ "G" ⇄ "N" ← lastNode consider execution of the following code, upon the linked chain above: Node<String> p = firstNode; Node<String> r = lastNode; p = firstNode; r = p.next; lastNode.next = p; p.previous = lastNode; p.next = null; lastNode = p; firstNode = r; firstNode.prev = null; Which of the linked chains below would result: Hint: draw a diagram of the list to execute the code upon. a) firstNode →"D" ⇄ "E" ⇄ "S" ⇄ "I" ⇄ "G" ⇄ "N" ← lastNode b) firstNode → "E" ⇄ "S" ⇄ "I" ⇄ "G" ⇄ "N" ⇄ "D" ← lastNode c) firstNode → "S" ⇄ "I" ⇄ "G" ⇄ "N" ⇄ "E" ⇄ "D" ← lastNode d) firstNode → "S" ⇄ "I" ⇄ "N" ⇄ "G" ⇄ "E" ⇄ "D" ← lastNode e) firstNode → "D" ⇄ "E" ⇄ "S" ⇄ "I" ⇄ "N" ⇄ "G" ← lastNode

b) firstNode → "E" ⇄ "S" ⇄ "I" ⇄ "G" ⇄ "N" ⇄ "D" ← lastNode

Suppose we have a Queue implemented with a circular array. The capacity is 10 and the size is 5. Which are legal values for front and rear? a) front: 0 rear: 5 b) front: 5 rear: 9 c) front: 7 rear: 2 d) front: 9 rear: 4 e) all of the above

b) front: 5 rear: 9

An enhanced for statement can only be use on data structures that... a) start counting at 0 b) implement Iterable c) implement Collection d) have an Iterator field variable

b) implement Iterable

Of the two sorting algorithms we studied in lecture, which would do less work, in terms of comparisons and swaps, if executed upon an already sorted array? a) selection sort b) insertion sort

b) insertion sort

Which of the following BEST completes the statement An iterator ______________ a) is loop variable b) is an object that traverses a collection c) can be used to consider each data item in a collection once d) can be used to insert an item into a collection

b) is an object that traverses a collection

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 0 and backIndex is 0... a) empty queue b) one element in the queue c) three elements in the queue d) four elements in the queue e) five elements in the queue f) six elemtents in the queue g) invalid

b) one element in the queue

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 2 and backIndex is 2 a) empty queue b) one element in the queue c) three elements in the queue d) four elements in the queue e) five elements in the queue f) six elements in the queue g) invalid

b) one element in the queue

Which of the following methods could throw an IndexOutOfBoundsException? a) public void add(T newEntry) b) public void add(int newPosition, T newEntry); c) public T remove(int givenPosition) d) public void clear(); e) public boolean contains(T anEntry)

b) public void add(int newPosition, T newEntry); c) public T remove(int givenPosition)

When too many recursive calls are made, creating more activation records than the allocated program memory can handle, what kind of error/exception occurs? a) not valid b) stack overflow c) recursive underflow d) nonrecursion e) heap overflow

b) stack overflow

In the demoed array-based implementation of a Stack ADT, the entry peek returns may be found at... a) the last location in the array b) the last occupied location in the array c) the first location in the array d) none of the above

b) the last occupied location in the array

If I is the number of inversions in an input array of n records, then Insertion Sort will run in what time? a) Θ(n−I) b) Θ(n+I) c) Θ(I) d) Θ(n)

b) Θ(n+I)

What is the running time of Selection Sort when the input is an array that has already been sorted? a) Θ(n) b) Θ(n​^2​​) c) Θ(logn) d) Θ(nlogn)

b) Θ(n​^2​​)

If I is the number of inversions in an input array of n records, then Insertion Sort will run in what time? a) Θ(I) b) Θ(n−I) c) Θ(n) d) Θ(n+I)

b) Θ(n−I)

Suppose q is an instance of a queue that can store Strings, and I execute the following statements starting with q empty: 1. q.enqueue("Sweden"); 2. q.enqueue("is"); 3. q.enqueue("my"); 4. String w = q.dequeue(); 5. String x = q.peek(); 6. q.enqueue("neighbor"); 7. String y = q.dequeue(); 8. String z = q.dequeue(); What is the value of z after executing these expressions in order? a) "Sweden" b) "is" c) "my" d) "neighbor" e) none of the above

c) "my"

What does the compareTo method return when the calling object and the parameter are equal? a) Less than 0 b) Greater than 0 c) 0 d) true e) false

c) 0

Consider the following recursive method: public int examMethod(int n) { if (n == 1) return 1; else return (n + this.examMethod(n-1)); } What value is returned by the call examMethod(16)? a) 1 b) 16 c) 136 d) None of the above.

c) 136

Giver the following code: public static void displayArray3(int[], int first, int last) { if (first == last) System.out.println(array[first] + " "); else { int mid = (first + last) / 2; displayArray3(array, first, mid); displayArray3(array, mid + 1, last); } With the call displayArray3 ({4,5,6,7,8,9,10,11},0,7), how many recursive calls would be made? a) 7 b) 8 c) 14 d) 22

c) 14

Given array: private int[] counts = {7, 12, 3, 56, 11, 9, 18 } And the selection sort from the video demo What is the value of lh when the array is put in this state {3, 7, 9, 11, 56, 12, 18 } a) 1 b) 2 c) 3 d) 4

c) 3

Given the following code: public static void springFreeze(int temp) { if (temp < 32) System.out.println("Frost!"); else { System.out.println("temps are dropping..."); springFreeze(temp - 4); } } How many times will springFreeze(40) print out "temps are dropping..."? a) 10 b) 4 c) 3 d) 2 e) 0

c) 3

Given the following method: public int func(int x, int y) { if (y == 1) { return x; else return x + func(x, y-i); } What will be returned when func(2,3) is exectued? a) infinite recursion b) null c) 6 d) 1

c) 6

Given a recursive algorithm to countdown to 1 from a given integer that makes 1 recursive call. Approximately how many recursive calls would it make to countdown from 99? a) 99^2 b) 2^99 c) 99 d) Log99

c) 99

We know that using Generics reduces the need to cast types. Which of the following answers best conveys some of the other benefit(s) of using generics and parameterized or generic types in Java? a) Generics provide type safety and enable strong type checks at compile time b) Provide developers with the ability to implement generic algorithms (classes and methods) c) All of the above

c) All of the above

In the linked implementation of a queue, a new item would be added: a) After all other entries that are greater than the new entry b) At the head c) At the rear d) After all other entries that are smaller than the new entry e) At the current position

c) At the rear

This is a notoriously inefficient algorithm traditionally taught to introduce sorting algorithms: a) Quick sort b) Merge sort c) Bubble sort d) Selection sort e) Insertion sort

c) Bubble sort

Select the best generalized algorithm for adding to a list using a linked chain implementation: a) Update the firstNode reference, create a new node, populate the data and next fields of the new node b) Prepare the linked chain for the new node, create a new node, populate the data and next fields of the new node c) Create a new node, populate the data and next fields of the new node, update the linked chain to include the new node d) Create a new node, populate the data and next fields of the new node, update the firstNode reference

c) Create a new node, populate the data and next fields of the new node, update the linked chain to include the new node

It is an error to pop data from a(n) _______ stack. a) Initialized b) Array-based c) Empty d) Full e) Linked

c) Empty

Advantage(s) of an inner iterator class over a separate, (non-inner), iterator class: a) The inner iterator class allows multiple iterator objects to be instantiated. b) It has the ability to remove an element c) It has direct access to the ADT's data so it can execute more efficiently d) Inner iterator objects can exhibit polymorphic behavior.

c) It has direct access to the ADT's data so it can execute more efficiently

Consider the design of a system used to track and manage the items in a library. From discussions with librarians and other stakeholders you identified the following possible classes and fields. Book Fields of the Book class: library ID, name, description, data of acquisition, status, title, ISBN, category, authors, publisher, publication date DVD Fields of the DVD class: library ID, name, description, data of acquisition, status, title, actors, directors, genre, rating, length Recognizing that Books, DVDs, and other forms of library media all contain similar pieces of data/information that must be tracked and managed, you decide to create a Media class (see below) and use inheritance since it improves code re-usability. Media Fields of the Media class: library ID, name, description, data of acquisition, status Which would be the most appropriate way to utilize inheritance within your UML design? a) Book as a superclass, with Movie as a subclass of Book, and Media as a standalone class b) Movie as a superclass, with Book as a subclass of Movie, and Media as a standalone class c) Media as a superclass, with Book and Movie as subclasses of Media d) Media, Book, and Movie each as standalone class (not related by inheritance)

c) Media as a superclass, with Book and Movie as subclasses of Media

Given fields: private Node firstNode; // Reference to first node private int numberOfEntries; And the following code: private void displayChain(Node curr) { if (curr == null) System.out.println(curr.get Data()); else displayChainBackwards (curr.getNext()); } Indicate how each private helper member method would print a non-empty chain... a) In order b) In reverse order c) Neither

c) Neither

How would the following code print the array? public static void displayArray(int[] array, int first, int last) { System.out.print(array[first] + " "); if (first < last) displayArray(array, first, last - 1); } a) In order b) In reverse order c) Neither

c) Neither

The order of the input records has what impact on the number of comparisons required by Bubble Sort (as presented in this module)? a) There is a constant factor difference b) There is a big difference, the asymptotic running time can change c) None

c) None

The order of the input records has what impact on the number of comparisons required by Selection Sort (as presented in this module)? a) There is a big difference, the asymptotic running time can change b) There is a constant factor difference c) None

c) None

If client code is traversing a list by using an iterator. The efficiency of traversal is: a) O(1) b) O(logn) c) O(n) d) O(n^2)

c) O(n)

What is the big Oh of the following code snippet? for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (favorites[j] == i) { return favorites[j]; } } } a) O(j) b) O(n) c) O(n^2) d) O(logn)

c) O(n^2)

The questions to follow are based on the Case Study described below. Case Study - Vending Machine You have been hired to produce a high-level software design for a Vending Machine application. This design must take the form of a UML class diagram. Your client has asked you to use good examples of actual vending machines as inspiration for your software design. With respect to other requirements your client has indicated that the physical vending machine would be similar in form, behavior, and features to the machine depicted in the images below. Which of the following is the best option for classes for the Vending Machine? Carefully consider the options presented, remember that some nouns are better suited for fields not classes. a) ProjectRunner, Model, View, Controller b) ProjectRunner, Product, Customer, Username, Quantity, Price c) ProjectRunner, Controller, GUI, Product, Payment d) ProjectRunner, Controller, Pterm-120roduct, Price, Email e) ProjectRunner, Controller, Model, Price, Quantity f) ProjectRunner, Product, User, Customer, Employee, OrderDate, ShippingAddress

c) ProjectRunner, Controller, GUI, Product, Payment

One difference between a queue and a stack is: a) Stacks use two ends of the structure, queues use only one b) Stacks require linked lists, but queues do not c) Queues use two ends of the structure; stacks use only one d) Queues require linked lists, but stacks do not

c) Queues use two ends of the structure; stacks use only one

Imagine you have an empty stack of strings named stack. List the contents of the stack from top to bottom after the following operations have executed. (Assume that the pop method returns the element that was popped.) stack.push("K"); stack.pop(); stack.push("P"); stack.push("G"); stack.push("R"); String str = stack.pop(); stack.push("V"); stack.push(str); a) P V G P b) R V G P K c) R V G P d) R V R G P

c) R V G P

The benefit of using sentinel nodes is: a) Added time is required for operations b) Added space is required c) Special cases are not required for operations on nodes at the beginning or end of the list d) They provide easy access to the previous node

c) Special cases are not required for operations on nodes at the beginning or end of the list

The benefit of using sentinel nodes... a) Added space is required b) Added time is required for operations c) Special cases are not required for operations on nodes at the beginning or end of the list d) All of the above

c) Special cases are not required for operations on nodes at the beginning or end of the list

When we use recursion to solve a problem, we have 1. a problem that contains one or more problems that are similar to itself 2. a version of the problem that is simple enough to be solved by itself, without recursion, and 3. a way of making the problem simpler so that it is closer to (and ultimately the same as) the version in 2. What is 2. called? a) The simple case b) The inductive case c) The base case d) The iterative case e) None of the above

c) The base case

public class RecursiveMath ... public int fib (int a) { if (a == 1) return 1; else return fib(a-1) + fib(a-2); } ... } Given the above definition, what is the result of executing the following? RecursiveMath bill = new RecursiveMath(); int x = bill.fib(-1); a) x is set to -1 b) x is set to undefined c) The code does not terminate d) The code cannot be executed, because it won't compile e) None of the above

c) The code does not terminate

For an array implementation of a stack, the most efficient choice for the top location is a) Wherever you feel like it, it doesn't matter. b) The last slot, array.length()-1. c) The last stored element in the array. d) The first element in the array. e) Both ends, it is actually best to always just use a deque.

c) The last stored element in the array.

Which of these is a traditional measure for the cost of a sorting algorithm? a) The memory size b) The amount by which the values are out of order c) The number of comparisons d) The number of records

c) The number of comparisons

When is Selection Sort a good choice to use for sorting an array? a) None of these answers b) When the array has only a few elements out of place c) When the cost of a swap is large, such as when the records the long strings d) When each component of the array requires a small amount of memory

c) When the cost of a swap is large, such as when the records the long strings

In which case might the number of comparisons NOT be a good representation of the cost for a sorting algorithm? a) When the CPU is really fast b) When there are lots of records c) When we are comparing strings of widely varying length d) When the amount of available space is small

c) When we are comparing strings of widely varying length

You've got a class that holds two ints and that can be compared with other IntPair objects: class IntPair { private int a; private int b; public IntPair(int a, int b) { this.a = a; this.b = b; } public int compareTo(IntPair other) { if (a < other.a) { return -1; } else if (a > other.a) { return 1; } else { if (b == other.b) { return 0; } else if (b > other.b) { return -1; } else { return 1; } } } } Let's denote new IntPair(5, 7) as [5 7]. You've got a list of IntPairs: [2 5], [4 6], [2 3] You sort them using IntPair.compareTo. What is their sorted order? a) [4 6], [2 3], [2 5] b) [4 6], [2 5], [2 3] c) [2 5], [2 3], [4 6] d) [2 3], [2 5], [4 6]

c) [2 5], [2 3], [4 6]

Which of the following List member methods should not be implemented as a public method for a SortedList? a) add (T newEntry) b) All of these should be implemented c) add (int newPosition, T newEntry) d) remove(int givenPosition) e) getEntry(int givenPosition)

c) add (int newPosition, T newEntry)

Use a list containing exercise objects: bicep curls, burpees, lunges, overhead presses, planks, push-ups, sit-ups, squats, tricep dips. What would be the state of the list and iterator after three calls to next() and then a call to remove? a) overhead presses, planks, push-ups, sit-ups, squats, tricep dips b) bicep curls, burpees, lunges, planks, push-ups, sit-ups, squats, tricep dips c) bicep curls, burpees, overhead presses, planks, push-ups, sit-ups, squats, tricep dips d) planks, push-ups, sit-ups, squats, tricept dips

c) bicep curls, burpees, overhead presses, planks, push-ups, sit-ups, squats, tricep dips

Given a list: bicep curls, burpees, push-ups, sit-ups, squats, tricep dips With an iterator between burpees and push-ups. What would be the state of the list after the following sequence of iterator calls: next(), remove(), next(), remove()? a) bicep curls, burpees, push-ups, sit-ups, squats, tricep dips b) bicep curls, sit-ups, squats, tricep dips c) bicep curls, burpees, squaats, tricep dips d) IllegalStateException

c) bicep curls, burpees, squaats, tricep dips

An algorithm has... a) time requirements b) space requirements c) both a & b d) none of the above

c) both a & b

This sorting algorithm repeatedly examines neighboring elements, swapping those pairs that are out of order. a) selection sort b) insertion sort c) bubble sort d) quick sort e) merge sort

c) bubble sort

When a linked chain contains nodes that reference both the next node and the previous node, it is called a(n)... a) multi-linked chain b) two-way linked chain c) doubly linked chain d) ordinary chain

c) doubly linked chain

public class RecursiveMath ... public int fib (int a) { if (a < 2) return a; else return fib(a-1) + fib(a-2); } ... } What is the base case for fib in the above definition? a) int a b) fib(a-1) + fib(a-2); c) fib(a) for a < 2 d) fib(a) for a >= 2 e) None of the above

c) fib(a) for a < 2

What would the following queue look like after 3 dequeues? firstnode --> [3][]-->[1][]-->[5][]-->[9][] <-- lastNode a) firstNode --> [9][] b) firstNode --> [3][] c) firstNode --> [9][] <-- lastNode d) firstNode --> [3][] <-- lastNode

c) firstNode --> [9][] <-- lastNode

In the worst case, the total number of comparisons for Insertion Sort is closest to: a) n^​2 b) n log n c) n^2/2 d) n​​

c) n^2/2

Which of the following is a possible sequence of calls to get from: barbells, step, weights, mat with an iterator before barbells to: barbells, weights, mat with an iterator between barbells and weights... a) next() b) next(), remove(), next() c) next(), next(), remove() d) next(), remove(), next(), next() e) next(), next(), remove(), next()

c) next(), next(), remove()

In a circular array-based implementation of a queue, the initial size of the array should be... a) two more than the queue's initial capacity b) two less than the queue's initial capacity c) one more that the queue's initial capacity d) one less than the queue's initial capacity

c) one more that the queue's initial capacity

You should express the complexity of an algorithm in terms of its... a) space requirements b) execution time c) problem size d) overall complexity

c) problem size

The dequeue operation: a) adds a new item at the front of a queue b) returns without removing the item at the front of the queue c) removes and returns the item at the front of the queue d) adds a new item at the end of a queue e) returns true if a queue is empty and otherwise false

c) removes and returns the item at the front of the queue

An example of something that could be built using a QueueADT is a structure that models: a) The undo operation in a word processor b) the back button in a web browser c) the customers waiting to talk to an online helpdesk d) a hundred names in alphabetical order, where names are added and removed frequently e) the roads and intersections in a city

c) the customers waiting to talk to an online helpdesk

Problem size is defined as... a) the amount of memory an algorithm uses b) the amount of execution time an algorithm takes c) the number of items an algoritm processes d) none of the above

c) the number of items an algorithms processes

Consider the following code: public int examMethod(int n) { if (n == 1) return 1; else if (n > 1) return (n + this.examMethod(n-1)); } What is the purpose of examMethod? a) to compute fibonacci(n) b) to compute factorial(n) c) to compute the sum of the positive integers from 1 to n d) none of the above

c) to compute the sum of the positive integers from 1 to n

Based on the insertion sort code traced in the demo. Given an array {15, 2, 46, 3, 10, 9}. What is the state of the array when i = 3 and the call to insertInOrder is complete? a) {15, 2, 46, 3, 10, 9} b) {2, 3, 46, 15, 10, 9} c) {2, 3, 15, 46, 10, 9} d) {2, 3, 10, 15, 46, 9} e) {2, 3, 9, 10, 46, 15}

c) {2, 3, 15, 46, 10, 9}

Given array: private int[] counts = {74, 55, 34, 99, 22} Trace selection sort from the video demo. What does the array look like at the end of the for loop when lh = 2? a) {74, 55, 34, 99, 22} b) {22, 34, 55, 99, 74} c) {22, 34, 55, 99, 74} d) {74, 34, 55, 99, 22}

c) {22, 34, 55, 99, 74}

What is the average-case time for Selection Sort to sort an array of n records? a) Θ(n​^2​​) b) Θ(logn) c) Θ(n) d) Θ(nlogn)

c) Θ(n)

What is the best-case time for Selection Sort to sort an array of n records? a) Θ(logn) b) Θ(n) c) Θ(n​^2​​) d) Θ(nlogn)

c) Θ(n​^2​​)

What is the running time of Bubble Sort when the input is an array where all record values are equal? a) Θ(logn) b) Θ(n) c) Θ(n​^2​​) d) Θ(nlogn)

c) Θ(n​^2​​)

Given a full queue in an array contents that is storing the values {'Y','E',null,'N','O','T'} What happens when enqueue('T') is called? Once the demonstrated ensureCapacity method is executed, what will be store in contents[1]? a) 'Y' b) 'E' c) 'N' d) 'O' e) Null

d) 'O'

public static void displayArray3(int[] array, int first, int last) { if (first === last) System.out.println(array[first] + " "); else { int mid = (first + last) / 2; displayArray3(array, first, mid); displayArray3(array, mid + 1, last); } An initial call to displayArray3 has parameter values of 0 and 20 for first and last respectively: displayArray3(myArray, 0, 20). Which of the following would be the values of first and last in the second recursive call from that method call? a) 0,20 b) 0,10 c) 10,20 d) 11,20

d) 11,20

Based on the insertion sort code traced in the demo for a linked chain. Given a linked chain containing 8 -> 4 -> 32 -> 16 -> 256 -> 64 -> 128, what is the state of the linked chain at the end of the fifth time through the while loop in insertionSort? a) 4 -> 8 -> 16 -> 64 -> 256 -> 32 -> 128 b) 4 -> 8 -> 32 -> 16 -> 256 -> 64 -> 128 c) 4 -> 8 -> 16 -> 32 -> 256 -> 64 -> 128 d) 4 -> 8 -> 16 -> 32 -> 64 -> 256 -> 128 e) 4 -> 8 -> 16 -> 32 -> 64 -> 128 -> 256

d) 4 -> 8 -> 16 -> 32 -> 64 -> 256 -> 128

Suppose you are trying to choose between an array and a singly linked list to store the data in your Java program. Which arguments would correctly support one side or the other? a) Linked list are better suited to a program where the amount of data can change unpredictably. b) Arrays provide more efficient access to individual elements. c) Linked lists provide more efficient access to individual elements. d) A and B only e) A, B, and C

d) A and B only

If the characters 'D', 'C', 'B', 'A' are placed in a stack (in that order), and then removed one at a time, in what order will they be removed? a) DCAB b) DCBA c) ABDC d) ABCD

d) ABCD

When looping through the chain to see if the list contains a designated item it is necessary to check that the current reference is not null because... a) It may be at the end of the list b) The designated item may not be in the list c) The list may be empty d) All of the above

d) All of the above

It is an error to dequeue data from a(n) _______ queue. a) Array-based b) Full c) Linked d) Empty

d) Empty

It is an error to enqueue data onto a(n) _______ queue. a) Array-based b) Linked c) Empty d) Full e) Initialized

d) Full

What are the merits of insertion sort compared to bubble sort and selection sort? a) It doesn't require as much extra storage. b) It copies elements only to their final location c) It requires less code. d) It is faster for already sorted data e) It can be implemented recursively

d) It is faster for already sorted data

The Stack is best characterized as: a) Just-in-Time b) First-In, First-out c) First come, First Served d) Last-In, First-Out

d) Last-In, First-Out

If client code is traversing a list by repeatedly using a get method and the underlying structure is a linked chain. The efficiency of traversal is: a) O(1) b) O(logn) c) O(n) d) O(n^2)

d) O(n^2)

The time complexity of selection sort is: a) O(1) b) O(n) c) O(n log n) d) O(n^2) e) none of the above

d) O(n^2)

The worst-case time complexity of insertion sort is: a) O(1) b) O(n) c) O(n log n) d) O(n^2) e) none of the above

d) O(n^2)

What is the big Oh of the following code snippet? for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (candy.getFrequencyOf(favorites[j]) ==i) { return favorites[j]; } } } a) O(j) b) O(n) c) O(n^2) d) O(n^3)

d) O(n^3)

Use this scenario to answer the following questions: Case Study - e-Commerce solution (online storefront) for ABC Ltd. You are required to produce a design for an e-commerce solution (online storefront) for the retail company ABC Ltd. This design must take the form of a UML class diagram. High-level requirements have been provided below. ABC will use the solution to promote and sell the thousands of products listed in ABC's product catalog. Though ABC expects to add other products in the near future the catalog currently includes books, DVDs, music CDs, apparel, consumer electronics, beauty products, kitchen items, jewelry, watches, garden items, and toys. Potential customers must be able to visit the online storefront to: Search or browse ABC's product catalog View product details (including description, price, customer ratings and reviews, etc.) Manage their shopping cart (add products to cart, remove products, etc.) In addition, registered customers must be able to login, manage their user account, check out/place orders, and submit reviews of items previously purchased. To register a customer user must complete and submit an online registration form, providing ABC with their email address, password, and one or more of each of the following, phone number, shipping address, billing address, and payment details. ABC's customer service, order fulfillment, and other employee users must also be able to use the system to support business operations. Which of the following is the best option for classes for this scenario? Carefully consider the options presented, remember that some nouns are better suited for fields not classes. a) Price, Order, User, Password, Book, DVD, Apparel, Toy, FirstName, LastName b) Product, Quantity, OrderDate, ShippingAddress, BillingAddress, Username c) Register, Account, CheckingOut, Submit, Add d) ProductCatalog, Product, User, Customer, Employee, Order

d) ProductCatalog, Product, User, Customer, Employee, Order

One difference between a queue and a stack is: a) Stacks use two ends of the structure, queues use only one b) Queues require linked lists, but stacks do not c) Stacks require linked lists, but queues do not d) Queues use two ends of the structure; stacks use only one

d) Queues use two ends of the structure; stacks use only one

Which of these will NOT affect the RELATIVE running times for two sorting algorithms? a) The amount by which the values are out of order b) The allowable range for the record values c) The number of records d) The CPU speed

d) The CPU speed

When is Insertion Sort a good choice for sorting an array? a) Each record requires a large amount of memory b) None of these situations c) The processor speed is fast d) The array has only a few records out of the sorted order

d) The array has only a few records out of the sorted order

Given that 0 <= k < number of entries in the list minus 1, after a call to remove(k), getEntry(k) should return a) Null b) an IndexOutOfBoundsException c) The item formerly stored in position k d) The item formerly stored in position k + 1 e) The item formerly stored in position k - 1

d) The item formerly stored in position k + 1

If an item is inserted in position k of a list of n items, which of the following is true? a) The item in position k will be removed b) The item in position k will be replaced with the item from position k+1 c) The item in position k will be placed with the item from position k - 1 d) The item in position n will be moved to position n + 1 e) The item in position n will be moved to position n - 1 f) The item in position n will be moved to position n - 1

d) The item in position n will be moved to position n + 1

On a real computer, what will happen if you make a recursive call that never makes the problem size smaller? a) The program keeps running until you stop it b) The results are nondeterministic c) The operating system detects the infinite recursion because of the repeated state d) The run-time stack overflows, halting the program

d) The run-time stack overflows, halting the program

When is Bubble Sort a good choice for sorting an array? a) Each component of the array requires a small amount of memory b) Each component of the array requires a large amount of memory c) The array has only a few items out of place d) There is no situation where Bubble Sort is the best choice over all of the others in this chapter

d) There is no situation where Bubble Sort is the best choice over all of the others in this chapter

In which cases are the time complexities the same for Selection Sort? a) Worst and Best b) Best and Average c) Worst and Average d) Worst, Average, and Best

d) Worst, Average, and Best

The enqueue operation: a) adds a new item at the front of the queue b) returns without removing the item at the front of the queue c) removes and returns the iteam at the front of the queue d) adds a new item at the end of the queue e) returns true if the queue is empty and otherwise false

d) adds a new item at the end of the queue

A method with the header public static double getMax(Iterable<price> prices) can be called with a parameter that is: a) an array b) any type that implements Collection c) from a foreach loop d) any type that implements Iterable

d) any type that implements Iterable

Where will you find the item added earliest to a queue? a) randomly b) in the middle c) at the back d) at the front

d) at the front

Given that backIndex references the last element of the queue stored in a contents array, which of the following best describes how to update backIndex when a new entry is successfully enqueued: a) frontIndex++ b) backIndex++ c) frontIndex = (frontIndex + 1) % contents.length d) backIndex = (backIndex + 1) % contents.length

d) backIndex = (backIndex + 1) % contents.length

Select the best choice below to fill in the blanks: When a __________ implements Comparator, the __________ named ____________ must be implemented. a) method, class, compare b) generic, class, compare c) generic, type, compare d) class, method, compare

d) class, method, compare

What type of behavior defines a queue? a) none of the above b) first-in last-out c) last-in first-out d) first-in first-out

d) first-in first-out

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 1 and backIndex is 4 a) empty queue b) one element in the queue c) three elements in the queue d) four elements in the queue e) five elements in the queue f) six elements in the queue g) invalid

d) four elements in the queue

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 3 and backIndex is 0 a) empty queue b) one element in the queue c) three elements in the queue d) four elements in the queue e) five elements in the queue f) six elements in the queue g) invalid

d) four elements in the queue

In the best case, the total number of swaps done by Selection Sort is closest to: a) n^2/2 b) n^2 c) nlogn d) n

d) n

Given a list: bicep curls, burpees, push-ups, sit-ups, squats, tricep dips With an iterator between burpees and push-ups. What would a call to next() return? a) Null b) bicep curls c) burpees d) push-ups e) sit-ups f) NoSuchElementException

d) push-ups

Based on the deque class shown in the videos. Given the following member method: public T removeBack(){ T back = getBack(); lastNode = lastNode.getPrev(); if (lastNode == null) firstNode = null; else lastNode.setNext(null); return back; } What is the case that is covered when the expression (lastNode == null) is true? a) removing from a deque with items only at the front b) removing from a full deque c) removing from an empty deque d) removing from a deque with one item

d) removing from a deque with one item

If a generic method is declared with type parameter <T extends Comparable<T>> and local variables value and target, both of type T, are given, then the following code can be used within the method: a) compareTo(target) b) value.compareTo(T) c) compareTo(value) d) value.comparTo(target) e) value implements T

d) value.comparTo(target)

What is the running time of Insertion Sort when the input is an array that has already been sorted? a) Θ(n​2​​) b) Θ(logn) c) Θ(nlogn) d) Θ(n)

d) Θ(n)

What is the running time for Insertion Sort when the input array has values that are in reverse sort order? a) Θ(nlogn) b) Θ(n) c) Θ(logn) d) Θ(n^​2​​)

d) Θ(n^​2​​)

What is the running time of Bubble Sort (as the algorithm is presented in this module) when the input is an array that has already been sorted? a) Θ(n) b) Θ(logn) c) Θ(nlogn) d) Θ(n^​2​​)

d) Θ(n^​2​​)

Given the following code: public static void springFreeze(int temp) { if (temp < 32) System.out.println("Frost!"); else { System.out.println("temps are dropping..."); springFreeze(temp - 4); } } How many times will springFreeze(28) print out "temps are dropping..."? a) 10 b) 4 c) 3 d) 2 e) 0

e) 0

Given the following code: public static int powerOf5(int exponent) { if (exponent == 0) return 1; else return 5 * powerOf5(exponent -1); } what is powerOf5(3)? a) Infinite recursion b) 1 c) 15 d) 25 e) 125

e) 125

The following sequence of operations is performed on a stack: push(1), push(2), pop, push(1), push(2), pop, pop, pop, push(2), pop. The values will be output in this order: a) 2, 1, 2, 2, 1 b) 2, 1, 2, 2, 2 c) 2, 2, 1, 2, 2 d) 1, 2, 2, 1, 2 e) 2, 2, 1, 1, 2 f) 1, 2, 1, 2, 2

e) 2, 2, 1, 1, 2

Given a list: bicep curls, burpees, push-ups, sit-ups, squats, tricep dips With an iterator between burpees and push-ups. What would the state of the iterator be after a call to next() ? a) Before bicep curls b) Between bicep curls and burpees c) Between burpees and push-ups d) Between burpees and sit-ups e) Between push-ups and sit-ups

e) Between push-ups and sit-ups

Which value of a queue is accessible? a) The lowest-valued item b) The rear item c) The top item d) The bottom item e) The front item f) The root g) The highest-valued item

e) The front item

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 0 and backIndex is 4 a) empty queue b) one element in the queue c) three elements in the queue d) four elements in the queue e) five elements in the queue f) six elements in the queue g) invalid

e) five elements in the queue

Based on the insertion sort code traced in the demo. Given an array {15, 2, 46, 3, 10, 9}. What is the state of the array when i = 4 and the call to insertInOrder is complete? a) {2, 3, 9, 46, 15, 10} b) {2, 3, 15, 46, 10, 9} c) {2, 3, 10, 46, 15, 9} d) {2, 3, 9, 10, 46, 15} e) {2, 3, 10, 15, 46, 9}

e) {2, 3, 10, 15, 46, 9}

How many times does Selection Sort call the swap function on an array of n records? a) 1 b) It depends on the order of the records c) n d) nlogn e) n^2 f) n-1

f) n-1

In the worst case, the total number of comparisons for Bubble Sort is closest to: a) n^​2​​ b) 2n^2 c) n​/2​​ d) n e) 2n f) n^2/2 g) n/4 h) n^2/4

f) n^2/2

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 0 and backIndex is -1 a) empty queue b) one element in the queue c) three elements in the queue d) four elements in the queue e) five elements in the queue f) six elements in the queue g) invalid

g) invalid


Kaugnay na mga set ng pag-aaral

Chapter I - Overview of Statistics

View Set

Series 65: Laws, Regulations, and Guidelines, Including Prohibition on Unethical Business Practices

View Set

Chronic Obstructive Pulmonary Disease (COPD)

View Set

NUR 301 | Chapter 23: Nursing Management: Patients With Gastric and Duodenal Disorders PrepU

View Set

很重要SAUNDERS OB ANTEPARTUM (3)

View Set