All Quiz 2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Using the evaluatePostfix algorithm, evaluate the following postfix expression. 7 2 + 4 * a. 36 b. 13 c. 15 d. 18

A

A language-independent specification for a group of values and operations on those values is called a/an: a. abstract data type b. data structure c. collection d. primitive

A

A test driver for the bad add method should check for which one of the following a. an over capacity condition b. printing elements of the bag c. adding elements of the correct type d. an empty bag condition

A

A top-level class a. is not nested b. is nested in an enclosing class c. is always static d. is defined entirely within another class definition

A

The Java Class Library interface Queue method that retrieves the entry at the front of a queue but returns null if the queue was empty is a. peek b. empty c. poke d. look

A

The Java Class Library interface Queue method that retrieves the entry at the front of a queue but throws a NoSuchElementException if the queue was empty is a. empty b. peek c. poke d. look

A

The ____ ADT organizes its entries according to the order in which they were added. a. queue b. stack c. list d. priority queue

A

The _____ shows a method's state during execution. a. activation record b. stack c. program counter d. program stack

A

The condition when a recursive method does not satisfy a base case it is called a. infinite recursion b. finite recursion c. iterative recursion d. baseless recursion

A

A chain requires less memory than an array of the same length.

False

A final class is more secure than one that is not final.

False

A method can change the state of an object passed to it as an argument.

False

A nested class is defined partially within another class definition.

False

A recursive method uses less memory than an iterative method.

False

A vector is analogous to a resizable linked-chain.

False

You should implement all methods of an ADT implementation before testing to make testing easier.

False

You should never suppress compiler warnings.

False

Activation records for recursive methods are the same as activation records for non-recursive methods.

True

All entries in the stack ADT must have the same data type.

True

Parentheses override the rule of operator precedence.

True

When a circular linked chain is used to represent a queue, it is not necessary to maintain a firstNode data field.

True

Adding a new entry to an empty bag a. is a simple task b. must be treated as a special case c. throws an IllegalOperationException d. causes a NullExceptionError

A

In a node object, the next field contains a. a reference to another node b. the data portion of the node c. a reference to the beginning of the list d. none of the above

A

In a two-part circular linked chain implementation of a queue, what is the performance when the dequeue operation ? a. O(1) b. O(log n) c. O(n) d. O(n^2)

A

In a vector implementation of a Stack ADT, you add an entry to the top of a stack using which vector method? a. add b. push c. put d. none of the above

A

In a vector implementation of a Stack ADT, you check for an empty stack using which vector method? a. isEmpty b. empty c. stackEmpty d. none of the above

A

In a vector implementation of a Stack ADT, you clear all of the contents of a stack using which vector method? a. clear b. delete c. deleteAll d. none of the above

A

In a vector implementation of a Stack ADT, you remove an entry from the top of a stack using which vector method? a. remove b. pop c. retrieve d. none of the above

A

In a vector implementation of a Stack ADT, you retrieve the top entry without removing it using which vector method? a. lastElement b. peek c. look d. none of the above

A

The ADT priority queue organizes objects a. according to priority of the objects b. alphabetically c. from front to back d. from back to front

A

The Java Class Library interface Queue method that retrieves and removes the entry at the front of a queue and returns null if the queue was empty is a. poll b. remove c. retrieve d. get

A

The Java Class Library interface Queue method that retrieves and removes the entry at the front of a queue and throws a NoSuchElementException if the queue was empty is a. remove b. poll c. retrieve d. get

A

The Java Class Library interface Queue method to put an entry on the back of a queue that returns false if the method fails is a. offer b. add c. put d. poll

A

The Java Class Library interface Queue method to put an entry on the back of a queue that throws an exception of the method fails is a. add b. offer c. put d. poll

A

The Java Class Library method to resize an array is called a. Arrays.copyOf b. Arrays.resize c. Arrays.copy d. Arrays.double

A

The _____ ADT that has operations to add, remove, or retrieve entries at both the front and back of a queue is called a a. deque b. reversible queue c. reversible stack d. all of the above

A

The efficiency for recursively calculating x^n is a. O(log n) b. O(n log n) c. O(n) d. O(n^2)

A

The efficiency for recursively traversing a chain of linked nodes is a. O(n) b. O(1) c. O(n^2) d. it cannot be proven

A

The efficiency for solving the Towers of Hanoi problem recursively is a. O(2^n) b. O(n^2) c. O(n) d. O(log n)

A

The method for adding a new item to the back of a queue is called a. enqueue b. dequeue c. getFront d. none of the above

A

The method for removing an item from the front of a queue is called a. dequeue b. enqueue c. getFront d. none of the above

A

The method for retrieving the queue's front entry without altering the queue is called a. getFront b. enqueue c. dequeue d. none of the above

A

The method remove that has no parameter in the bag implementation a. removes the last entry in the array b. removes the first entry in the array c. removes a random entry in the array d. none of the above

A

What is the output of the following program when the method is called with 4? voidunknown(intn) { if(n > 0) unknown(n-1); System.out.print("?"); } a. ????? b. ???? c. ??? d. none of the above

A

What is the output of the following program when the method is called with 4? voidunknown(intn) { if(n > 0) { System.out.print("?"); unknown(n-1); } } a. ???? b. ????? c. ??? d. none of the above

A

When you remove an item from a stack, you remove it from a. the top b. the bottom c. the middle d. wherever the client specifies

A

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

A

Where is a new node added to a linked list? a. at the beginning b. at the end c. in the middle d. in a random place

A

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

A

Which bag behavior is not useful or relevant for a set? a. getFrequencyOf() b. add() c. remove() d. contains()

A

Which bag behaviors would need modified when implementing a set? a. add() b. clear() c. contains() d. toArray()

A

Which behavior is not represented in a bag? a. reorder the bag b. report the number of items in the bag c. report if the bag is empty d. add an item to the bag

A

Which behavior is not specified in the bag ADT? a. sort() b. contains() c. clear() d. remove()

A

Which behavior(s) change the contents of a bag? a. add() b. getFrequencyOf() c. contains() d. toArray()

A

Which behavior(s)change the contents of a bag? a. remove() b. getCurrentSize() c. isEmpty() d. getFrequencyOf()

A

Which behaviors leave the contents of a bag unaltered? a. contains() b. remove() c. clear() d. add()

A

Which instruction suppresses an unchecked-cast warning from the compiler? a. @SuppressWarnings("unchecked") b. @SuppressUnchecked() c. @SuppressUncheckedWarnings() d. @Warning("suppress unchecked")

A

Which method accesses the last entry of a vector? a. lastElement b. last c. endOfVector d. you can't access the last entry directly

A

Which method can be used to retrieve all of the elements of a bag? a. toArray() b. printBag() c. displayBag() d. getAllItems()

A

Which method removes all entries of a bag? a. clear() b. remove() c. delete() d. empty()

A

Which method removes one occurrence of a particular entry from a bag if possible? a. remove(anItem) b. clear(anItem) c. delete(anItem) d. empty(anItem)

A

Which method removes one unspecified entry from a bag if possible? a. remove() b. clear () c. delete() d. empty()

A

Which method returns a count of the current number of items in a bag? a. getCurrentSize() b. getSize() c. size() d. currentSize()

A

Which of the following are good reasons to write Java statements that use your bag ADT before the implementation is done? a. it helps confirm the design b. it helps check the suitability of the specification c. it helps check your understanding of the specification d. all of the above

A

Which of the following is a disadvantage of using an array to implement the ADT bag? a. increasing the size of the array requires time to copy its entries b. adding an entry to a bag is fast c. removing an unspecified entry from the array is fast d. all of the above

A

Which of the following is a special kind of bag that does not allow duplicate entries? a. set b. collection c. extended bag d. super bag

A

Which of the following are properties of a set? a. duplicates are permitted b. elements are stored in order c. elements may not be removed d. none of the above

D

Which of the following methods is a good candidate for a core method: a. add() b. toArray() c. isArrayFull() d. all of the above

D

Which of the following real-world events could be simulated using a queue? a. bank line b. a shared network printer c. restaurant reservation list d. all of the above

D

Which of the following would be suitable items to store in a bag? a. marbles b. coins c. student roster d. all of the above

D

You wish to keep track of the distribution of words in a document, for example, how many times the word "apple" appears. You store each word in the document in a bag. Why is a bag a potentially good solution? a. the order of the words is unimportant b. the words in thedocument are not unique c. getFrequencyOf() is a useful behavior for determining the word distribution d. all of the above

D

An abstract data type is not necessarily a collection.

False

An iterative solution to the Towers of Hanoi problem moves fewer disks than the recursive solution.

False

By declaring a data type to be a BagInterface, we can replace the bag class with another class that implements the BagInterface.

False

Code written with respect to an interface makes it difficult to replace one implementation of a bag with another.

False

Entries of a bag may belong to different classes because items are unordered.

False

In a circular array-based implementation of a queue, frontIndex is equal to one less than backIndex when the queue is full.

False

In a circular array-based implementation of a queue, frontIndex is equal to one more than backIndex when the queue is empty.

False

In a linked chain implementation of a queue, the enqueue operation could potentially be dependent on the other entries and will require a search.

False

In a linked chain implementation of a queue, the enqueue operation requires a traversal to the end of the chain to insert a new entry onto the queue.

False

In a vector-based implementation of the Stack ADT, the most efficient place to maintain the top entry of a stack is in the vector's first element.

False

In an array-based implementation of the Stack ADT, it is more efficient to have the first array location reference the top of the stack.

False

In an array-based implementation of the Stack ADT, spreading the cost of the push operation when the stack is full yields a performance of O(n).

False

Infix expressions are easier to evaluate than postfix expressions.

False

Recursive method calls create multiple copies of the method in memory.

False

Recursive methods do not return a value.

False

The ArrayDeque class implements the Stack interface.

False

The bottom item in a stack was the last item added.

False

The first item added to a stack is the first one removed.

False

Unlike a stack, a queue does not restrict access to its entries.

False

When defining the bag class write methods that have simple implementation first to get them out of the way.

False

When defining the bag class, you should implement the isArrayFull and removeoperations first.

False

When testing a method, you only need to check for arguments that lie within the legal range of their corresponding parameter.

False

You can only pop from the top of the stack but you can peek at any entry on the stack.

False

You cannot determine the exact number of times a particular item appears in a bag because it is unordered.

False

A class should not return a reference to an array that is a private data field.

True

A collection is not necessarily an abstract data type.

True

A node does not reference the data in another node.

True

A priority queue cannot have null entries

True

A set is a special kind of bag.

True

A stack restricts access to its entries.

True

A vector is manipulated with methods.

True

A vector will grow in size as needed.

True

A vector's entries are indexed beginning with 0.

True

After the method clear, the programmer does not need to worry about deallocating the nodes that were in the chain.

True

All entries of a bag must have the same data type or a subtype of that data type.

True

An array potentially wastes more space than a chain.

True

Any method that adds an entry to a collection is typically considered to be a core method.

True

Any methods that a core method might call are part of the core group.

True

Converting a tail-recursive method to an iterative method is usually a straightforward process.

True

Each node in an ordinary linked chain references only the next node.

True

Entries of a bag can belong to classes related by inheritance.

True

In a circular array-based implementation of a queue, the available locations are not contiguous.

True

In a circular array-based implementation of a queue, you cannot use only frontIndex to determine when a queue is full.

True

In a linked chain implementation of a queue, when both the firstNode and lastNode entries are null, the chain is empty.

True

In a linked-chain implementation of the Stack ADT, the first node references the stack's top entry.

True

In an array-based implementation of a queue, inserting and deleting entries is accomplished using modulo arithmetic.

True

In an array-based implementation of a queue, keeping the front entry of the queue at queue[0] is inefficient.

True

In an array-based implementation of the Stack ADT, the cost of doubling the array size is amortized over all additions to the stack.

True

In the program stack, the second record on the stack belongs to the method that called the current method.

True

It is a good programming practice to only access a class's data fields only through accessor and mutator methods.

True

Pull is an alias for the pop method.

True

Queues are used in operating systems.

True

Security checks are essential to maintain the integrity of the LinkedBag objects.

True

The Java Class Library ADT PriorityQueue uses the compareTo method to determine how to order entries.

True

The Java Class Library interface for Queue has no operation to modify the contents of the front entry.

True

The Queue interface extends the Deque interface.

True

The item most recently added to a queue is at the back of the queue.

True

The null value can be used to signal failure to remove or retrieve an entry from a priority queue when it is empty.

True

The outer LinkedBag class can access the data fields of the inner Node class directly without using set and get methods.

True

The program stack stores activation records chronologically.

True

Using a resizable array to implement the stack ADT avoids the condition where a stack is too full to accept another entry.

True

When a circular linked chain has one node, the node references itself.

True

When comparing objects in a bag, we assume that the class to which the objects belong defines its own version of equals.

True

When using a linked implementation, a bag can never become full.

True

Write stubs early in the implementation of an ADT so you can begin testing early.

True

You can push, pop and get items at either end of the ADT deque.

True

You can replace recursion with iteration by simulating the program stack.

True

You can use a recurrence relation to determine the performance of a recursive method.

True

You cannot reach the bottom item in a stack without popping all of the other items off first.

True

You need two external references for a circular doubly linked chain, one for the firstNode and one for the lastNode.

True

You should always trace a recursive method to ensure it is correct.

True

Which behaviors do not change the contents of a bag? a. add() b. clear() c. remove() d. none of the above

D

A call to the remove method with no arguments a. removes the first node b. removes the last node c. removes a random node d. asks the user which node to remove

A

A common alias for the queue method getFront is a. peek b. get c. put d. all of the above

A

A linked chain whose last node is null is sometimes called a(n) a. linear linked chain b. circular linked chain c. null terminated linked chain d. all of the above

A

A method that calls itself is called a a. recursive method b. base method c. iterative method d. dynamic method

A

A recursive method that processes a chain of linked nodes a. uses the first node in the chain b. uses the last node in the chain c. divides the chain in half placing the middle node in the left chain d. divides the chain in half placing the middle node in the right chain

A

A reference to the first node in a linked list is called the _____ reference. a. head b. initial c. first d. default

A

A return value of -1 from the getIndex method indicates a. the entry was not present in the bag b. the entry was found at the end of the array c. the bag was empty d. the bag was full

A

Accessing all of the nodes in a chain beginning with the first one is called a(n) a. traversal b. visitation c. chaining d. link crawl

A

In a linked-chain implementation of a Stack ADT, the performance of popping an entry from the stack is a. O(1) b. O(2) c. O(n) d. O(n^2)

A

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

A

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

A

An array whose index of the first location follows the index its last one is call a. circular b. following c. round d. oval

A

An expression that has correctly paired delimiters is called a(n) a. balanced expression b. Reverse Polish expression c. infix expression d. algebraic expression

A

An implementation of an ADT with a programming language is called a/an: a. data structure b. abstract data type c. collection d. primitive

A

An incomplete definition of a method is called a _____. a. stub b. core method c. fail-safe method d. security problem

A

An inner class is a. a nested class b. not static c. both a and b d. none of the above

A

An object that groups other objects and provides services to its clients is called a/an: a. collection b. abstract data type c. data structure d. primitive

A

An object you link in Java to form a linked list is called a(n) a. node b. address c. reference d. link

A

At the time a method is called during program execution, the activation record is pushed onto the a. program stack b. execution stack c. frame d. none of the above

A

Decrementing the private class variable numberOfEntries in a bag a. causes the last entry to be ignored b. causes an IllegalState exception to be thrown c. destroys the integrity of the bag container d. is a security problem

A

During program execution, the _____ references the current instruction. a. program counter b. st1ack c. frame d. activation record

A

Given the following chain, what does the resultant chain look like after adding the node with an entry "U" in it? "J", "X", "F", "K", "L", null a. "U", "J", "X", "F", "K", "L", null b. "J", "X","F", "K", "L", "U", null c. you cannot determine where the entry will go in a bag chain implementation d. none of the above

A

In a linked-chain implementation of a Stack ADT, the performance of pushing an entry onto the stack is a. O(1) b. O(2) c. O(n) d. O(n2)

A

Given the following chain, what does the resultant chain look like after removing the node with the entry "J" in it? "J", "X", "F", "K", "L", null a. "X", "F", "K", "L", null b. null, "X", "F", "K", "L", null c. you cannot remove the first node in an non-empty chain d. none of the above

A

Given the following chain, what does the resultant chain look like after removing the node with the entry "K" in it? "J", "X", "F", "K", "L", null a. "X", "F", "J", "L", null b. "J", "X", "F", "L", null c. "J", "X", "F", "K", "L", null d. none of the above

A

Given the following chain, what does the resultant chain look like after removing the node with the entry "L" in it? "J", "X", "F", "K", "L", null a. "X", "F", "K", "J", null b. "J", "X", "F", "K", null c. you cannot remove the last node d. none of the above

A

Given the following infix expression, which one of the following is the corresponding postfix expression? (a + b) * (c -d) / (e + f) a. a b + c d -* e f + / b. a b c d e f + * -/ + c. a b + c d -e f + * / d. none of the above

A

Given the following infix expression, which one of the following is the corresponding postfix expression? w + x * y / z a. w x y * z / + b. w x + y z * / c. w x y q + * / d. none of the above

A

Given the following infix expression, which one of the following is the corresponding postfix expression? a + r ^ 2 -5 a. a r 2 ^ + 5 - b. a r + ^ 5 - c. a r 2 5 + ^ - d. none of the above

A

How can we tell if a two-part circular linked chain queue is empty? a. both the queueNode and freeNode reference the same node b. the freeNode is one node behind the queueNode c. the freeNode is one node in front of the queueNode d. the empty field is set to true

A

How does a queue organize it items? a. according to the order in which they were added b. by priority c. alphabetically d. randomly

A

How many recursive calls will be made if the following method is called with 6? voidgreeting(intn) { System.out.println("Hello!"); greeting(n-1); } a. infinitely b. 7 c. 6 d. 5

A

How many recursive calls will be made if thefollowing method is called with 6? voidgreeting(intn) { if(n > 0) { System.out.println("Hello!"); greeting(n+1); } } a. infinitely b. 7 c. 6 d. 5

A

If a bag is empty before the remove method executes, it a. returns null b. throw an exception c. returns an error message d. all of the above

A

If an array bag contains the entries "lions", "elephants", "otters", "bears", "tigers", "lemurs" and a call to the remove method with the entry "bears" is made, what does the array look like after remove? a. ""lions", "elephants", "otters", "lemurs", "tigers", null b. "lions", "elephants", "otters", null, "tigers", "lemurs" c. "lions", "elephants", "otters", "tigers", "lemurs", null d. "lions", "elephants", "otters", "tigers", "lemurs"

A

If the following nodes are added in order, what does the resultant chain look like? "L", "A", "R", "X", "J" a. "J", "X", "R", "A", "L", null b. "L", "A", "R", "X", "J", null c. null, "J", "X", "R", "A", "L" d. null, "L", "A", "R", "X", "J"

A

In a ResizableArrayBag class, why does the add method always return true? a. to conform to the bag interface b. because the array will always double in size c. returning void is not a fail-safe programming practice d. all of the above

A

In a ______ the last node references the first node. a. circular linked chain b. array based queue c. array based circular queue d. linked chain

A

In a circular array-based implementation of a queue implementation where one unused location is used to differentiate between the front and back of the queue, the frontIndex is _____ than the backIndex. a. two more b. one more c. one less d. two less

A

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

A

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

A

In a circular array-based implementation of a queue, what is the performance when the enqueue operation does not resize the array? a. O(1) b. O(log n) c. O(n) d. O(n2)

A

In a circular array-based implementation of a queue, what is the performance when the enqueue operation if you amortize the cost of resizing the array over all additions to the queue? a. O(1) b. O(log n) c. O(n) d. O(n2)

A

In a circular linked chain, when a node is removed from the queue a. it is deallocated b. it is moved to a separate list c. it is ignored d. none of the above

A

In a doubly linked chain implementation of a queue, what is the performance when the dequeue operation? a. O(1) b. O(log n) c. O(n) d. O(n^2)

A

In a linked chain implementation of a queue, an external reference to the last node in the chain is called a(n) a. tail reference b. last node c. linked reference d. final node

A

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

A

In a linked chain implementation of a queue, the performance of the getFront operation is a. O(1) b. O(log n) c. O(n) d. O(n2)

A

In a linked-chain implementation of a Stack ADT, the performance of looking at the first entry on the stack without removing it is a. O(1) b. O(2) c. O(n) d. O(n^2)

A

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

A

In an array-based chain implementation of a Stack ADT, what is the performance of the ensureCapacity method when the array is not full? a. O(1) b. O(n) c. O(n log n) d. O(n2)

A

In an array-based chain implementation of a Stack ADT, what is the performance of the ensureCapacitymethod when the array is full? a. O(n) b. O(1) c. O(n log n) d. O(n^2)

A

In an array-based implementation of a queue, a possible solution to dealing with the full condition is to a. leave one array location unused b. check for frontIndex equal to backIndex c. wait for an arrayFullExcetion to be thrown d. all of the above

A

In an array-based implementation of a queue, a possible solution to dealing with the full condition is to a. maintain a count of queue items b. check for frontIndex equal to backIndex c. wait for an arrayFullExcetion to be thrown d. all of the above

A

In the Java Class Library, the default constructor Vector creates an empty vector with an initial capacity of a. 10 b. 0 c. 100 d. user-defined

A

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

A

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

A

In the program stack, the record at the top of the stack belongs to the method a. that is currently executing b. that is scheduled to execute next c. that called the method that is currently executing d. none of the above

A

In the remove method, setting the last entry of the array to null a. flags the removed object for garbage collection b. prevents malicious code from accessing it c. is a good security practice d. all of the above

A

Ordinary algebraic expressions are also known as a. infix expressions b. postfix expressions c. prefix expressions d. all of the above

A

Placing the Node class inside the LinkedBag class makes it a(n) a. inner class b. outer class c. dependent class d. inherited class

A

Polish notation is another term for a(n) a. prefix expression b. postfix expression c. infix expression d. algebraic expression

A

Recursive methods a. are useful when each recursive all is a solution to a smaller, identical problem ** b. do not use an if-statement c. are not useful in programming d. all of the above

A

Recursive methods need a(n) a. base case b. for loop c. trace d. all of the above

A

Reverse polish notation is another term for a(n) a. postfix expression b. prefix expression c. infix expression d. algebraic expression

A

Sets that adhere to the standard interface in the Java Class library a. do not contain a pair of objects x and y such that x.equals(y) is true b. are completely compatible with the bag interface c. allow duplicate entries d. order the objects contained in the set

A

The most efficient approach to dealing with a gap left in an array after removing an entry from a bag is to a. replace the entry being removed with the last entry in the array and replace the last entry with null b. replace the entry being removed with the first entry in the array and replace the first entry with null c. shift subsequent entries and replace the duplicate reference to the last entry with null d. replace the entry being removed with null

A

The next field in a node is also referred to as the a. link portion b. node c. initial address d. data portion

A

The node that is easiest to access in a linked-chain is a. the head node b. the tail node c. access time is the same for all nodes d. it cannot be determined

A

The operation to add an entry to a stack is called a(n) a. push b. add c. put d. peek

A

The operation to remove all entries from a stack is called a(n) a. clear b. remove c. removeAll d. empty

A

The operation to retrieve the top entry of a stack without removing it is called a(n) a. peek b. pop c. look d. top

A

The operation to return a stack's top entry is called a(n) a. pop b. get c. top d. peek

A

The pop and peek methods throw a(n) ________ exception when the stack is empty. a. runtime b. checked c. compile time d. stackEmpty

A

The precedence of an operator in a postfix expression a. is implied by the order in which the operators and operands occur b. is always left to right c. is always right to left d. depends on the compiler implementation

A

The rate of growth for the Towers of Hanoi problem as the number of disks increases is a. exponential b. quadratic c. linear d. constant

A

The remove method replaces the removed entry with null because a. the entry could potentially be scheduled for garbage collection b. the client expects a null return value c. it is a fail-safe programming practice d. otherwise it could be considered a duplicate value

A

To accommodate entries of any class, the bag methods use ______ . a. a generic type b. an inherited type c. a sub class d. all of the above

A

To determine the efficiency of a recursive method you need to solve a(n) a. recurrence relation b. recursive relation c. quadratic equation d. base case

A

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

A

Using the evaluatePostfix algorithm, evaluate the following postfix expression. a b + c d -*Assume that a =5,b =7, c = 6, and d = 2. a. 48 b. 39 c. 55 d. none of the above

A

Using the evaluatePostfix algorithm, evaluate the following postfix expression. wx+ y* z/Assume that w=3 , x=4, y = 2, z = 7. a. 2 b. 28 c. 18 d. 21

A

What happens if an OutOfMemoryError occurs while adding a new node to the chain? a. the chain will remain intact b. the chain will lose its integrity c. a faulty node will be added to the beginning of the chain d. access to the chain will be lost

A

What happens when you remove a node from a chain with only one node? a. the firstNodereference will become null b. the firstNodereference will become invalid c. an IllegalOperationException is thrown d. none of the above

A

What is the entry returned by the peekmethod after the following stack operations. push(A), push(R), pop(), push(D), pop(), push(L), pop(), push(J), push(S), pop(), pop() a. A b. S c. L d. D

A

What is the output of the following program when the method is called with 4? void unknown(intn) { System.out.print("?"); if(n > 0) unknown(n-1); } a. ????? b. ???? c. ??? d. none of the above

A

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

A

What object behaves like a high-level array? a. vector b. linked-chain c. array-chain d. all of the above

A

What question should you keep in mind when debugging a recursive method? a. If the method returns a value, does each of the cases return a value? b. Should a for-loop be included in the method? c. Are the activation records correct? d. All of the above.

A

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

A

When a counter enumerates simulated time units, it is called a(n) a. time-driven simulation b. clock simulation c. event-driven simulation d. all of the above

A

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

A

When a vector needs to increase its size a. the capacity is doubled b. the capacity is increased by 10 empty entries c. the capacity is increased by 1 as needed d. the capacity increase is user-defined

A

When adding an item to a bag, which of the following statements are true? a. You cannot specify the position of the item in the bag. b. You can specify the item will be placed as the first in the bag. c. You can specify the item will be placed as the last in the bag. d. None of the above.

A

When method X calls method Y, and method Y calls methodX, this is called a. mutual recursion b. tail recursion c. associative recursion d. an error

A

When method X calls method Y, method Y calls method Z, and method Z calls method X, this is called a. indirect recursion b. mutual recursion c. tail recursion d. an error

A

When resizing an array to increase the bag size, if the copy exceeds the maximum memory specified for the computer, the checkCapacity method should a. throw an IllegalStateException b. throw a MaxSizeExceededException c. throw a MaxMemoryExceededException d. return false

A

When the last action in a recursive method is a recursive call, it is called a. tail recursion b. final recursion c. delayed recursion d. latent recursion

A

When the need to expand the size of a bag occurs, the common practice is to a. double the size of the array b. increase the size of the array by one to accommodate the new entry c. use the Fibonacci sequence to determine the incremental size of the new array d. prompt the user for how much larger the bag will need to be

A

When too many recursive calls are made creating more activation records than the allocated program memory can handle, what kind of error occurs? a. stack overflow b. activation record overflow c. recursive overflow d. infinite recursion

A

When would you choose a two-part circular chain over a circular chain? a. when you frequently add an entry after removing one b. when you rarely add entries after removing one c. when you are space constrained d. when you don't want the garbage collector running

A

When you add an item to a stack, you place it a. on the top b. on the bottom c. in the middle d. it doesn't matter where

A

Which of the following is an advantage of using an array to implement the ADT bag? a. adding an entry to a bag is fast b. removing a particular entry requires time to locate the entry c. increasing the size of the array requires time to copy its entries d. the client has control over the size of the bag

A

Which of the following is not true with regard to bags? a. objects are in a specific order b. can contain duplicate items c. is an abstract data type d. is a kind of collection in Java

A

Which of the following methods is a good candidate for a core method: a. add() b. clear() c. contains() d. remove()

A

Which one of the following Java statements allocates an array in the bag constructor causing a compiler warning for an unchecked operation? Assume capacity is an integer. a. bag = (T[ ]) new Object[capacity]; b. bag = new T[capacity]; c. bag = new Object[capacity]; d. bag = new (T[ ]) Object[capacity];

A

Which one of the following is considered a safe and secure programming practice? a. making no assumptions about the actions of clients and users b. using @SupressWarning ("unchecked") c. adding the comments and headers of the public methods to the class by copying them from the interface d. all of the above

A

Which one of the following is considered a safe and secure programming practice? a. validating input data and arguments to a method b. identifying a group of core methods to implement first c. using generic data types d. none of the above

A

Which statement is true about the VectorStack class methods? a. they invoke the methods of the Vector class b. they require slightly more execution time than the ArrayStack methods c. both a & b d. none of the above

A

Why would the add method return false? a. when the addition of a new item was not successful b. when there was a duplicate of the entry already in the bag c. when there was not a duplicate of the entry already in the bag d. when addition of a new item was successful

A

_____ is an alias for the name of the pop method. a. pull b. remove c. delete d. all of the above

A

_____ is an alias for the peek method. a. getTop b. pull c. look d. all of the above

A

_____ is an alias for the push method. a. insert b. pull c. delete d. all of the above

A

A call to the remove method with no arguments on an empty list a. returns null b. returns false c. throws a ListEmptyException d. throws an IllegalOperationException

B

A common alias for the queue method dequeue is a. get b. remove c. delete d. all of the above

B

A common alias for the queue method enqueue is a. put b. add c. insert d. all of the above

B

A reasonable action when attempting to remove an item from an empty stack is a. assume a precondition that the stack is not empty has been met b. throw an exception c. return null d. all of the above

B

An object of type Node that contains a data type of Node is a a. circular reference b. improper reference c. forward reference d. logic error

B

In a circular array-based implementation of a queue, what is the performance when the enqueue operation must resize the array? a. O(n^2) b. O(n) c. O(log n) d. O(1)

B

The clear method a. sets the firstNode to null b. traverses the chain and deallocating each node until it reaches the end c. returns true if it succeeds d. all of the above

B

The remove method with no arguments returns a. the first entry in the chain b. true if the method succeeds, false otherwise c. a random entry in the chain d. none of the above

B

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

B

When adding a node to a two-part circular linked chain implementation of a queue we insert the new node into the chain a. after the node that freeNode references b. before the node that freeNode references c. it has nothing to do with the location of freeNode d. none of the above

B

Which behavior(s) leave the contents of a bag unaltered? a. toArray() b. getFrequencyOf() c. isEmpty() d. all of the above

D

A two-part circular linked chain implementation of a queue a. is initialized with no available nodes b. keeps nodes that are deallocated for future use c. allocates new nodes on demand when there are no available nodes d. all of the above

C

If we use a chain of linked nodes with only a head reference to implement a queue which statement is true? a. You must traverse the entire chain to access the last node. b. Accessing the last node is very inefficient. c. Both a & b d. None of the above

C

In a linked chain implementation of a queue, when the queue is empty a. the firstNode is null b. the lastNode is null c. both a & b d. none of the above

C

In order to modify the front entry of a queue a. you need a set method defined b. you need to dequeue the front entry, modify the contents, and then use the requeue method to place it back on the front of the queue c. you cannot modify it under any circumstances d. none of the above

C

In order to resize an array to accommodate a larger bag, you must a. define an alias that references the original array b. create a new array that is larger than the original array and make the alias reference it c. copy the contents of the original array reference by the alias to the new array and discard the original array d. all of the above

C

Stacks exhibit which type of behavior? a. first-in, first out b. first-in, last out c. last-in, first out d. last-in, last out

C

The remove method for a given entry returns a. the first entry in the chain that matches or null of it is not in the chain b. the last entry in the chain that matches or null of it is not in the chain c. true if the method succeeds, false otherwise d. none of the above

C

To convert an infix expression to a postfix expression a. scan the infix expression left to right b. scan the infix expression right to left c. search for all of the operators first d. search for all of the operands first

C

What happens when a recursive method does not reach the base case? a. the program crashes b. a stack overflow occurs c. both a & b d. none of the above

C

What is an advantage of using a chain for a Bag ADT? a. It avoids moving data when adding or removing bag entries. b. It has a fixed size which is easier to manage. c. It can be resized to provide as much space as needed. d. All of the above

C

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

C

When adding a node to a two-part circular linked chain implementation of a queue a. first check if a node is already available in the chain b. check to see if the linked chain needs resized c. allocate a new node and assign the reference to freeNode d. all of the above

C

Which code correctly adds the first entry to an empty bag? a. Node newNode = new Node(newEntry); firstNode = newNode; b. Node newNode = new Node(); newNode = newEntry; firstNode = newNode; c. both a & b d. none of the above

C

A deque ADT behaves a. like a queue b. like a stack c. both a & b d. none of the above

D

A fixed size array a. has a limited capacity b. can waste memory c. prevents expansion when the bag becomes full d. all of the above

D

A stub is created for what purpose? a. to avoid syntax errors b. to avoid duplicate code c. to protect the integrity of the ADT d. to practice fail-safe programming

D

A stub should a. report that is was invoked by displaying a message b. include a return statement that returns a dummy value c. be written early for testing programs d. all of the above

D

A two-part circular linked chain implementation of a queue a. conceptually has two lists b. uses a freeNode reference for the first available node that follows the queue c. has nodes that form the queue followed by nodes that are available for use in the queue d. all of the above

D

For which of the following would a bag implementation be suitable? a. a shopping cart b. a vending machine c. a postage stamp collection d. all of the above

D

In a linked-chain implementation of a Stack ADT, when a node is popped from the stack a. the original first node will no longer be referenced b. the original first node will be deallocated c. the new first node will reference what was the second node in the chain d. all of the above

D

In a two-part circular linked chain implementation of a queue a. queueNode references the front node of the queue b. freeNode references the node that follows the queue c. the queue is empty if queueNode equals freeNode d. all of the above

D

In an array-based chain implementation of a Stack ADT, what value at the top of the stack indicated that it is empty? a. -1 b. 0 c. 1 d. null

D

In the LinkedBag implementation, the numberOfEntriesfield a. records the number of entries in the current bag b. records the number of nodes in the chain c. is set to zero in a new chain d. all of the above

D

Recursion can be used to solve problems like a. processing linked chains b. processing arrays c. sorting d. all of the above

D

The Stack ADT may be implemented with a. a linked-chain b. an array c. a vector d. all of the above

D

The activation record contains a. the method's arguments b. local variables c. a copy of the program counter d. all of the above

D

The dequeue method a. throws an exception if the queue is empty b. returns the item at the front of the queue c. removes the item at the front of the queue d. all of the above

D

Traversing a chain of linked nodes a. is easier to do recursively than iteratively b. is easier to do iteratively than recursively c. is impossible to do recursively d. is easy to do iteratively

D

What are the consequences of returning a reference to the bag array in the toArray method? a. the return variable is an alias for the private instance array variable b. the client will have direct access to the private instance array variable c. the client could change the contents of the private instance array variable without using the public access methods d. all of the above

D

Which behaviors change the contents of a bag? a. clear() b. remove() c. add() d. all of the above

D

What happened when a bag becomes full in a linked list implementation? a. An OutofMemoryError will occur. b. The add method will return false. c. A MemoryExceededException will be thrown. d. This condition is not possible with a linked list implementation.

D

What happens when you use the new operator in the LinkedBag constructor? a. a new node is created b. the JRE allocates memory for a node object c. a new object is instantiated d. all of the above

D

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

D

What question should you keep in mind when debugging a recursive method? a. Does each base case produce a result that is correct for that case? b. are there enough base cases? c. Is at least one of the cases a base case that has no recursive call? d. All of the above.

D

What question should you keep in mind when debugging a recursive method? a. Is there at least one recursive call? b. Did you consider all possible cases? c. Does the method contain a statement to test an input value and leads to different cases? d. All of the above.

D

When calling the remove method with an argument if there are multiple entries a. exactly which occurrence removed is unspecified b. only one occurrence is removed c. the first occurrence is removed d. all of the above

D

When implementing the bag ADT, which scenario could result in a security problem? a. a client attempts to create a bag whose capacity exceeds a given limit b. a SecurityException is thrown in the constructor c. an IllegalStateException is thrown in the constructor d. the delete method is implemented before the add method

D

When implementing the bag ADT, which scenario could result in a security problem? a. a constructor throw an exception or error before completing its initialization b. the programmer validates input data to a method c. generics are used to restrict data types of theentries in the collection d. a group of core methods is not defined

D

When removing a node from a chain, what case should we consider? a. the node is at the beginning of the chain b. the node is at the end of the chain c. both a and b d. none of the above

D

When removing a node from a chain, what case should we consider? a. the node is not at the beginning of the chain b. the node is at the end of the chain c. both a and b d. none of the above

D

When removing a node from a two-part circular linked chain implementation of a queue a. the entry at the front of the queue is returned b. the node is moved to the part of the chain that is available for the enqueue method c. the queueNode is advanced d. all of the above

D

When using abstraction as a design principle you should focus on: a. what you want to do with the data b. how the data is stored c. how the data is manipulated d. all of the above

D


Ensembles d'études connexes

East Asian Art & Architecture Quiz 2

View Set

Macro Gross Domestic product Module 4

View Set

Chapter 4: States of Consciousness Quiz #4

View Set

Splunk Advanced Power User Part 1

View Set