cs2114 final prep

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

To remove the node in position k, which of the following is needed?

A reference to the node in position k-1

The clone() method defined in the Object class performs:

A shallow copy

Shallow copy for an object means creating a new instance of the object containing a copy of all of its instance variables references.

False

Consider a system with a cache capacity of 3 which uses the FIFO Cache Eviction Policy. If the cache was initially empty, which items would still be in the cache after an application requests files in the following order: File 7, File 55, File 32, File 3, File 44, File 32, File 44, File 55?

File 3, File 44, File 55

Which cache policy is more susceptible to exploitation by a malicious user (hacker) who knows the cache policy used by a given system?

Least Recently Used

What does the compare method of a comparator object return when the first parameter is less than the second?

Less than 0

Suppose QueueADT is implemented using a singly linked list. What is the lowest Big-Oh time complexity that can be achieved for an enqueue method?:

O(1)

What is the big-Oh complexity of isEmpty() on a list that is implemented with a singly linked chain?

O(1)

What is the time complexity for adding an entry to a fixed-size array-based bag ADT?

O(1)

What is the time complexity for adding an entry to a linked-based bag ADT?

O(1)

Suppose you have a sorted list of numbers stored in a Java array of ints. What is the worst-case time complexity of searching for a given number in the list using binary search?

O(log n)

For an array implementation of a list, the worst case efficiency of remove(index) is:

O(n)

If client code is traversing a list by using an iterator. The efficiency of traversal is:

O(n)

If the top of the stack is the first entry of the array what is the complexity for pop() in big Oh notation?

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?

O(n)

Suppose you have a list of numbers stored in consecutive locations in a Java array. What is the worst-case time complexity of finding a given element in the array using linear search?

O(n)

The time complexity of linear search is:

O(n)

What is the worst-case time complexity for searching a linked-based bag ADT for a particular entry?

O(n)

The time complexity of selection sort is:

O(n2)

The worst-case time complexity of insertion sort is:

O(n2)

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:

O(n^2)

What is the running-time efficiency of the following code in terms of Big-O? for (int i = 0; i <= n; i++){ for (int k = 1; k <= n; k*=2{ System.out.print(i * j * k); } }

O(nlogn)

Based on the find method traced in the video, it depends on T extending Comparable.

True

Based on the find method traced in the video, it is a recursive method.

True

Binary search trees with no duplicate entries have nodes with 0,1, or 2 children

True

Deep copy for an object means performing a shallow copy plus copying all of the mutable objects inside the object.

True

For binary search trees with no duplicate entries, entries in the left subtree of a node are less than the entry in the node.

True

For binary search trees with no duplicate entries, entries in the right subtree of a node are greater than the entry in the node.

True

To deep clone an array-based collection, you need to perform 3 levels of cloning: Shallow copy, clone the array object, and deep clone the items stored in the array.

True

Select all of the following that will happen if removeFront() is called on a deque with 1 item?

firstNode and lastNode will become null lastNode.data will be returned firstNode.data will be returned

Given that the height of a tree is 1 more than the number of edges from the root to the deepest node:If a binary tree n nodes that either have 0 or 2 children and all leaves on the same level, what is the height of the tree?

log2(n+1)

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.getData()); } } Indicate how each private helper member method would print a non-empty chain

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)?

infinite recursion

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

invalid

For binary search trees with no duplicate entries, entries in the left subtree of a node are greater than the entry in the node.

False

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?

"Better Half" "Sidekick" "Bro"

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");

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

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");

"Ford Fiesta", "Chevrolet Sonic", "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");

"cheetah"

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?

"my"

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]?

'O'

What condition to use to test whether an array based queue with one unused location is full.

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

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 >; }

(firstNode == null) && (lastNode == null) (firstNode == null) (lastNode == null)

For large values of n which statement is true?

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

Given the following code skeleton for the private helper method: if (first > last) return ___________________;else { int mid = (first + last) / 2; if (ray[mid].equals(target))return ___________________; if (ray[mid].compareTo(target) < 0)return ___________________; elsereturn ___________________;} Select the order of the code to fill in the blanks:

-1 mid binarySearchHelper(ray,target,mid + 1,last) binarySearchHelper(ray,target,first,mid-1)

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?

0

For binary search trees with no duplicate entries, entries in the right subtree of a node are less than the entry in the node.

False

How many times will springFreeze(28) print out "temps are dropping..."?

0

What does the compareTo method return when the calling object and the parameter are equal?

0

Given a circular array implementation of a queue in this state with queue.length as 7, you are to finish the trace of ensureCapacity() and answer the question below: What are the values of frontIndex and backIndex after the call is complete?

0,5

Suppose you try to perform a binary search on a 5-element array sorted in the reverse order of what the binary search algorithm expects. How many of the items in this array will be found if they are searched for?

1

When getHeight is called with the node that contains D. What value will the recursive call getHeight(node.getRight()) return?

1

Assume that we have a Link class reference named head and named q that point to Link nodes as follows: q pointing at 10 What will the order of the items be after applying these lines of code? Link r = q.next; q.next = head; head.next = r; head = q;

10 =>5 => 15 => 20

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?

11, 20

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)?

125

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)?

136

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);}

14

Suppose you try to perform a binary search on the unsorted array {1, 4, 3, 7, 15, 9, 24}. Which element will not be found when you try searching for it?

15

Approximately how many recursive calls would our Towers of Hanoi pseudo code algorithm make given a tower with 11 disks?

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

2^7

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 }

3

How many times will springFreeze(40) print out "temps are dropping..."?

3

Given that the height of a tree is 1 more than the number of edges from the root to the deepest node: If a binary tree of height 5 has nodes that either have 0 or 2 children and all leaves on the same level, how many nodes are in the tree?

31

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?

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

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?

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)?

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 for demoRecursion(1)?

48

Suppose you try to perform a binary search on the unsorted array {1, 4, 3, 7, 15, 9, 24}. How many of the items in this array will be found if they are searched for?

5

Given that the height of a tree is 1 more than the number of edges from the root to the deepest node: If a binary tree of height 3 has nodes that either have 0 or 2 children and all leaves on the same level, how many nodes are in the tree?

7

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?

99

If you attempt to call the clone method on an object that doesn't implement the Cloneable interface

A CloneNotSupportedException will be thrown

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 and B only

Leaf

A node that has no children

Given the above binary tree rooted at Node A, what is the order of nodes visited by a preorder search?

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

If an inorder traversal of a complete binary tree visits the nodes in the order ABCDEF (where each letter is the value of a node), which order are the nodes visited during an postorder traversal? Recall that OpenDSA defines a complete binary tree as follows: "A complete binary tree has a restricted shape obtained by starting at the root and filling the tree by levels from left to right. In the complete binary tree of height d, all levels except possibly level d are completely full."

ACBEFD

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?

All of the above

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

All of the above

What will happen if removeFront() is called on an empty deque?

An EmptyDequeException will be thrown

Binary search trees with no duplicate entries have nodes with exactly two children .

False

Which of the following is more restrictive?

ArrayList<Integer> myList;

With respect to Cybersecurity the term ______ refers to mechanisms which attempt to confirm That users are who they claim to be The "believed" source of data matches the "actual" source of data.

Authenticity

The following code will create a series of Link nodes, with the first one pointed to by head. What order will the Link nodes be in after this code is executed? Node head = new Node("Z", null); Node p = new Node("C", null) head.next = new Node("B", p); Node c = head.next.next; head.next.next = new Node("F", c); c = head; Node temp = head.next.next; temp.next.next = new Node("A", head); head = c.next; c.next = null;

B => F => C => A => Z

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() ?

Between push-ups and sit-ups.

Which of the following statements about binary search algorithms is FALSE?

Binary search can be implemented to take O(1) time in the worst case.

This is a notoriously inefficient algorithm traditionally taught to introduce sorting algorithms:

Bubble sort

What node will be in a same rank (position) if the following tree is traversed by preorder, postorder and inorder algorithm?

C

What node will be visited prior to E in an inorder traversal of the following tree?

C

Your Web Browser is an example of what type of software?

Client

When you upload assignment submissions to WebCAT for grading you (and your software and hardware) are adopting the role of a _________ with WebCAT acting in the role of a _________.

Client, Server

Insertion sort on an array is requires (select all that apply):

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

With respect to Cybersecurity the term ______ means the protection of data from being viewed or used by unauthorized users.

Confidentiality

Select the best generalized algorithm for adding to a list using a linked chain implementation:

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

Given the above binary tree rooted at Node A, what is the order of nodes visited by an inorder search?

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

Based on the find method traced in the video, it depends on data extending Comparator.

False

Based on the find method traced in the video, it is an equals method for binary search trees.

False

Based on the find method traced in the video, it throws an exception when data is not found.

False

Binary search trees with no duplicate entries have all leaves on the the second level.

False

Select the most accurate steps to remove a node that contains a designated element.

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

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?

Head = newNode;

Which of the following is the best example of a data availability management concern, as described by the CIA Triad?

How to distinguish a flash crowd vs DDOS attack.

If the top of the stack is the last element in the array what is the complexity for push(newEntry) in big Oh notation?

O(1)

Which combination of statements are True? Statements: The question mark (?) is a wildcard or placeholder, representing an unknown type In the statement "? extends MyClass", the ? represents a subtype of MyClass where MyClass represents an Upper Bound In the statement "? extends MyClass", the ? represents a supertype of MyClass where MyClass represents a Lower Bound

I and II

What is not true about a binary search tree?

If there are n nodes, then its height is n/2

Root

In a tree, the topmost node of the tree.

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); }

In reverse order

With respect to the declaration ArrayList<? super Customer> myCustomer; Which of the following is True?;

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

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?

Insertion Sort

The use of a generic data type is preferred over using Object as a general class in a collection because

It guarantees that all the objects contained in the collection are related by inheritance, thus avoiding a ClassCastException in the client code

Advantage(s) of an inner iterator class over a separate, (non-inner), iterator class:

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

What are the merits of insertion sort compared to bubble sort and selection sort?

It is faster for already sorted data.

Suppose you have a binary search tree with no left children. Duplicate keys are not allowed. Which of the following explains how this tree may have ended up this way?

It was filled in ascending order.

A stack is

LIFO (last in first out)

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):

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

Keeping track of lastNode in addition to firstNode

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

In a circular array-based implementation of a queue, what is the efficiency performance of the dequeue operation ?

O(1)

In a circular array-based implementation of a queue, what is the performance when the dequeue operation ?

O(1)

In a linked chain implementation of a queue, the performance of the enqueue operation is

O(1)

What node will be visited after A in a preorder traversal of the following tree?

N

Would blacklisting a specific state/region fully prevent Distributed DOS (DDOS) attacks on a targeted victim's public online service (for example YouTube)?

No

Child node

Node referenced by another node in a tree.

Sibilings

Nodes that have the same parent node.

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?

Null

Here is a definition for the Employee class. class Employee {String name;public Employee(String name) {this.name = name;}public void setName(String name) {this.name = name;}public void print() {System.out.println(name);}} What is the expected output of the following code snippet? Employee[] listOfEmployees = new Employee[5];listOfEmployees[0].setName("Mark");listOfEmployees[0].print();

NullPointerException will be thrown

Java uses quicksort and mergesort under the hood for built-in sorting of arrays and lists. These algorithms have efficiency:

O( n log n)

If an algorithm requires 7 basic operations for an algorithm with a problem size of n, the algorithmic complexity is

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?

O(1)

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 waspopped.) stack.push("K"); stack.pop(); stack.push("P"); stack.push("G"); stack.push("R"); String str = stack.pop(); stack.push("V"); stack.push(str);

R V G P

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);

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();

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();

Rudy

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();

Sam

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?

Selection sort

The benefit of using sentinel nodes

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

In some cases a recursive solution to a given problem is more intuitive and easier to implement than an iterative solution. However, recursive solutions are usually more expensive than iterative solutions in terms of:

Storage space

The advantage of a hard drive versus cache is that

The advantage of a hard drive versus cache is that

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);

The code does not terminate

Edge

The connection that links two nodes

Select all of the following that will happen if removeFront() is called on a deque with 3 items?

The first node of the three will be removed firstNode.data will be returned

Given that 0 <= k < number of entries in the list minus 1, after a call to remove(k), getEntry(k) should return

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?

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

For an array implementation of a stack, the most efficient choice for the top location is

The last stored element in the array.

static <T> void sort(T[] a, Comparator<? super T> c) What does the previous method declaration mean?

The method can sort any object that defines a Comparator class for that object or any of it's super types

The following references can be used to add an item to position k in a linked chain implementation of a list:

The node containing the item in position k - 1

What will be ouput as a result of a call to the calculate method? private int sum = 0; private int product = 0; public static final int AMOUNT = 5; public void output(){ System.out.println("The sum of the numbers from 1 to " + AMOUNT + " is " + sum); System.out.println("The product of the numbers from 1 to " + AMOUNT + " is " + product); } public void calculate(){ int sum = 0; int product = 1; for (int i = 1; i <= AMOUNT; i++){ sum = sum + i; product = product * i; } output(); }

The sum of the numbers from 1 to 5 is 0 The product of the numbers from 1 to 5 is 0

Based on ListInteface.java, an attempt to remove and item from an empty list will

Throw an IndexOutofBoundsException

In cybersecurity the term ______ is used to refer to a weakness in an information system, system security procedures, internal controls, or implementation that could be exploited or triggered by a threat source

Vulnerability

Locating a new node's insertion point in a binary search tree stops when

We reach a null child.

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)

client code can only provide type Number or any subclass of Number for the type parameter for T

For the list, [20, 40, 10, 30], what will the array look like after the second pass of selection sort?

[10, 20, 40, 30]

You've got a class that holds two ints and that can be compared with other IntPair objects: 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?

[3 7], [3 4], [4 6]

Which of the following best describes the 2 key components of a recursive method:

a base case and a recursive case

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 linked list

Which of the following List member methods should not be implemented for a SortedList?

add (int newPosition, T newEntry)

Which bag behavior(s) would need to be modified when implementing a set?

add()

The enqueue operation:

adds a new item at the end of the queue

implementation

all the data fields and details of the method definitions

A key benefit of inheritance is

an object can have several types, it is type compatible with any of its superclasses

Where does a queue add new items?

at the back

Where will you find the item added earliest to a queue?

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:

backIndex = ( backIndex + 1) % contents.length

What would be the state of the list after the following sequence of iterator calls: next(), remove(), next(), remove()?

bicep curls, burpees, squats, tricep dips

This sorting algorithm repeatedly examines neighboring elements, swapping those pairs that are out of order.

bubble sort

Select the best choice below to fill in the blanks: When a __________ implements Comparator, the __________ named ____________ must be implemented.

class, method, compare

Select the best choice below to fill in the blanks: When a __________ implements Comparable, the __________ named ____________ must be implemented.

class, method, compareTo

If an ArrayQueue is stored an array contents with 1 unused element, which of the following are true (select all that apply):

contents.length -1 indicates the capacity of the queue 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?

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

Encapsulation

design principle that encloses data and methods within a class, thereby hiding the class' implementation details

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?

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

When a linked chain contains nodes that reference both the next node and the previous node, it is called a(n)

doubly linked chain

To efficiently remove a node at the end of a linked chain implementation of a queue requires a

extra reference in the node pointing to the previous node

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?

fib(a) for a < 2

What type of behavior defines a queue?

first-in first-out

Given that a linked chain exists in memory as represented by the following: Consider execution of the following code, upon the linked chain above. What is the resulting order of Nodes? Node<String> q = firstNode.next; firstNode.next = q.next; q.next = firstNode; firstNode = q;

firstNode → "B" → "A" → "C" → "D"

Given that a double 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.

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

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 You Answered

five elements in the queue

abstraction

focus on what and not how

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

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

four elements in the queue

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?

front: 5 rear: 9

Trace the code starting at line 5. What method activation records are on the call stack from top to bottom at line 10?

method1

Trace the code starting at line 5. What method activation records are on the call stack from top to bottom at line 17?

method2, method1

Trace the code starting at line 5. What method activation records are on the call stack from top to bottom at line 30?

method4, method3, method2, method1

To remove a specified entry of a bag that is implemented with a linked chain, first get a reference to the node to remove, then the most efficient approach is to:

move the data in the first node to the referenced node , then remove the first node

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

next(), next(), remove()

Authenticity

no imposters

Confidentiality

no information leaking

Availability

no interruption of intended access

Assurance

no lying

Integrity

no tampering

Anonymity

no tracking

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

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

one element in the queue

In a circular array-based implementation of a queue, the initial size of the array should be

one more than the queue's initial capacity

Which of the following are true for a list ADT?

ordered items can be replaced

Which of the following visibility modifiers should be used for a field in a class C if the programmer does not want the subclass D to have direct access to the field?

private

Given the method header: public<T extends Comparable<? super T>> int binarySearch( T[] ray, T target) Which would be the best header for a helper method?

private <T extends Comparable<? super T>> int binarySearchHelper(T [] ray, T target, int first, int last)

You should express the complexity of an algorithm in terms of its

problem size

When we use recursion to solve a problem, we have a problem that contains one or more problems that are similar to itself a version of the problem that is simple enough to be solved by itself, without recursion, and a way of making the the problem simpler so that it is closer to (and ultimately the same as) the version in 2. What is 2. called?

the base case

Which of the following methods requires the creation of a new node?

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

Which of the following methods could throw an IndexOutOfBoundsException?

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

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?

push-ups

The dequeue operation:

removes and returns the item at the front of a queue

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?

removing from a deque with one item

The most efficient approach to dealing with a gap left in an array after removing an entry from a bag is to

replace the entry being removed with the last entry in the array and replace the last entry with null

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.

selection sort

When too many recursive calls are made, creating more activation records than the allocated program memory can handle, what kind of error/exception occurs?

stack overflow

An example of something that could be built using a QueueADT is a structure that models:

the customers waiting to talk to an online helpdesk

A 'Cache Hit' occurs when ______

the data item wanted by an application was found within the cache, thereby removing the need for the system to retrieve the data item from the hard drive (or some other storage medium).

In the demoed array-based implementation of a Stack ADT, the entry peek returns may be found at

the last occupied location in the array

Problem size is defined as

the number of items an algorithms processes

In the demonstrated linked-chain implementation of a StackADT, when a node is popped from the stack

the original first node will no longer be referenced

In the linked chain implementation of a queue, the chain's first node contains

the queue's front entry

An algorithm has

time requirements and space requirements

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?

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

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.

true

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

true

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:

value.compareTo(target)

client interface

what client code needs to know to use a class

Given the following 2 definitions for Computer and Notebook: public class Computer { private String manufacturer; private String processor; private int ramSize; private int diskSize; private double processorSpeed; public Computer(String manuf, String proc, int ram, int disk, double prcSpeed){ manufacturer = manuf; processor = proc; ramSize = ram; diskSize = disk; processorSpeed = prcSpeed; } public int getRamSize(){ return ramSize; } public int getDiskSize(){ return diskSize; } public double getProcessorSpeed(){ return processorSpeed; } public String toString(){ return "manufacturer: " + manufacturer + " " + "\nprocessor: " + processor + " "+ "\nramSize: " + ramSize + " " + "\ndiskSize: " + diskSize + " " + "\nprocessorSpeed: " + processorSpeed; }}//////////////////////////////////////////////////////////////////////////////////////////////////////////public class Notebook extends Computer { private double screenSize; private double weight; public Notebook( String manuf, String proc, int ram, int disk, double prcSpeed, double ScrnSz, double wt){ super(manuf, proc, ram, disk, prcSpeed); screenSize = ScrnSz; weight = wt; } public double getScreenSize(){ return screenSize; } public double getWeight(){ return weight; And: Computer myComputer = new Computer("Acme", "Intel", 2, 160, 2.4);Computer workComputer = new Notebook("DellGate", "AMD", 4, 240, 1.8, 15.0, 7.5); Which line of code doesn't compile?

workComputer.getWeight();

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);

x is set to -1

Given the following 2 definitions for Computer and Notebook: public class Computer { private String manufacturer; private String processor; private int ramSize; private int diskSize; private double processorSpeed; public Computer(String manuf, String proc, int ram, int disk, double prcSpeed){ manufacturer = manuf; processor = proc; ramSize = ram; diskSize = disk; processorSpeed = prcSpeed; } public int getRamSize(){ return ramSize; } public int getDiskSize(){ return diskSize; } public double getProcessorSpeed(){ return processorSpeed; } public String toString(){ return "manufacturer: " + manufacturer + " " + "\nprocessor: " + processor + " "+ "\nramSize: " + ramSize + " " + "\ndiskSize: " + diskSize + " " + "\nprocessorSpeed: " + processorSpeed; }}public class Notebook extends Computer { private double screenSize; private double weight; public Notebook( String manuf, String proc, int ram, int disk, double prcSpeed, double ScrnSz, double wt){ super(manuf, proc, ram, disk, prcSpeed); screenSize = ScrnSz; weight = wt; } public double getScreenSize(){ return screenSize; } public double getWeight(){ return weight; }} and: Notebook yourComputer = new Notebook("DellGate", "AMD", 4, 240, 1.8, 15.0, 7.5);Computer anotherComputer = new Computer("Acme", "Intel", 2, 160, 2.4);Computer anotherLaptop = new Notebook("Acme", "Intel", 2, 160, 2.4,7,8);Notebook moreLaptop = new Notebook("Acme", "Intel", 2, 160, 2.4,7,8); Which line of code doesn't compile?

yourComputer = anotherLaptop;

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?

{2, 3, 10, 15, 46, 9} PreviousNext

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?

{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?

{22, 34, 55, 99, 74}


संबंधित स्टडी सेट्स

Unit 9 | Societal & Technological Growth Part 2 | Jiya Munroe

View Set

AP EURO MID YEAR STUDY GUIDE MULTIPLE CHOICE -- USING ONLY 53 THESE ARE POSSIBLE EXACT QUESTIONS

View Set

Marriage and Family Counseling Midtern

View Set

Chapter 5 - Sexually Transmitted Infections

View Set

Little House in the Big Woods Chapter 6 Two Big Bears

View Set

Problem Set 5: Neurophysiology - Cellular Networks

View Set

30 Questions to test a Data Scientist on Natural Language Processing

View Set

Maternity Exam 3 Cumm. Questions

View Set