CS final Flashcards

1
Q

Which can cause the actions of the setUp() method to not be reflected at the start of each test class:

Initialized variables were changed in one of

the test methods

the variables initialized in setUp were also declared locally within setUp

if a tearDown() method is used

none- the actions of the setUp() method happen only once

A

Correct answer:

the variables initialized in setUp were also declared locally within setUp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write a test method that will cover every case of the following method

public Hokie createHokie(String name) {

if (name.equals(“”)) {

return null;

}

return new Hokie(name);

}

public void testCreateHokie(){ assertNull(createHokie(“”)); assertNull(!createHokie(“Hannah”);}

public void testCreateHokie(){ assertEquals(null,createHokie(“”)); assertNotEquals(“Hannah”,createHokie(“Hannah”);}

public void testCreateHokie(){ assertNull(createHokie(“”)); assertNotNull(createHokie(“Hannah”);}

public void testCreateHokie(){ assertEquals(null,createHokie(“”)); assertEquals(“Hannah”,createHokie(“Hannah”);}

A

public void testCreateHokie(){ assertNull(createHokie(“”)); assertNotNull(createHokie(“Hannah”);}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What code would you use to test if the sum() method of the MyCalculator class is throwing the correct exception?

public int sum(String num1String, String num2String) {

int sum = 0;

try {

int num1 = Integer.parseInt(num1String);

int num2 = Integer.parseInt(num2String);

sum = num1 + num2;

}

catch (NumberFormatException nfe) {

throw new NumberFormatException();

}

return (sum);

}

}

NumberFormatException myNFE = null;

try {

calc.sum(“2hello”, “3”);

}

catch (NumberFormatException nfe) {

nfe = myNfe;

}

assertNotNull(myNFE);

NumberFormatException myNFE = null;

try {

calc.sum(“2”, “0”);

}

catch (NumberFormatException nfe) {

myNFE = nfe;

}

assertNotNull(myNFE);

ArithmeticException myAE = null;

try {

calc.sum(“2”, “0”);

}

catch (ArithmeticException ae) {

myAE = ae;

}

assertNotNull(ae);

NumberFormatException myNFE = null;

try {

calc.sum(“2hello”, “3”);

}

catch (NumberFormatException nfe) {

myNFE = nfe;

}

assertNotNull(myNFE);

A

NumberFormatException myNFE = null;

try {

calc.sum(“2hello”, “3”);

}

catch (NumberFormatException nfe) {

myNFE = nfe;

}

assertNotNull(myNFE);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Consider the Movie class:

class Movie {

String genre, title;

int year;

public Movie() {

}

public void setMovie(String title, String genre, int year)

{

this.title = title;

this.genre = genre;

this.year = year;

}

public void setYear(int year)

{

this.year = year;

}

public void print() {

System.out.println(title + “ “ + genre + “ movie in “ + year);

}

}

What is the output from the following code snippet?

Movie recentFilm = new Movie();

recentFilm.setMovie(“The Little Mermaid”, “musical”, 2023);

Movie classicFilm = recentFilm;

classicFilm.setYear(1989);

recentFilm.print();

The Little Mermaid musical movie in 2023

The Little Mermaid musical movie in 1989

The Little Mermaid musical movie in 1989, 2023

The Little Mermaid musical movie in 1989 2023

A

The Little Mermaid musical movie in 1989

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The simplified UML diagram above shows the relationships among Java classes Bird, Crow, and Duck.

Suppose Bird has a land(Location place) method, but we want Ducks to makeSplash() just after they land and then behave like other Birds. Assuming Ducks have a makeSplash() method, we should

Group of answer choices

Define a land method in Duck that just consists of makeSplash(), i.e.

public void land(Location place) {

this.makeSplash();

}

, Not Selected

Define a land method in Duck by copying the land code from Bird then adding in makeSplash() at the start, i.e.

public void land(Location place) {

// [paste the body of Bird’s land method here]

this.makeSplash();

}

Define a land method in Duck that just consists of makeSplash() and Bird.land(place); i.e.

public void land(Location place) {

Bird.land(place);

this.makeSplash();

}

Define a land method in Duck that just consists of makeSplash() and super.land(place)

public void land(Location place) {

super.land(place);

this.makeSplash();

}

Define a land method in Duck that just consists of makeSplash() and this.land(place), i.e.

public void land(Location place) {

this.land(place);

this.makeSplash();
A

Define a land method in Duck that just consists of makeSplash() and super.land(place)

public void land(Location place) {

super.land(place);

this.makeSplash();

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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 workComputer = new Computer(“Acme”, “Intel”, 2, 160, 2.4);

Notebook yourComputer = new Notebook(“DellGate”, “AMD”, 4, 240, 1.8, 15.0, 7.5);

Which line of code doesn’t compile?
yourComputer .getRamSize();

workComputer.getScreenSize();

yourComputer .getScreenSize();

workComputer.getRamSize();

A

workComputer.getScreenSize();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Suppose you have an array of seven int values called test containing the following array:

{8, 14, 0,12, 10,9,20}

Trace the execution of the following code:

int x = 0;
int y = 0;
for (int i = 0; i < test.length; i++)
{
if (test[i] % 4 == 0)
{
x++;
y += test[i];
}
}

What is the value of x when this loop is done?
35

3

40

7

4

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Given the following code:

for (int i=0; i < values.length; i++) {
if (values[i] == searchedValue){
found = true;
} else {
found = false;
}
}
if (found) {
System.out.println(“found “ + searchedValue);
} else {
System.out.println (“not found”);
}

If the initial values are:

int[] values = { 3, 6, 10, 12, 100, 200, 250, 500 };
int searchedValue = 10;
boolean found = false;
What is output?

not found

found 10

A

not found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

It allows the data type to be determined later by the client of the class.

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

It can contain objects of type OrderedPair.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

for (int i=0; i < values.length; i++) {
if (values[i] == searchedValue){
found = true;
} else {
found = false;
}
}
if (found) {
System.out.println(“found “ + searchedValue);
} else {
System.out.println (“not found”);
}

If the initial values are:

int[] values = { 3, 6, 10, 12, 100, 200, 250, 500 };
int searchedValue = 250;
boolean found = false;
What is output?

not found

found 250

A

not found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

For an ArrayBag when would the add method return false?

when there was not a duplicate of the entry already in the bag

when addition of a new item was successful

when the addition of a new item was not successful

when there was a duplicate of the entry already in the bag

A

when the addition of a new item was not successful

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A fixed size array

can waste memory

has a limited capacity

all of these

prevents expansion when the bag becomes full

A

all of these

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

contains()

add()

toArray()

getFrequencyOf()

A

add()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which of the following 5 implementations could not be used for contains in and ArrayBag as implemented in the course?

public boolean contains(T anEntry)
{
int i = 0;
while ((i <= numberOfEntries - 1))
{
if (anEntry.equals(contents[i]))
{
return true;
}
i++;
}
return false;
}

public boolean contains(T anEntry)
{
int i = 0;
while ((i <= numberOfEntries))
{
if (anEntry.equals(contents[i]))
{
return true;
}
i++;
}
return false;
}

public boolean contains(T anEntry)
{
return getFrequencyOf(anEntry) > 0;
}

public boolean contains(T anEntry)
{
boolean found = false;
int i = 0;
while ( !found && (i < numberOfEntries))
{
if (anEntry.equals(contents[i]))
{
found = true;
}
i++;
}
return found;
}

public boolean contains(T anEntry)
{
return getIndexOf(anEntry) > -1;
}

A

public boolean contains(T anEntry)
{
int i = 0;
while ((i <= numberOfEntries))
{
if (anEntry.equals(contents[i]))
{
return true;
}
i++;
}
return false;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which of the following 5 implementations could not be used for getFrequency?

public int getFrequencyOf(T anEntry)
{
int i = 0;
int count = 0;
while( i < numberOfEntries)
{
if(anEntry.equals(contents[i]))
{
count++;
}
i++;
}
return count;
}

public int getFrequencyOf(T anEntry)
{
int count = 0;
for(int i = 0; i < numberOfEntries; i++)
{
if(anEntry.equals(contents[i]))
{
count++;
}
}
return count;
}

public int getFrequencyOf(T anEntry)
{
int count = 0;
for(int i = numberOfEntries - 1; i >= 0; i–)
{
if(anEntry.equals(contents[i]))
{
count++;
}
}
return count;
}

public int getFrequencyOf(T anEntry)
{
int count = 0;
for(int i = numberOfEntries - 1; i > -1; i–)
{
if(anEntry.equals(contents[i]))
{
count++;
}
}
return count;
}

public int getFrequencyOf(T anEntry)
{
int i = 0;
int count = 0;
while(anEntry.equals(contents[i]))
{
i++;
count++;
}
return numberOfEntries - count;
}

A

public int getFrequencyOf(T anEntry)
{
int i = 0;
int count = 0;
while(anEntry.equals(contents[i]))
{
i++;
count++;
}
return numberOfEntries - count;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The most efficient approach to dealing with a gap left in an array after removing an entry from a bag to correspond with the approaches used in this course, would be to

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

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

shift subsequent entries and replace the duplicate reference to the last entry with null

replace the entry being removed with null

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Which of the following would not be an alternate way to write remove() method for an ArrayBag as implemented in the course

public T remove()
{
T result = null;
if (numberOfEntries > 0)
{
result = contents[numberOfEntries -1];
contents[numberOfEntries - 1] = null;
numberOfEntries–;
}
return result;
}

public T remove()

{
int lastEntry = numberOfEntries-1
return removeEntry(lastEntry);
}

public T remove()
{
T result = removeEntry(numberOfEntries-1);
return result;
}

public T remove()
{
T result = removeEntry(getIndexOf(null));
return result;

}

A

public T remove()
{
T result = removeEntry(getIndexOf(null));
return result;

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Which method removes all entries of a bag?

remove()

none of these

clear()

delete()

A

clear()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Which of the following would be a way to write remove() method for an ArrayBag?

private T removeEntry(int givenIndex)

{

    T result = null;

    if (!isEmpty() && (givenIndex >= 0))

    {

        result = contents[givenIndex];

        contents[givenIndex] = contents[numberOfEntries - 1];

        contents[numberOfEntries - 1] = null;

        numberOfEntries--;

    }

               return result;

}

public T remove()

{

T result = removeEntry(getIndexOf(null));

return result;

}

public T remove()

{

T result = null;

if (numberOfEntries > 0)

{

    contents[numberOfEntries - 1] = null;

    numberOfEntries--;

}

return result;

}

public T remove()

{

T result = removeEntry(numberOfEntries-1);

return result;

}

public T remove()

{

return removeEntry(numberOfEntries--);

}

A

public T remove()

{

T result = removeEntry(numberOfEntries-1);

return result;

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Given:

class Link {

public Link next; //Point to next node in list

public Object data; //Value for this node

//Constructors

public Link(Object dataIn, Link nextIn) {

this.data = dataIn;

this.next = nextIn;

}

public Link(Link nextIn) {

this.data = null;

this.next = nextIn;

}

Object getData() { // Return the data field

return data;

}

void setData(Object newData) { // Set the data field

data = newData;

}

Link getNext() { // Return the next field

return next;

}

void setNext(Link newNext) { // Set the next field

next = newNext;

}

}

Given a linked chain of Integers reference by the variable head which contains data 20, 30, 10, 5 in that order. Consider the impact of the execution of the following lines of code:

Link p = head;

Link q = head.next;

Link r = q.next;

Integer myVal = q.data

What is the value of r.data?

20

5

30

10

A

10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Given:

Link head = new Link(null);

head.data = new Integer(20);

head.next = new Link(new Integer(30), null);

head.next.next = new Link(new Integer(10), null);

Link temp = head.next.next;

Which line of code would add another node to the end of the chain?

temp.data = new Link(new Integer(45), null);

temp.next.next = new Link(new Integer(45), null);

temp.next.data = new Link(new Integer(45), null);

temp = new Link(new Integer(45), null);

temp.next = new Link(new Integer(45), null);

A

temp.next = new Link(new Integer(45), null);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Given:

Link head = new Link(null);

head.data = new Integer(10);

head.next = new Link(new Integer(5), null);

head.next.next = new Link(new Integer(20), null);

Link temp = head.next.next;

temp.next = new Link(new Integer(30), null);

What would the linked chain look like if the following code was executed next?

temp.next.next = head;

head.next = null;

head = temp;

Head -> 10 ->5 -> 20

Head -> 20 ->30 -> 10

Head -> 10 ->5 -> 20 -> 30

Head -> 20 ->30 -> 10 -> 5

A

Head -> 20 ->30 -> 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

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 ->K->D->R->F

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

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

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

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

while (curr.next != null)

    Link curr = head.next;

    curr = curr.next;

Link curr = head.next;

while (curr != null)

       curr = curr.next;

while (curr != null)

     Link curr = head;

     curr = curr.next;

while (curr.next != null)

    Link curr = head;

    curr = curr.next;

Link curr = head;

while (curr != null)

       curr = curr.next;
A

Link curr = head;

while (curr != null)

       curr = curr.next;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

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

while (curr.next != null)

    Link curr = head;

     curr = curr.next;

Link curr = head;

while (curr != null)

       curr = curr.next;

Link curr = head.next;

while (curr != null)

       curr = curr.next;

While (curr != null)

     Link curr = head;

      curr = curr.next;

while (curr != null)

    Link curr = head.next;

    curr = curr.next;
A

Link curr = head.next;

while (curr != null)

       curr = curr.next;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

The efficient version of the remove method that has no parameter in the linked implementation of a bag

removes a random element in the chain

removes the last element in the chain

none of these

removes the first element in the chain

A

removes the first element in the chain

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What does the”new” operator do in the following code from the LinkedBag add method:

Node newNode = new Node(newEntry);

all of these

a new node is created

a new object is instantiated

the JRE allocates memory for a node object

A

all of these

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Which of the following is true about the following code:

Node newNode;

newNode.data = newEntry;

It causes an exception

a new object is instantiated

a new node is created

the JRE allocates memory for a node object

A

It causes an exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

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

O(1)

O(n^2)

Negligible

O(n)

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

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

O(n)

O(n^2)

negligible

O(1)

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

For large values of n which statement is true?

(1000 n ) / 2 behaves like n^2

(1000 n ) / 2 behaves like n

all of these

(1000 n ) / 2 behaves like 500

A

(1000 n ) / 2 behaves like n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

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.push(“P”);

stack.push(“G”);

stack.push(“R”);

String str = stack.pop();

stack.pop();

stack.push(“V”);

stack.push(str);

P V G P

G V P K

K P V R

R V P K

A

R V P K

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

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

O(1)

O(n^2)

O(n)

O(logn)

A

Correct answer:

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

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

O(1)

O(n)

O(n^2)

O(logn)

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

In the course array-based implementation of a Stack ADT, the last entry in the the array is

Always the top of the stack

One slot after the bottom of the stack

One slot afer the top of the stack

Always the bottom of the stack

A

Always the top of the stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

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

the second to last node in the chain will now be the top

the original first node in the chain will no longer be referenced

all of these

the original first node in the chain will have a new value

A

Correct answer:

the original first node in the chain will no longer be referenced

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

In the course linked-chain implementation of a StackADT, when a node is pushed onto the stack

the original first node will no longer be referenced

the original first node will now be the second node

the original first node will have a new value

the second to last node will now be the top

A

Correct answer:

the original first node will now be the second node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

In the course linked-chain implementation of a StackADT, the efficiency of push and pop

Is better for push

Is better for pop

Depends on n

Is the same

A

is the same

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Consider the design of a system used to track and manage the items in a library.

From discussions with librarians and other stakeholders you identified the following possible classes and fields.

Book

Fields of the Book class: library ID, name, description, data of acquisition, status, title, ISBN, category, authors, publisher, publication date

DVD

Fields of the DVD class: library ID, name, description, data of acquisition, status, title, actors, directors, genre, rating, length

Recognizing that Books, DVDs, and other forms of library media all contain similar pieces of data/information that must be tracked and managed, you decide to create a Media class (see below) and use inheritance since it improves code re-usability.

Media

Fields of the Media class: library ID, name, description, data of acquisition, status

Which would be the most appropriate way to utilize inheritance within your UML design?

Book as a superclass, with Movie as a subclass of Book, and Media as a standalone class

Media, Book, and Movie each as standalone class (not related by inheritance)

Movie as a superclass, with Book as a subclass of Movie, and Media as a standalone class

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Consider the design of a system used to track and manage items in a running store.

From discussions with the owner and other stakeholders you identified the following possible classes and fields.

Fields of the Product class: product ID, name, price, size

Shoes: product ID, name, price, size, gender, width, brand, purpose

Clothes: product ID, name, price, size, gender, category, season

Which would be the most appropriate way to utilize inheritance within your UML design?

Item as a superclass, with Clothes as a subclass of Item, and Shoes as a standalone class

Clothes as a superclass, with Shoes as a subclass of Clothes, and Product as a standalone class

Product as a subclass, with Clothes and Shoes as superclasses of Product

Product as a superclass, with Clothes and Shoes as subclasses of Product

Dog, Reptile, and Product each as standalone class (not related by inheritance)

A

Correct answer:

Product as a superclass, with Clothes and Shoes as subclasses of Product

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Consider the design of a system used to track and manage students at a university.

From discussions with administrators and other stakeholders you identified the following possible classes and fields.

Student

Fields of the Student class: student ID, name, gender, race, ethnicity, full-time status, GPA

Undergraduate student: student ID, name, gender, race, ethnicity, full-time status, GPA, majors, minors, hours completed

Graduate student: student ID, name, gender, race, ethnicity, full-time status,GPA, department, advisor, degree pursuing

Which would be the most appropriate way to utilize inheritance within your UML design?

Student as a subclass, with Undergraduate STudent and Graduate student as superclasses of Student

Student as a superclass, with Undergraduate student as a subclass of Student, and Graduate Student as a standalone class

Graduate Student as a superclass, with Student as a subclass of Graduate Student, and Undergraduate as a standalone class

Student, Undergraduate student, and Graduate student each as standalone class (not related by inheritance)

Student as a superclass, with Undergraduate Student and Graduate Student as subclasses of Student

A

Student as a superclass, with Undergraduate Student and Graduate Student as subclasses of Student

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Which of the following could be considered an example of a non-functional requirement for this scenario?

The system shall allow users to search for a product item

The system shall notify users when an item has been successfully added to the shopping cart

The system shall process and complete user-submitted requests within 10 seconds

The system shall allow ABC support staff to look up an order

The system shall allow registered customers to place an order

The system shall allow users to add an item to the shopping cart

A

The system shall process and complete user-submitted requests within 10 seconds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

(Select all which apply)

The Employee Management System shall…

Support the tracking and management of a minimum of 100,000 employee records

Allow authorized users to search for an employee record

Allow employee users to submit a vacation\leave application

Allow authorized users to add, view, and modify an employee record

Complete user-initiated requests within 3 seconds when the number of simultaneous users are > 500 but < 1000

A

Allow authorized users to search for an employee record

Allow employee users to submit a vacation\leave application

Allow authorized users to add, view, and modify an employee record

41
Q

Your organization’s online services have recently been hit by a flurry of Denial of Service attacks. Denial of Service attacks occur when an attacker, or attackers, attempt to make a computing device, service, or network resource unavailable to users. Attacks may flood a server or resource with fake service requests to overload systems in order to prevent legitimate requests from being fulfilled. Analysis of the attacks suggests that you are dealing with a Distributed DOS (DDOS), where requests are sent from many machines, for example Botnets are zombie computers that receive/execute remote commands without the owner’s knowledge.

Your team is attempting to determine an appropriate course of action. One approach is to maintain a Blacklist/Whitelist in which access from blacklisted addresses (individual machines, networks or even whole countries) is prevented and access from whitelisted addresses is always allowed.

Using the 8 Key questions you must consider if permanently blacklisting is an ethical solution.

Which question would be the least helpful in determining if permanently blacklisting certain addresses is an ethical course of action?

Fairness

Cost

Outcomes

Responsibilities

Liberty

A

Cost

42
Q

You are the DevOps Manager for a financial organization. Your role authorizes you access to the development, testing, and production environments as well as customer financial data.

Going to work one day you notice a news headline describing a scandal implicating a celebrity of financial fraud, a celebrity who happens to be a customer of the financial organization you work for. Your curiosity is piqued and you wonder if the allegations are true.

Which ethical principle could possibly be violated if you give in to curiosity and look at the customer’s financial information?

Choose the ACM Ethical Principle that BEST applies

1.6 Respect privacy.

1.3 Be honest and trustworthy.

1.7 Honor confidentiality.

A

1.6 Respect privacy.

43
Q

You are the DevOps Manager for a financial organization. Your role authorizes you access to the development, testing, and production environments as well as customer financial data.

Going to work one day you notice a news headline describing a scandal implicating a celebrity of financial fraud, a celebrity who happens to be a customer of the financial organization you work for. Your curiosity is piqued and you wonder if the allegations are true.

Which ethical principle could possibly be violated if you give in to curiosity and look at the customer’s financial information?

Choose the ACM Ethical Principle that BEST applies

2.8 Access computing and communication resources only when authorized or when compelled by the public good.

1.7 Honor confidentiality.

2.1 Strive to achieve high quality in both the processes and products of professional work.

A

2.1 Strive to achieve high quality in both the processes and products of professional work.

44
Q

A software bug resulted in incorrect calculations being applied to 100 account holder’s financial data during a batch processing job. The organization’s directors have requested that this be rectified as soon as possible. You need to advise your development team of the correct course of action.

Which of the following would be the LEAST ethical approach to correcting the financial data for each of the affected accounts?

Reversing the batch processing job, updating the software to fix the bug, then running the batch processing job again

Directly interacting with the backend (database/data repository) to make changes, manually retrieving each account and updating the records by keyboard entry

Writing a script to programmatically fix the affected accounts, with the script utilizing the code and methods typically used for the relevant financial operations, and with the code updated to remove the bug

A

Directly interacting with the backend (database/data repository) to make changes, manually retrieving each account and updating the records by keyboard entry

45
Q

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)

Infinite recursion

15

25

125

1

A

125

46
Q

Given the following code:

public void countDown(int leadTime, String message)

        {

                    System.out.println(leadTime + "...");

                    if (leadTime < 5)

                               countDown(leadTime + 1, message);

                    else

                               System.out.println(message);

          }

If client code calls countDown(0,”GAMEOVER”), what is the order of the subsequent method calls?

countDown(4,”GAMEOVER”), countDown(3,”GAMEOVER”), countDown(2,”GAMEOVER”), countDown(1,”GAMEOVER”)

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

countDown(1,”GAMEOVER”), countDown(2,”GAMEOVER”), countDown(3,”GAMEOVER”), countDown(4,”GAMEOVER”)

countDown(1,”GAMEOVER”), countDown(2,”GAMEOVER”), countDown(3,”GAMEOVER”), countDown(4,”GAMEOVER”), countDown(5,”GAMEOVER”)

A

countDown(1,”GAMEOVER”), countDown(2,”GAMEOVER”), countDown(3,”GAMEOVER”), countDown(4,”GAMEOVER”), countDown(5,”GAMEOVER”)

47
Q

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 the private helper member method would print a non-empty chain

In order

Neither

In reverse order

A

Correct answer:

In reverse order

48
Q

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 the private helper member method would print a non-empty chain

Neither

In order

In reverse order

A

Correct answer:

In order

49
Q

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

        displayChain(curr.getNext());

}

Indicate how the private helper member method would print a non-empty chain

In reverse order

In order

Neither

A

Neither

50
Q

Given the following code:

public static void displayArray(int[] array, int first, int last)
{
if (first == last)
System.out.print(array[first] + “ “);
else
{
int mid = (first + last) /2;
displayArray(array, first, mid);
displayArray(array, mid + 1, last);
}
}

With the call displayArray ({4,5,6,7,8,9,10,11},0,7), how many recursive calls would be made?

14

22

7

3

A

14

51
Q

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

1

16

None of these

136

A

136

52
Q

How many times will F be called if n = 4, ignoring F(4) itself?

public static long F(int n) {

if (n == 0)return 0;

if (n == 1) return 1;

return F(n-1) + F(n-2);

}

12

8

14

9

A

8

53
Q

public class RecursiveMath

public int fib (int a) {

  if (a >= 2)

     return fib(a-1) + fib(a-2); 

   return a;

}

}

What is the base case for fib in the above definition?

fib(a) for a < 2

fib(a-1) + fib(a-2);

None of these

int a

fib(a) for a >= 2

A

fib(a) for a < 2

54
Q

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

None of these

x is set to undefined

The code does not terminate

x is set to -1

The code cannot be executed, because it won’t compile

A

The code does not terminate

55
Q

Suppose q is an instance of a queue that can store Strings, and and q is initially empty:

q.enqueue(“Sweden”);

q.enqueue(“is”);

q.enqueue(“my”);

String w = q.dequeue();

String x = q.peek();

q.enqueue(“neighbor”);

String y = q.dequeue();

String z = q.dequeue();

What is the value of z after executing these expressions in order?

“Sweden”

“neighbor”

none of these

“my”

“is”

A

“my”

56
Q

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

a hundred names in alphabetical order, where names are added and removed frequently

The undo operation in a word processor

the back button in a web browser

the customers waiting to chat with an online banking agent

the railway system

A

the customers waiting to chat with an online banking agent

57
Q

What item is at the front of the deque after these statements are executed?

DequeInterface waitingLine = new LinkedDeque();

waitingLine.addToFront(“Piper”);

waitingLine.addToBack(“Cedar”);

waitingLine.addToBack(“Wren”);

waitingLine.addToFront(“Fawn”);

String name = waitingLine.removeFront();

Cedar

Wren

Fawn

Piper

A

Piper

58
Q

Based on the deque class shown in the course videos and 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 an empty deque

removing from a full deque

removing from a deque with one item

removing from a deque with items only at the front

A

removing from a deque with one item

59
Q

Based on the deque class shown in the course videos and 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 in the DLNode constructor, what will the prev field of the node containing “Jeep Wrangler” reference?

lastNode

firstNode and lastNode

firstNode

Null

A

Null

60
Q

Which of the following would not correctly complete the isEmpty() method for a doubly linked implementation of a deque in all cases

Public boolean isEmpty()

{

return < fill in code here >;

}

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

(firstNode == null)

(firstNode == lastNode)

(lastNode == null)

A

Correct answer:

(firstNode == lastNode)

61
Q

Based on the deque class shown in the course videos, what does this code most likely do:

firstNode = firstNode.getNext();

if (firstNode == null)

  lastNode = null;

else

  firstNode.setPreviousNode(null);

Iterates through a doubly linked chain

Iterates through a singly linked chain

Removes the first node from a doubly linked chain

Removes the first node from a singly linked chain

A

Removes the first node from a doubly linked chain

62
Q

Suppose we have a Queue implemented with a circular array with one unused slot. The capacity of the queue is 10 and the size is 5.

Which are legal values for front and rear?

front: 0

rear: 5

front: 4

rear: 9

front: 7

rear: 2

front: 9

rear: 2

all of the above

A

front: 9

rear: 2

63
Q

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 1

four elements in the queue

five elements in the queue

one element in the queue

six elements in the queue

invalid

empty queue

three elements in the queue

A

five elements in the queue

64
Q

Given that frontIndex stores the index of the first element of the queue stored in a circular contents array, which of the following best describes how to update frontIndex when a new entry is successfully dequeued:

backIndex = ( backIndex + 1) % contents.length

frontIndex = ( frontIndex + 1) % contents.length

frontIndex ++

backIndex ++

A

Correct answer:

frontIndex = ( frontIndex + 1) % contents.length

65
Q

A data structure that provides a method to directly access any of its members is a:

stack

queue

bag

list

A

list

66
Q

When adding a node newNode to a linked list referenced by head, what code would be in the branch for the case that the list is empty?

curr = newNode;

head. Next = newNode

prev.next = newNode

head = newNode;

A

head = newNode;

67
Q

When adding a node newNode to the beginning of a singly linked list with a head and tail reference, what code would be in the branch for the case that the list is not empty?

newNode.next = head;

head = newNode;

newNode = head;

head.next = newNode;

newNode.next = head;

tail = head.next;

newNode.next = head;

curr = newNode;

A

newNode.next = head;

head = newNode;

68
Q

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

Null

an IndexOutOfBoundsException

The item formerly stored in position k+1

The item formerly stored in position k-1

A

The item formerly stored in position k+1

69
Q

Suppose you are trying to choose between an array and a singly linked list to store the data in your program. Which data structure will be more efficient if data is regularly removed from the first half of the data structure?

Select all that apply

A linked list

An array

A

Correct answer:

A linked list

70
Q

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? Select all that apply

Arrays provide more efficient access to individual elements.

Linked lists are better suited to a program where the amount of data can change unpredictably.

Linked lists provide more efficient access to individual elements.

A

Correct answer:

Arrays provide more efficient access to individual elements.

Linked lists are better suited to a program where the amount of data can change unpredictably.

71
Q

Select the most accurate steps to remove a node that contains a designated element from a singly linked list with a head and tail reference

If it’s not the first node, then 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 next reference of the node containing the designated element. Removing the first node would be a special case.

If it’s not the last node, then 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 next reference of the node containing the designated element.

If it’s not the first node, then find the node that contains the designated element, reset the next reference of that node to be the node before it.

If it’s not the first or last node, then 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 next reference of the node containing the designated element. Removing the first or last node would each be a special case.

A

If it’s not the first or last node, then 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 next reference of the node containing the designated element. Removing the first or last node would each be a special case.

72
Q

Which of the following would remove the Node referenced by the non-null variable curr from items, a non-empty doubly linked list with references firstNode and lastNode without sentinel nodes? Assume that curr has access to methods getPrevious(), setPrevious(Node n), getNext(), and setNext(Node n). Also, items has access to getSize().

if (list.getSize() == 0){

curr.getPrevious().setNext(curr.getNext());    

curr.getNext().setPrev(curr.getPrev());  

lastNode = firstNode; }

else {

curr.getPrevious().setNext(curr.getNext());    

curr.getNext().setPrev(curr.getPrev());  

}

curr.getPrevious().setNext(curr.getNext());

curr.getNext().setPrev(curr.getPrev());

if (list.getSize() == 1){

curr.getPrevious().setNext(curr.getNext());    

curr.getNext().setPrev(curr.getPrev());  

lastNode = firstNode; }

else {

curr.getPrevious().setNext(curr.getNext());    

curr.getNext().setPrev(curr.getPrev());  

}

if (firstNode == lastNode){

firstNode = null;

lastNode = null;

} else {

if (curr == firstNode){

firstNode = curr.getNext();    

firstNode.setPrev(null);

}

if (curr == lastNode){

 lastNode = curr.getPrev();    

 lastNode.setNext(null);

}

else {

 curr.getPrevious().setNext(curr.getNext());    

 curr.getNext().setPrev(curr.getPrev());  

}

}

curr.getPrevious().setNext(prev.getNext());

curr.getNext().setPrev(next.getPrev());

if (list.getSize() == 0){

curr.getPrevious().setNext(curr.getNext());    

curr.getNext().setPrev(curr.getPrev());  

lastNode = firstNode; }

else {

curr.getPrevious().setNext(curr.getNext());    

curr.getNext().setPrev(curr.getPrev());  

}

A

if (firstNode == lastNode){

firstNode = null;

lastNode = null;

} else {

if (curr == firstNode){

firstNode = curr.getNext();    

firstNode.setPrev(null);

}

if (curr == lastNode){

 lastNode = curr.getPrev();    

 lastNode.setNext(null);

}

else {

 curr.getPrevious().setNext(curr.getNext());    

 curr.getNext().setPrev(curr.getPrev());  

}

}

73
Q

Which of the following is true about a doubly linked chain implementation of a list with sentinel nodes? Select all that apply.

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

It improves the algorithmic efficiency of adding an element to the middle of a list compared to a doubly linked chain without sentinel nodes

It is more efficient than a singly linked chain for iterating through the list backwards

It stores more data than a doubly linked chain without sentinel nodes

It takes more space than a doubly linked chain without sentinel nodes

A

Correct answer:

It is more efficient than a singly linked chain for iterating through the list backwards

It takes more space than a doubly linked chain without sentinel nodes

Correct answer:

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

74
Q

Given a singly linked list with a firstNode and lastNode. What is the efficiency of remove(givenPostion) for the first, middle and last position in the list?

O(1);O(1);O(1)

O(1);O(n);O(n)

O(1);O(1);O(n)

O(1);O(n);O(1)

O(n);O(n);O(n)

A

Correct answer:

O(1);O(n);O(n)

75
Q

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

O(n)

O(n^2)

O(1)

A

Correct answer:

O(n^2)

76
Q

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

IllegalStateException

bicep curls, burpees, push-ups, sit-ups, squats, tricep dips

bicep curls, burpees, squats, tricep dips

bicep curls, sit-ups, squats, tricep dips

A

Correct answer:

bicep curls, burpees, squats, tricep dips

77
Q

Given

public class User implements Comparable<User> {</User>

private String firstName;

private String lastName;

private String emailAddress;

}

Which of the following methods could be used to sort User objects using last name and when 2 lastNames are the same then use firstName?

public int compare(User other) {

    int result = lastName.compareTo(other.lastName);

    if (result == 0)

        return firstName.compareTo(other.firstName);

    else

        return result;

 

} 

public int compareTo(User other) {

    int result = emailAddress.compareTo(other.emailAddress);

    if (result == 0)

       return lastName.compareTo(other.lastName);

    else

       return result;

 

}

public int compareTo(User other) {

    int result = lastName.compareTo(other.lastName);

    if (result == 0)

        return emailAddress.compareTo(other.emailAddress);

    else

        return result;

 

}              

public int compareTo(User other) {

    int result = lastName.compareTo(other.lastName);

    if (result == 0)

        return firstName.compareTo(other.firstName);

    else

        return result;

 

}
A

public int compareTo(User other) {

    int result = lastName.compareTo(other.lastName);

    if (result == 0)

        return firstName.compareTo(other.firstName);

    else

        return result;

 

}
78
Q

This sorting algorithm looks at the unsorted portion of the array only performs a swap to get the next element in place. After one pass the smallest item is in the first slot and after the second pass the second smallest item is in the second slot and so forth.

selection sort

insertion sort

merge sort

bubble sort

quick sort

A

Correct answer:

selection sort

79
Q

Chris implements a standard sorting algorithm that sorts the numbers 64, 25, 12, 22, 11 like so:

64 25 12 22 11

25 64 12 22 11

12 25 64 22 11

12 22 25 64 11

11 12 22 25 64

Which sorting algorithm is this?

merge sort

bubble sort

insertion sort

selection sort

A

Correct answer:

insertion sort

80
Q

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

It copies elements only to their final locations.

It is faster for already sorted data.

It requires less code.

It doesn’t require as much extra storage.

It can be implemented recursively.

A

It is faster for already sorted data.

81
Q

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

Swapping of sorted items above each unsorted item’s insertion point

Comparison of each unsorted item to determine the next sorted item

Comparison of each unsorted item to all the currently sorted items

Swapping of unsorted item to its final destination

Comparison of each unsorted item to its neighbor until finding its destination

A

Correct answer:

Swapping of unsorted item to its final destination

Comparison of each unsorted item to determine the next sorted item

82
Q

In order to insert an item in order in a sorted singly linked chain, the following techniques can be used to do so in O(n) (select all that apply):

The reverse transversal technique

The look-ahead technique

The runner technique

The foreach loop technique

A

Correct answer:

The look-ahead technique

The runner technique

83
Q

Select the best choice below to fill in the blanks:

When a __________ implements Comparator, the __________ named ____________ must be implemented.

class, method, compareTo

class, method, compare

method, class, compareTo

method, class, compare

A

Correct answer:

class, method, compare

84
Q

Given an array of Grocery objects that needs to be sorted either by price or by expiration date. Select the best design approach

Write two custom sort methods, one that sorts Grocery objects based on price and one that sorts them based on expiration date.

Have Grocery class implement Comparable and have the compareTo accept a parameter to indicate which attribute to compare on and call it different ways from a single sort method.

Create a Comparator object to compare Grocery objects based on price and a Comparator object to compare Grocery objects based on expiration date and have the sort method expect a Comparator object as a parameter.

A

Correct answer:

Create a Comparator object to compare Grocery objects based on price and a Comparator object to compare Grocery objects based on expiration date and have the sort method expect a Comparator object as a parameter.

85
Q

Which of the following possible reasons BEST explains why a SortedList implementation would not need the method, add(int newPosition, T newEntry)?

The contains method could be used instead.

The behavior achieved through the add(int newPosition, T newEntry) could also be achieved by combining other SortedList methods.

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

To reduce the number of lines of code required.

A

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

86
Q

Which of the following are valid approaches to implementing a SortedList? (select all that apply)

Write it from scratch, most of the methods implemented similarly to the List implementation, some methods removed, added, or updated to ensure that the List remains in sorted order

Use inheritance, where a SortedList is a child (subclass) of a List (superclass). Attributes and methods are inherited, methods overridden and updated to ensure that the List remains in sorted order. Methods which do not suit the sorted requirement are be overridden with code which throws an Exception if called

Use composition, where a SortedList uses a List as a field, with other attributes and methods to supported the SortedList features

A

Write it from scratch, most of the methods implemented similarly to the List implementation, some methods removed, added, or updated to ensure that the List remains in sorted order

Use inheritance, where a SortedList is a child (subclass) of a List (superclass). Attributes and methods are inherited, methods overridden and updated to ensure that the List remains in sorted order. Methods which do not suit the sorted requirement are be overridden with code which throws an Exception if called

Use composition, where a SortedList uses a List as a field, with other attributes and methods to supported the SortedList features

87
Q

Both ListInterface and SortedListInterface include the method definition, contains(anEntry). Consider the example implementation of the List contains(anEntry) method presented below.

public boolean contains(T anEntry) {

boolean found = false;
int index = 0;
while (!found && (index < numberOfEntries)) {
if (anEntry.equals(list[index])){
found = true;

}
index++; } // end while

        return found; } // end contains

How could the contains(anEntry) method implementation used for List be improved upon when implementing the contains(anEntry) method for a SortedList?

The contains method implementation could start searching through the List from index 1 instead of 0.

The contains method implementation could start searching through the List from index list.getLength() - 1 instead of 0.

The contains method could be written so that it stops searching the List for anEntry when it passes the location where anEntry should be found if stored within a SortedList.

The contains method implementation could start searching through the List from index list.getLength() instead of 0.

A

The contains method could be written so that it stops searching the List for anEntry when it passes the location where anEntry should be found if stored within a SortedList.

88
Q

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

The contains(newEntry) and getPosition(newEntry) would be inherited, client code can use these inefficient methods

The clear() method would be inherited but would no longer work, client code using these methods would throw an Exception

A

Correct answer:

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

89
Q

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

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

The revised List Base class can be set up so that inefficient methods - like contains(newEntry) and getPosition(newEntry) - cannot be inherited by subclasses

The contains(newEntry) and getPosition(newEntry) would be inherited, client code can use these inefficient methods

A

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

90
Q

Deep copy for an object means

creating an alias for the object

performing a shallow copy plus copying all of the objects inside the object.

creating an copy of the object but all the objects inside the object remain aliases

performing a shallow copy plus copying all of the mutable objects inside the object.

A

performing a shallow copy plus copying all of the mutable objects inside the object.

91
Q

Which of the following best describes the leaf of a tree data structure:

a node with no children

a node at the top of the tree

a node with no parent

a node with no siblings

A

a node with no children

92
Q

the same level, what is the height of the tree?

log2 (n)

2 n

2 n-1

log2 (n-1)

log2 (n+1)

2 n+1

A

Correct answer:

log2 (n+1)

93
Q

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 7 has nodes that either have 0 or 2 children and all leaves on the same level, how many nodes are in the tree?

32

63

64

31

128

127

A

127

94
Q

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?

8

7

5

3

A

7

95
Q

Give a binary tree of height 3 with 5 nodes and the inorder traversal

ABCDE

Which of the following must be leaves if B is the root?

D, E

D

A, E

D, B

A, B

A

A, E

96
Q

Given a binary tree of height 3 with 5 nodes and the preorder traversal

ABCDE

Which nodes must be the root

B

D

E

A

C

A

A

97
Q

Given a binary tree of height 3 with 5 nodes and the postorder traversal

ABCDE

Which node is the root?

E

A

D

C

B

A

Correct answer:

E

98
Q

Given the following code skeleton for a private helper method binarySearchHelper:

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:

mid

-1

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

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

-1

mid

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

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

-1

mid

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

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

mid

-1

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

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

A

Correct answer:

-1

mid

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

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

99
Q

Given

public <T extends Comparable<T>> int binarySearch(T[] array, T value, int first, int last)</T>

{

if (first > last) {

return -1;

}

else {

int mid = (first + last) / 2;    

if (value.compareTo(array[mid]) < 0)

    return binarySearch(array,value,first,mid - 1);

else  if (value.compareTo(array[mid]) > 0)

    return binarySearch(array,value,mid + 1,last);

return mid;

}

}

How many recursive calls would be made after the following initial call to binarySearch?

Integer[] vals = {2,4,6,8,10,12,14,16,18};

binarySearch(vals,9,0,vals.length - 1);

1

3

9

5

4

A

4

100
Q

Given

public <T extends Comparable<T>> int binarySearch(T[] array, T value, int first, int last)</T>

{

if (first > last) {

return -1;

}

else {

int mid = (first + last) / 2;    

if (value.compareTo(array[mid]) < 0)

     return binarySearch(array,value,first,mid - 1);

else  if (value.compareTo(array[mid]) > 0)

    return binarySearch(array,value,mid + 1,last);

return mid;

}

}

How many recursive calls would be made after the following initial call to binarySearch?

Integer[] vals = {2,4,6,8,10,12,14,16,18};

binarySearch(vals,16,0,vals.length - 1);

1

4

0

3

2

A

2

101
Q

What is not true about a binary search tree?

When printed with inorder traversal, it will be sorted

It is a binary tree

The leftmost node is the smallest node in the tree

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

A

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

102
Q

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

We reach a null child.

We find a node greater than the node to be inserted.

We reach the tree’s maximum level.

We find a node lesser than the node to be inserted.

We find a node without any children.

A

It was filled in ascending order.

103
Q

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?

All keys were identical.

It was filled in descending order.

It was filled in ascending order.

The tree is a preorder tree.

The root value was the maximum.

A

It was filled in ascending order.