Quiz 3, Quiz 4, Test 2, Test 1

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

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

Where does a queue add new items?

at the back

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

at the front

Given that backIndex references the last element of the queue stored in a contents array, which of the following best describes how to update backIndex when a new entry is successfully enqueued:

backIndex = ( backIndex + 1) % contents.length

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

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

An initial call to displayArray3 has parameter values of 0 and 20 for first and last respectively: displayArray3(myArray, 0, 20). Which is the correct sequence of subsequent calls?

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

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

doubly linked chain

public class RecursiveMath ... public int fib (int a) { if (a < 2) return a; else return fib(a-1) + fib(a-2); } ... } What is the base case for fib in the above definition

fib(a) for a < 2

What type of behavior defines a queue?

first in, first out

What would the following queue look like after 3 dequeues?

firstNode --> 9 <-- lastNode

Which of the following are possible methods for a Customer class?

getShippingAddress(), getBillingAddress(), placeOrder()

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"

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'

Which of the following would be appropriate functional requirements for an Employee Management System? (Select all which apply) The Employee Management System shall...

- Allow authorized users to add, view, and modify an employee record - Allow authorized users to search for an employee record - Allow employee users to submit a vacation\leave application

Which of the following inheritance relationships are appropriate for this scenario's design? (Select all which apply) Note: You may assume that the arrows used depict an inheritance relationship

- Customer and Employee as subclasses of User - Apparel, Book, Consumer Electronics, DVD, etc. as subclasses of Product

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

Keeping track of lastNode in addition to firstNode

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

@Override public T removeFront() { T front = getFront(); firstNode = firstNode.getNext(); if(firstNode == null) { lastNode = null; } else { firstNode.setPrev(null); } return front; } Select all of the following that will happen if removeFront() is called on a deque with 3 items?

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

Which of the following could be considered appropriate functional requirements for the Vending Machine? Select all that apply.

- The system shall allow users to select a product to purchase - The system shall dispense a product - The system shall process a payment - The system shall notify users when a payment has been processed - The system shall notify users when a payment has been processed

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

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

@Override public T removeFront() { T front = getFront(); firstNode = firstNode.getNext(); if(firstNode == null) { lastNode = null; } else { firstNode.setPrev(null); } return front; } Select all of the following that will happen if removeFront() is called on a deque with 1 item?

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

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

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

0,5

Anonymizing posts (removing identifying data etc.) before forwarding to the human judge supports which of the following ACM Ethical Principles? Choose the ACM Ethical Principle which BEST applies.

1.4 Be fair and take action not to discriminate.

What ethical principle could possibly be violated by the competition software ranking scored posts by last name, then by timestamp, instead of by timestamp then last name, ? Choose the ACM Ethical Principle which BEST applies.

1.4 Be fair and take action not to discriminate.

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 TWO ethical principles could possibly be violated if you give in to curiosity and look at the customer's financial information?Choose the TWO ACM Ethical Principles which BEST apply.

1.6 & 2.8

An initial call to displayArray3 has parameter values of 0 and 20 for first and last respectively: displayArray3(myArray, 0, 20). Which of the following would be the values of first and last in the second recursive call from that method call?

11,20

Given the following code: public static int powerOf5(int exponent){ if (exponent == 0) return 1; else return 5 * powerOf5(exponent -1); } what is powerOf5(3)?

125

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

136

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

14

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

14

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

2^11

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

2^7

Given 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

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

40

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

48

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

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

Consider the software design for a Vending Machine that: a) both loads and dispenses from the front b) requires the tracking of the contents of each product's "tray" With respect to the data structure design decision, which statement is true?

A Stack would be an appropriate data structure for this application

Suppose you are trying to choose between an array and a singly linked list to store the data in your Java program. Which arguments would correctly support one side or the other?

A and B - Linked lists are better suited to a program where the amount of data can change unpredictably. - Arrays provide more efficient access to individual elements.

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

A base case and a recursive case

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

A reference to the node in position k - 1

J.C. Knight (2002) describes safety-critical systems as "those systems whose failure could result in loss of life, significant property damage or damage to the environment". John C Knight. 2002. Safety critical systems: challenges and directions. In Proceedings of the 24th international conference on software engineering.547-550.1 As lead for a software development project involving a safety-critical system you are being pressured by your manager to release the system before it has been adequately tested. Approving the release of the system before completing testing would be:

A violation of the ACM Code of Ethics and Professional Conduct

We know that using Generics reduces the need to cast types. Which of the following answers best conveys some of the other benefit(s) of using generics and parameterized or generic types in Java?

All of the above

What is ethics?

All of the above

When looping through the chain to see if the list contains a designated item it is necessary to check that the current reference is not null because

All of the above

@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

An Employee Management System would need the ability to track and manage many different instances of the Employee objects (as well as many instances of Employee subclasses, such as ExternalContractor, PartTimeEmployee).To accommodate this requirement the design should be amended to include:

An appropriate data structure (or structures) for organizing, processing, retrieving and storing Employee data

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

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

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?

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

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 FOUR questions would best help you determine if permanently blacklisting certain addresses is an ethical course of action? (Select the best 4 options.)

Fairness, Liberty, Responsibilities, and Outcomes

What are the Eight Key questions used to evaluate the ethical dimensions of a problem or situation? Select all which apply.

Fairness, Outcomes, Responsibilities, Character, Liberty, Empathy, Authority, RIghts

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;

Fairness

How can I act equitably and balance legitimate interests?

Liberty

How does respect for freedom, autonomy, or consent apply?

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

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

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

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

public static void displayArray(int[] array, int first, int last) { if (first <= last){ displayArray(array, first, last - 1); System.out.print(array[last] + " "); } }

In reverse order

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

A social media service has uncovered evidence to suggest that manipulating the nature and priority of the content a user sees in their social media feed could affect their emotional state. Being an unanticipated effect of their technology the social media company is considering exploratory research involving deliberately manipulating the content for a portion of the users, then monitoring and observing the subsequent impact. Which of the 8 Key questions would be most relevant if users were not previously advised that they would become part of such research when they registered to use the service?

Liberty

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

Neither

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

Which of the following are appropriate methods for inclusion in the design of this scenario? Check all that apply.

PlaceOrder(), sendOrderInvoice(), sendOrderCancellationNotice(), sortProductsByPrice(), submitProductReview()

Which of the following is the best option for classes for this scenario? Carefully consider the options presented, remember that some nouns are better suited for fields not classes.

ProductCatalog, Product, User, Customer, Employee, Order

Which of the following is the best option for classes for the Vending Machine? Carefully consider the options presented, remember that some nouns are better suited for fields not classes.

ProjectRunner, Controller, GUI, Product, Payment

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

The benefit of using sentinel nodes

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

Consider the Vending Machine software design. With respect to a relatively loosely coupled design which incorporates MVC, which of the following would be the preferred arrangement?

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

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

public class RecursiveMath ... public int fib (int a) { if (a == 1) return 1; else return fib(a-1) + fib(a-2); } ... } Given the above definition, what is the result of executing the following? RecursiveMath bill = new RecursiveMath(); int x = bill.fib(-1);

The code does not terminate

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

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

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

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

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

Throw an IndexOutofBoundsException

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

Consider an initial design which includes a User, Customer, and Employee class arranged in a hierarchy where Customer and Employee are subclasses of User. Which of the following are good examples of field combinations for the User and Customer class?

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

Outcomes

What achieves the best short- and long-term outcomes for me and all others?

Empathy

What would I do if I cared deeply about those involved?

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

one more than the queue's initial capacity

Which of the following are true for a list ADT?

ordered & items can be replaced

Which of the following 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);

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

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

the queue's front entry

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

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


Kaugnay na mga set ng pag-aaral

Ch. 26: Disorders of Blood Flow and Blood Pressure Regulation

View Set

Chapter 10: Eukaryotic Cell Biology

View Set

A320 over wing exit and briefing

View Set

Financial management test 1 chapter 1

View Set