CS2114 Final

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

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..."?

3

If there is an if statement with 2 conditions, how many test cases are necessary?

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

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

An EmptyDequeException will be thrown

Given an array of ints named values, what does this code do? double largest = values[0]; for (int i = 1; i < values.length; i++) { if (values[i] > largest) { largest = values[i]; } }

Find the max value

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

The lifetime of a parameter in Java is

From when its method is called until it returns

The advantage of a hard drive versus cache is that

Hard drives hold more data

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.

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

Which loop starts at the first node of a non-empty linked chain and loops all the way through the chain?

Link curr = head; While (curr.next != null) curr = curr.next;

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

Which of the following adheres to the naming convention for declaring a Java constant?

final double PI = 3.14;

What type of behavior defines a queue?

first in first out

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

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] + " "); }

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

public int func(int x, int y) { if (y == 1) { return x; else return x + func(x, y+ 1) What. will be returned when func(2,3)

infinite recursion

Placing the Node class inside the LinkedBag class makes it a(n)

inner class

Select which to use based on the information given: If several classes have the same method signatures but implement all the methods differently.

interface

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

Which of the following BEST completes the statement An iterator ______________

is an object that traverses a collection

What kind of variable is label? public class Labeller extends JFrame { public Labeller () { JLabel label = new JLabel("Field or Variable");} public static void main (String[] args) { new Labeller();}}

local variable, Object Reference

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)

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 last node to the referenced node , then remove the last node

Which of the following is not true about an interface in Java?

must include a constructor

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

neither in order or reverse 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, last - 1); }

neither in order or reverse order

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

child node

node referenced by another node in a tree

siblings

nodes that are children of the same node

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

A risk of multiple iterators

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

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

One of the key features of Object-oriented programming is encapsulation. Because of encapsulation, we generally have _________ instance variables and _____________ methods.

private, public

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

problem size

A method called myMethod has been defined in a class with the following signature. Which of these four choices cannot be an overloaded alternative for myMethod? public void myMethod (int i, double d) Hint: Overloading a method means creating two methods with the same name but different parameters

public int myMethod(int i, double d)

Which of the following method declarations follows the accepted naming convention for Java?

public void myMethod(){}

Which method is run before each test method?

public void setUp(){}

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

If currentSize is 8, trace int[] values = { 35, 16, 100, 12, 100, 200, 250, 500, 0, 0}; int newElement = 11; if (currentSize < values.length) { currentSize++; values[currentSize - 1] = newElement; } What is the array after the code executes?

{ 35, 16, 100, 12, 100, 200, 250, 500, 11, 0};

If pos is 4 and currentSize is 7, trace this code that removes an item: int[] values = {10, 20, 30, 40, 50, 60, 70}; for (int i = pos + 1; i < currentSize; i++) { values[i - 1] = values[i]; } What is the array after the code executes?

{10, 20, 30, 40, 60, 70, 70}

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}

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}

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 Least Recently Used Cache Eviction Policy. If an application requests and accesses files in the order File 32, File 3, File 44, File 32, File 44, which item would be considered the Least Recently Used?

File 3

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

Given an array of ints named values, what does the following code do: for (int i = 0; i < values.length; i++) { values[i] = i * i; }

Fills the array with squares (0, 1, 4, 9, 16, ...)

What does the add method return?

true if the addition is successful, or false if not.

Which pair of code blocks are used to enclose exception-prone code, and to check for and handle exceptional events?

try and catch

The operator == tests to see if

two variables reference the same place in the computer's memory

Consider the following Java code: public interface toyCollectionInfo<T> { // 1 private T favoriteToy; private T[] toys; public T getFavorite(); public void setFavorite(T fav); } The capital letter "T" on line 1 stands for:

type to be used for the toys

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)

Consider the following Java method: public xxx printGreeting() { // 1 System.out.println("Hello!"); // 2 } // 3 The xxx in line 1 is best replaced by:

void

client interface

what client code needs to know to use a class

A stack is

LIFO (last in first out)

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

Throw an IndexOutofBoundsException

What does a reference type represent?

a memory address instead of the actual item stored in that address

leaf

a node that has no children

Why would the add method return false?

when the addition of a new item was not successful

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

Lists are ordered but not necessarily sorted. List ordering is based on the positions of the elements or Objects within the List, NOT on the value or state of the element or Object

** remember

SortedListInterface includes an additional remove method definition, boolean remove(T anEntry).

** remember

The SortedListInterface includes a new method, int getPosition(T anEntry). PreviousNext

** remember

What is ethics?

- An area of study that deals with ideas about what is good and bad behavior - Moral principles that govern a person's behavior or the conducting of an activity - A branch of philosophy dealing with what is morally right or wrong

Given the following statement: public ArrayList<Person> friends = new ArrayList<Person>(); Select all of the following that are true:

- Any Person object can be added to friends - Any object that is a subclass of Person can be added to friends

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

For large values of n which statement is true?

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

A SortedList implementation contains code which compares new elements being added to the SortedList to the elements previously added and stored within the SortedList. This comparison helps the add() method code determine the correct position to add the new element so as to preserve sorted order

** remember

ListInterface includes the method definition, T replace(int givenPosition, T newEntry), while SortedListInterface does not.

** remember

ListInterface includes the method definition, add(int newPosition, T newEntry), while SortedListInterface does not

** remember

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?

- Arrays provide more efficient access to individual elements. - Linked lists provide more efficient access to individual elements.

Why are ethics important to computer scientists and computing professionals?

- Computing Technology can have positive and negative effects on lives, society, and the world; computer scientists and computing professionals are responsible for considering the ethical implications and potential impact of the decisions they make

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?

- Generics provide type safety and enable strong type checks at compile time - Provide developers with the ability to implement generic algorithms (classes and methods)

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

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

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

- It may be at the end of the list - The designated item may not be in the list - The list may be empty

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

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

The following loop should reverse the order of the elements in the array. Trace the loop to find the bug. Which test case(s) fail? for (int i = 0; i < values.length / 2; i++) { int temp = values[i]; values[i] = values[values.length - 1]; values[values.length - 1] = temp; }

- [5 7 -3 19 42] - [2 4 6 8 10] - [-8 7 -6 5 -4 3]

A fixed size array

- has a limited capacity - can waste memory - prevents expansion when the bag becomes full

Which of the following are true for a list ADT?

- ordered - items can be replaced

Junit testing...

- provides ability to test specific methods -Uses assert statements instead of print statements -Should be used throughout development -Has a setUp method useful for initializing variables

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 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 ___________________; else return ___________________;} 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)

Which of the following statements are true? Check all that apply.

-A catch block must have an associated try block -A try block can have multiple catch blocks -Code in a finally block will always execute whether or not an exception occurs in the try block

Which of the following could result in code throwing a null pointer exception?

-Attempting to invoke a method from a null object -Attempting to use an object that was declared but never instantiated -Using an object that became null

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.lengt

Which of the following are good reasons to write tests that use your bag ADT before the implementation is done?

-it helps confirm the design -it helps check the suitability of the specification -it helps check your understanding of the specification

What are the consequences of returning a reference to the bag array in the toArray method?

-the return variable is an alias for the private instance array variable -the client will have direct access to the private instance array variable -the client could change the contents of the private instance array variable without using the public access methods

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

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..."?

0

How many objects are created in the following declaration? String name;

0

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

0

What does the following Java code print? int sum=0; for (int i=0; i>100; i++) { sum += i; } System.out.println(sum);

0

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

Assume that we have a Link class reference named head and named q that point to Link nodes as follows: head -> 5 -> 10 (q) -> 15 -> 20 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

What does the following Java code print: int sum=0; for (int j=0; j<3; j++) { for (int i=0; i<4; i++) { sum += 1; } } System.out.println(sum);

12

What does the following Java code print? int sum=0; for (int i=0; i<10; i+=4) { sum += i; } System.out.println(sum);

12

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

Imagine a class named Club, to be a member a person must be aged 15 or older, but less than50. What values would you use to boundary test a method designed to check if aperson was a suitable age to join?

14, 15, 49, 50

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

What does the following Java code print? int sum=0; for (int i=1; i<=5; i++) { sum += i; } System.out.println(sum);

15

In Java, what value will the variable i have after this declaration: int i = 2 + 8 % 4;

2

How many objects and object references would we have if the following code is executed? Student first_st = new Student(); Student second_st = new Student(); Student third_st = second_st;

2 objects, 3 references

Consider the Date class: class Date { int year, month, day; public Date() { this.year = 1983; this.month = 9; this.day = 3;} public void setDate(int month, int day, int year) { this.year = year; this.month = month; this.day = day; } public void print() { System.out.println(month + "/" + day + "/" + year);}} What is the output from the following code snippet? Date dueDate = new Date();dueDate.setDate(5, 20, 1980);Date expirationDate = dueDate;expirationDate.setDate(2, 28, 1989);dueDate.print();

2/28/1989

Trace the following method given graduationYear = 1984 and currYear =2020. What does nextReunion() return? public int nextReunion() { int yearDiff = currYear - graduationYear; if (yearDiff <= 0) return currYear + (5 - yearDiff); else return currYear + (5 - (yearDiff % 5));}

2024

Trace the following method given graduationYear = 2020 and currYear =2020. What does nextReunion() return? public int nextReunion() { int yearDiff = currYear - graduationYear; if (yearDiff <= 0) return currYear + (5 - yearDiff); else return currYear + (5 - (yearDiff % 5));}

2025

Trace the following method given graduationYear = 2022 and currYear =2020. What does nextReunion() return? public int nextReunion() { int yearDiff = currYear - graduationYear; if (yearDiff <= 0) return currYear + (5 - yearDiff); else return currYear + (5 - (yearDiff % 5));}

2027

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

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

In the Java language, what is the value of this expression? 8 / 5 + 3.2

4.2

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

Consider the following: When foo is executed, what is printed out? public void foo () { int x = 42; int y = 24; mystery (x, y); System.out.println (x + " " + y); } public void mystery (int var1, int var2) { int temp = var1; var1 = var2; var2 = temp;}

42 24

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

What will be printed by this code? public static void main(String [] args){ int number = 6; int secondNumber = changeNumber (number); System.out.print(number + " " + secondNumber); } public static int changeNumber(int number){ number = 12; return number; }

6 12

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

7

What will be the outputted? class A{ int firstMethod(int input){ return input*2;}} class B extends A{ int firstMethod(int input){ super.firstMethod(input); return input*2;}} class C extends B{ int firstMethod(int input){ return super.firstMethod(input)* 2;}} public class test { public static void main(String[] arg){C myObject = new C(); System.out.println(myObject.firstMethod(2));}}

8

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 CloneNotSpportedException will be thrown

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

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

int income = 30; boolean condition1 = true, condition2 = true; if(income < 100) if(income > 10) if(condition1){ System.out.print("A"); if(income<20) System.out.print("B"); }else System.out.print("C"); if(!condition2){ if(income>50) System.out.print("D"); }else{ System.out.print("E");}

AE

Based on the demonstrated implementation of LinkedBag1. What is the output of the following code? LinkedBag1 bag; bag = new LinkedBag1(); bag.add("Alisha"); bag.add("Ashley"); bag.add("Ariel"); System.out.println(bag.toArray(new String[25])[0]);

Ariel

Which of the following is more restrictive? ArrayList<Integer> myList; or ArrayList<? super Integer> myList;

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

Where does new data get added to this linked implementation of a bag?

Beginning

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

Between bicep curls and burpees

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.

Binary Search O worst case

Binary search takes (log n) time, worst case.

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

Bubble sort

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

Given an array of doubles named values, what does the following code do: double total = 0; for(double element : values) { total = total + element; } double average = 0; if (values.length > 0) { average = total/values.length; }

Calculates the sum and average of the values

Which of these relationships best exemplify the "IS-A" relationships in object-oriented programming (OOP)?

Cat IS-A mammal

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

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

Confidentiality

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

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

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

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

False

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

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

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

What is usually an advantage of using a chain to implement the ADT bag?

It avoids moving data when adding or removing bag entries.

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

It ensures that all the members of the collection are objects related by inheritance.

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.

What is the primary risk of implementing a SortedList by inheriting from the List class?

Methods like add(newPosition, newEntry) and replace(givenPosition, newEntry) would be inherited, client code can use these methods in a manner that affects the sorted order

Implementing SortedLists using the class definition below would result in which of the following? public class MySortedList> extends MyList implements SortedListInterface

MySortedList would inherit all of the methods from MyList, methods unique to the SortedListInterface would need to be implemented

If a variable myObj is declared as type GeneralCase and assigned an instance of a subclass of GeneralCase, SpecificCase: GeneralCase myObj = new SpecificCase(); Can myObj be used to call a method that is defined for SpecificCase but not GeneralCase?

No

If a variable myObj is declared as type GeneralCase and assigned an instance of a subclass of GeneralCase, SpecificCase: GeneralCase myObj = new SpecificCase(); If yourObj is declared as a variable of type SpecificCase can it be assigned to myObj with the statement: yourObj = myObj;

No

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

No

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

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

O( n log n)

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

O(1)

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)

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)

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)

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)

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

O(logn)

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)

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

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 big O 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]; }}}

O(n^2)

What is the big O 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]; }}}

O(n^3)

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++){ for (int k = 1; k <= n; k++){ System.out.print(i * j * k);}}}

O(n^3)

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

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

Why is the method signature for the equals method in a Hokie class: public boolean equals(Object obj)?

So that it overrides the equals method defined for the Object class

The benefit of using sentinel nodes

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

If a variable myObj is declared as type GeneralCase and assigned an instance of a subclass of GeneralCase, SpecificCase: GeneralCase myObj = new SpecificCase(); If myObj is used to call a method total() that is implemented in GeneralCase and SpecificCase, which version gets called?

SpecificCase

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

Which of the following recommendations for testing software is good advice?

Test each piece of your solution as you build it, so you will find errors as quickly as possible.

why a SortedList implementation would not need the method, add(int newPosition, T newEntry)?

The SortedList add(newEntry) method has the responsibility of adding new entries in sorted order, as a result Client code would no longer be required to, or be allowed to, specify the location of the new entries by using add(int newPosition, T newEntry).

public class RecursiveMath ... public int fib (int a) { if (a == 1) return 1; else return fib(a-1) + fib(a-2); } ... } RecursiveMath bill = new RecursiveMath(); int x = bill.fib(-1);

The code does not terminate

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

The scope of a variable in Java is:

The part of the program in which it can be used

What is the main benefit of implementing a SortedList by inheriting from a revised List Base class instead of inheriting from the standard List Base class?

The revised List Base class can be set up so that unwanted methods - like add(newPosition, newEntry) and replace(givenPosition, newEntry) - cannot be inherited by subclasses

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

A ListIterator provides a superset of the functionality that an Iterator provides.

True

A class that implements Iterator will have a compile time error if it does not implement a remove method

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.

True

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

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

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.

True

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

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

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.

When adding an item to a bag, which of the following statements are true?

You cannot specify the position of the item in the bag.

Suppose you are writing a method in a new class. You are also writing unit test cases to demonstrate that this method works correctly. You know you have written enough test cases to demonstrate the method works as desired when?

You have written separate test cases for each identifiable "group" of input values and/or output values where the behavior is expected to be similar.

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

[3 4], [3 7], [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

Suppose you are writing a program for a robot that will go around a building and clean the floor. Your program will contain, among other things, a Robot class and a Building class (with information about the layout of the building). The Building class is also used in a different program for scheduling maintenance of various parts of the building. The relationship between your Robot class and your Building class is best modeled as:

a peer relationship

Consider the equals() method of the Employee class (depicted below) then select the answer which best completes the following statement: StatementOmitting or removing line 4 from the equals() method if (obj == null) return false; would create _____ that could be exploited by malicious client code. 1 @Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null) return false; if (this.getClass() == obj.getClass()) { Employee other = (Employee) obj; return name.equals(other.name) && address.equals(other.address); } else { return false; } }

a vulnerability

Select which to use based on the information given: If several classes have identical methods and a few methods that need to be implemented differently.

abstract class

A set is an abstract data type that is similar to a bag. It is also unordered, but it does not allow duplicates. Examples of sets would be even integers or a collection of the movies you have previously seen. Which bag behavior would need to be modified for a set?

add

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

add (T newEntry)

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

add()

Which behavior(s) change the contents of a bag?

add()

Which of the following is usually an advantage of using an array to implement the ADT bag?

adding an entry to a bag is fast

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

A method with the header public static double getMax(Iterable<price> prices) can be called with a parameter that is:

any type that implements Iterable

Assume we have a null variable foo. Which is the correct way to use assert statements when writing junit tests with student.TestCase?

assertNull(foo);

When testing a method that returns a boolean, what assert statements should you use?

assertTrue or assertFalse

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

at the front

Where does a queue add new items?

back

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

The fact that an iterator keeps its place within a list is a

benefit because it saves work and improves efficiency

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?

bicep curls

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?

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

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

Which method removes all entries of a bag?

clear()

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

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

What will be outputted? int num = 3; int counter = 1; boolean condition = true; while(condition){ num+= counter++; if(num>10){ condition=false; num+= ++counter;}}

counter = 5 num = 17

What are the two fields of a Node?

data and next

encapsulation

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

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

Given that a linked chain exists in memory as represented by the following: firstNode -> "A" -> "B" -> "C" -> "D" 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.next; lastNode.next = p; r = p.next; r.prev = null; p.next = firstNode; p.prev = lastNode; firsNode.next = null; firstNode.prev = p; lastNode = firstNode; firstNode = r; Which of the linked chains below would result: Hint: draw a diagram of the list to execute the code upon.

firstNode → "S" ⇄ "I" ⇄ "G" ⇄ "N" ⇄ "E" ⇄ "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

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

Which method returns a count of the current number of items in a bag?

getCurrentSize()

A reference to the first node in a linked list is called the _____ reference.

head

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? Link head = new Link("A", null); head.next = new Link("C", new Link("B", null)); Link p = head.next; head.next = new Link("F", p); Link q = head; Link temp = head.next.next; temp.next = new Link("Z", null);

head -> A ->F -> C -> Z

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? Link head = new Link("R", null); head.next = new Link("A", new Link("T", null)); Link c = head.next.next; head.next = new Link("D", c);

head -> R -> D -> T

Given a Node<T> class with constructors Node(T data, Node next) and Node(T data), and the code below, select the resulting list pointed to by head: Node a = new Node("R"); Node b = new Node("S", a); Node d = new Node("T", b); Node c = new Node("U", d); Node head = c;

head -> U->T->S->R

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? Link head = new Link("K", null); head.next = new Link("D", new Link("R", null)); head.next.next.next = new Link("F", null); Link c = head; head = c.next; head.next.next.next = c; c.next = null;

head ->D->R->F->K

An enhanced for statement can only be use on data structures that

implement Iterable

Root

in a tree, the topmost node of the tree

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

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

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] + " "); }

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

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.getNext() != 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 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

Which method is in the ArrayBag class is overloaded?

remove

The dequeue operation:

removes and returns the item at the front of a queue

The method remove that has no parameter in the linked implementation

removes the first element in the chain

The fixed array implementation of the method remove that has no parameter in the bag

removes the last entry in the array

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

Which behavior is not represented in a bag?

reorder the bag

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

What does a primitive type represent?

simple indecomposable values

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 incomplete definition of a method is called a _____.

stub

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

edge

the connection that links two nodes

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

When using a local variable that has the same name as a field what is outputted when this is called? this.x

the field variable

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

In Java, what word is used to refer to the current object, or to call one constructor from another in the same class?

this

Which of these Java keywords can be used to intentionally cause an exception?

throw

When an exception occurs within a method, the method creates an Exception object then hands it off to the Java runtime system to take further action, this is referred to as

throwing an exception

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


Kaugnay na mga set ng pag-aaral

The Child with a Metabolic Condition Chapter 31

View Set

OLE MISS | Bisc 103 - Exam 3 - Chapter 24

View Set

More Data Structures and algorithms interview questions

View Set

American Government Unit 1 Study Guide

View Set

Unit Circle- Evaluating Trig Functions Of Degree Angles

View Set

Marketing Research Test Review Questions #1

View Set

Acute Kidney Injury and Chronic Kidney Disease (Ch. 34)

View Set

Ch. 15: Labor Relations and Collective Bargaining

View Set

fundamentals of business, marketing, and finance midterm review

View Set

ADV. MED SURGE Exam 4 (ch 32-40)

View Set

Biology 1409 - Lab Exam 2 - Lesson 6 through 13

View Set