Data Structures

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

Storing a collection of elements

collection

The root interface for manipulating a collection of objects

collection interface

Java Collections supports two types of

containers: collection and map

I have implemented the queue with a circular array, keeping track of first, last, and count (count is the number of items in the array). Suppose first is zero, and last is CAPACITY-1. What can you tell me about count ? count must be zero. count could be zero or CAPACITY, but no other values could occur. None of the above. count must be CAPACITY.

count could be zero or CAPACITY, but no other values could occur.

Suppose List<String> list = new ArrayList<String>(). Which of the following operations are correct? ist.add(new Integer(100)); list.add(new ArrayList()); list.add("Red"); list.add(new java.util.Date());

list.add("Red");

stores an ordered collection of elements

lists

storing key/value pairs

map

Efficient data structures for quickly searching an element using a key

maps

Recursive methods need _____________ time and memory to execute than non recursive methods.

more

Which of the following stack operations could result in stack underflow? push pop is_empty Two or more of the above answers

pop

The operation for adding an entry to a stack is traditionally called:

push

store objects that are processed in a first-in, first-out fashion

queues

method is used to remove an element at the specified index from the list.

remove(index)

A new element can be set at the specified index using the ________________ method.

set(index, element)

The List interface extends the Collection interface and defines a collection for ?

storing elements in a sequential order

A sublist can be obtained by using the ______________________ method.

subList(fromIndex, toIndex)

data structure

supports for accessing and manipulating the data

ArrayList and LinkedList are defined under?

the List interface

The information on generics is used by the compiler but is not available at runtime.

type erasure

The Comparable interface defines the compareTo method, which is ?

used to compare two elements of the same class that implement the interface.

When implementing a linked list the addLast(e) method creates a new node to store the element and appends it to the end of the list. If the list is empty, both head and tail remove the first node will point to this new node size is increased by 1 will point to null

will point to this new node

In a priority queue, elements are assigned first with priorities at the end without priorities

with priorities

True or False: Each collection is Iterable.

True

True or False: Since the insertion and deletion operations on a stack are made only at the end of the stack, it is more efficient to implement a stack with an array list than a linked list.

True

True or False: The Collection interface extends the Iterable interface.

True

True or False: The motivation for using Java generics is to detect errors at compile time.

True

True or False: To create a data structure is to create an instance from the class.

True

True or False: To define a date structure is to define a class

True

True or False: You can obtain its Iterator object to traverse all the elements in the collection.

True

The List interface adds position-oriented operations, as well as a new list iterator that enables the user to traverse the list in which direction?

bidirectionally.

I have implemented the queue with a linked list, keeping track of tail and head. Which of these will change during an insertion into an EMPTY queue? Only tail changes. Both change. Neither changes Only head changes.

both change

Can a collection object be cloned and serialized?

Yes, all instances of Cloneable except priority queues can be cloned and all instances of Cloneable can be serialized

data structure

a collection of data organized in some fashion

method is used to insert an element at a specified index

add(index, element)

The Abstract Collection class provides partial implementation for the collection interface. It implements all the methods in Collection except

add, size, and iterator methods

The class for a data structure should use __________ _________ to store data and provide methods to support such operations as search, insertion, and deletion.

data fields

Stores a group of non duplicate elements

sets

Here is an infix expression: 4+3*(6*3-12) Suppose that we are using the usual stack algorithm to convert the expression from infix to postfix notation. What is the maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression?

4

What is a resizable-array implementation of the List interface

ArrayList

To create a list to store integers, use A. ArrayList<Object> list = new ArrayList<>(); B. ArrayList<Integer> list = new ArrayList<>(); C. ArrayList<int> list = new ArrayList<int>(); D. ArrayList<Number> list = new ArrayList<>();

B. ArrayList<Integer> list = new ArrayList<>();

If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed?

DCBA

True or False The List interface extends Collection to define an ordered collection with no duplicates allowed.

False

Ture or False The ListIterator interface extends the Iterator interface to add unidirectional traversal of the list.

False

What lets you parameterize types?

Generics

Data structures that can be used to organize and manipulate data efficiently

Java Collection Framework

stores objects that are processes in the order of their priorities

Priority Queues

True or False The List interface stores elements in sequence and permits duplicates.

True

True or False to define a data structure is to essentially define a class

True

True or False: A generic type can be defined for a class or interface. A concrete type must be specified when using the class to create an object or using the class or interface to declare a reference variable.

True

True or False: A generic type can be defined for a static method.

True

True or False: A recursive call can result in many more recursive calls, because the method keeps on dividing a subproblem into new subproblems.

True

True or False: Any problem that can be solved recursively can be solved non recursively with iterations.

True

True or False: Any recursive method can be converted into a non recursive method.

True

True or False: Both have the same performance for inserting and removing elements in the middle or at the end of the list.

True

What is the value of the postfix expression 6 3 2 4 + - *

Something between -15 and -100

Recursive programs can run out of memory, causing a _________ logic error syntax error end of file error stack overflow error

Stack flow error

store objects that are processes in a last-in, first-out fashion

Stacks

If data is a circular array of CAPACITY elements, and last is an index into that array, what is the formula for the index after last ?

(last + 1) % CAPACITY

Consider the usual algorithm for determining whether a sequence of parentheses is balanced. Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right parentheses (in some order). What is the maximum number of parentheses that will ever appear on the stack AT ONE TIME during the computation?

2

Which of the following applications may use a stack? Keeping track of local variables at run time. A parentheses balancing program. Syntax analyzer for a compiler. All of the above.

All of the above.

Which of the following statements are characteristics of recursive methods ? The method is implemented using an if-else or a switch statement that leads to different cases. One or more base cases (the simplest case) are used to stop recursion. Every recursive call reduces the original problem, bringing it increasingly closer to a base case until it becomes that case. All of these are characteristics of a recursive method

All of these are characteristics of a recursive methods

If you need to support random access through an index without inserting or removing elements at the beginning of the list choose

ArrayList

The critical difference between ArrayList and LInkedList pertains to internal implementation, which affects their performance. Explain the difference:

ArrayList is efficient for retrieving elements and LinkedList is efficient for inserting and removing elements at the beginning of the list.

To create a list, use one of its two concrete classes:

ArrayList or LinkedList.

What is a data structure to store elements in a list

Arraylist class

Given the following statement, what is the best way to find a maximum object in an array of strings ? String[] names = {"red", "green", "blue"}) Collections.max(names) Arrays.max(names) Collections.max(Arrays.asList(names)) Arrays.sort(names)

Collections.max(Arrays.asList(names))

Which of the following is a correct statement to sort the elements in a list called lst ? Collections.sort(lst) Arrays.sort(lst) new LinkedList(new String[]{"red", "green", "blue"}) lst.sort()

Collections.sort(lst)

Which of the following are true about ArrayList A. stores elements in an array. B. The array is dynamically created. C. If the capacity of the array is exceeded, a larger new array is created and all the elements from the current array are copied to the new array. D. All are true

D. All are true

_________________ occurs when method 1 invokes method 2, which in turn invokes method 1

Indirect recursion

A classic design pattern for walking through a data structure without having to expose the details of how data is stored in the data structure.

Iterator

If, however, your application requires the insertion or deletion of elements at the beginning of the list, you should choose

LinkedList.

The ArrayList class and the LinkedList class are two concrete implementations of the

List interface

One difference between a queue and a stack is: Queues use two ends of the structure; stacks use only one. Stacks require dynamic memory, but queues do not. Stacks use two ends of the structure, queues use only one. Queues require dynamic memory, but stacks do not.

Queues use two ends of the structure; stacks use only one.

You can use _________________ wildcards, bounded wildcards, or lower-bound wildcards to specify a range for a generic type.

Unbounded

What if the elements' classes do not implement the Comparable interface? Can these elements be compared?

You can define a comparator to compare the elements of different classes. To do so, define a class that implements the java.util.Comparator<T> interface and overrides its compare method.

method to insert a collection of elements at a specified index

addAll(index, collection)

If your application does not require the insertion or deletion of elements

an array

To create a data structure is therefore to create _______________________________

an instance from the class.

The listIterator() or listIterator(startIndex) method returns

an instance of ListIterator.

The Iterable interface defines the iterator method, which returns _________________

an iterator

data structure

an object that stores other objects, referred to as data or elements

In the linked list implementation of the queue class, where does the push member function place the new entry on the linked list?

at the tail

When working with generic types, if you attempt to use a class or method with an incompatible object, the compiler will ___________________.

detect the error

To declare a generic method, you place the _________________ immediately after the keyword static in the method header. instances generic type <E> actual type subtype

generic type <E>

The method is used to obtain the index of the specified element's first occurrence in the list

indexOf(element)

When implementing a linked list, the add(index, e) method

inserts an element into the list at the specified index.

When implementing a linked list, and inserting an element into the list, if index is 0, then _____________________________ remove the middle element from the list. invoke addLast(e) to insert the element at the end of the list. invoke addFirst(e) to insert the element at the beginning of the list create a new node to store the new element and locate where to insert it.

invoke addFirst(e) to insert the element at the beginning of the list

The get(i) method is available for a linked list, but it is or is not a time-consuming operation.

is a time-consuming operation.

All the interfaces and classes defined in the java Collections framework are grouped in

java.util package

the method to obtain the index of its last occurrence.

lastIndexOf(element)


Ensembles d'études connexes

NCLEX musculoskeletal and immune

View Set

Chapter 2 - The US Economy: A Global View

View Set

Pearson Test: Darwin's Theory of Evolution

View Set

The Professional Scrum Master™ level I (PSM I) Assessment: Set 2

View Set