test 1

Ace your homework & exams now with Quizwiz!

When removing the last item in a doubly-linked list with both head and tail pointers, how many total pointers are updated (not including the temporary pointer to the element)?

2

Which of the following symbols do we use to specify parameter types in generic class creation ?

< >

The ArrayList class, like many other data structures, uses generics to allow it to store various data types. Which of the following statements are true regarding class level generics? Select all that apply.

A class can have fields of the generic types usedA class can have multiple type variables, which can be either bounded or unbounded

Select all of the following that are true.

A search algorithm will generally stop as soon as it finds a node containing the item searched for. Forward traversal algorithms use the next pointers of each node, and reverse traversal algorithms use the prev (previous) pointers.

Which operations below are standard operations you might want to perform with a list collection? Assume the list is not sorted

Add after (element) Peek at front Add to front Remove from front Remove (element) Peek at back Add to back Remove from back

For a generic class with type parameters defined as: public class Animal <T> { ... } Which would be an appropriate instantiation of that class of Long?

Animal<Long> dog = new Animal<Long>(); Animal<Long> dog = new Animal<>();

Given the following definition of the InfoStore class, create an InfoStore object of type String called myStore, with parameters so that store1 holds a String that says "hello" and store2 holds a String that says "bye". public class InfoStore <T extends Comparable<T>>{private T store1;private T store2; public InfoStore(T s1, T s2){store1 = s1;store2 = s2;}} InfoStore myStore = new InfoStore ( , );

Answer 1: <String>< String >< String><String >Answer 2: <String>< String >< String><String ><>< >Answer 3: "hello" "hello""hello" "hello" Answer 4: "bye" "bye""bye" "bye"

Imagine you need to keep a list of donors for a fundraising event, so that you can send thank-you cards. The 'Donor' class has name and address. You know that you will have at most 400 donors and you really don't care what order they are stored in. You aren't going to add more donors later, and the only thing you are going to do is eventually iterate the list and print out address labels. What type of list should you use?

ArrayList

Consider an ArrayList<E> with a method indexOf(E elem) that returns the position (index) of elem in the list. What is the Big O() complexity of such a method?

Big O(n)

Which of the following operations are more efficient when using a linked list than with an array list?

Delete the beginning item on the list. Add item to beginning of list (prepend).

What are generic methods ?

Generic methods introduce their own type parameters

Assuming you have an initial list L = [w -> b -> d], what is the result of the following code? (Assume that w, b, d are objects contained in nodes and -> is a link between nodes.) L.addLast(a); L.remove(b); L.set(3,c);

It will throw an exception

Imagine you want to keep a list of customer leads for your business. You want them sorted by most recent contact date, which is a property in the CustomerLead class. You are adding new customer leads every day. You also need to remove customer leads when it becomes apparent that the customer is not interested in your product. You want to be able to move customers to one end of the list when you recontact them. You want to be able to do a lot at the other end of the list where there are customers that haven't been contacted recently. What type of list should you use?

Linked list, sorted

In a linked list of n nodes with both head and tail pointers, what is the worst case complexity of the addLast(Object) operation?

O(1)

What is the Big O notation for a method that executes in constant time?

O(1)

Which of the following choices demonstrates increasing levels of complexity in Big O notation?

O(1) --> O(logN) --> O(N) --> O(NlogN) --> O(N^2)

What is the Big O notation for searching in an ArrayList?

O(N)

Which of the following Big O notations is the correct simplification of O(N+8N)?

O(N)

How would the Big O notation look for the algorithm n7+n3+nlogn+94

O(N7)

In a linked list of n nodes with both head and tail pointers, what is the worst case complexity of the add(int k, Object x) operation?

O(k)

The add(Object) operation in a sorted list with a linked implementation has what level of complexity? Assume a linear traversal algorithm is being used.

O(n)

To addToFront() operation in a list with an array implementation has what level of complexity?

O(n)

What would be the complexity of the size() method for the linked implementation of a list of n nodes, if there was no count variable?

O(n)

What is the Big O notation of the following growth function? 71 n5 + 100 n10 + 84 n3 + 33

O(n10)

Which statement about data structures is wrong?

Operations defined in a data structure can only include accessing or updating stored data, searching for specific data, inserting new data, and removing data.

Which of these is NOT one of the three standard steps to follow when selecting a data structure to solve a problem?

Run simulations to quantify the expected running time of the program

Imagine you want to keep a list of donors for a fundraising event and you want to be able to group donors by the amounts they have donated for various purposes. You are adding new donors all the time. What type of list should you use?

Singly-Linked, Sorted List

Which operations below are standard operations you might want to perform with a list collection that is sorted?

Solution add remove from back peek at back peek at front remove from front remove (element)

Which following statements are correct in terms of the relationship of data structures and algorithms?

Some algorithms utilize data structures to store and organize data during the algorithm execution.Data structures not only define how data is organized and stored, but also the operations performed on the data structure. Algorithms to implement those operations are typically specific to each data structure.

If we add a node to an empty singly-linked list, which is true about the state of the list?

The new node is the head and tail of the list.

A doubly-linked list contains the following items: Pineapple <-> Dragonfruit <-> Peach <-> Lime <-> Banana Where Pineapple is the 'head' of the list, Banana is the 'tail', and the 'count' is 5. Three searches are ran on this list: The first search looks for Peach, and follows a normal, forward traversal. The second search looks for Lime, and follows a reverse traversal (the search begins from the tail and uses the node's previous pointers) The third search looks for Watermelon, and follows a reverse traversal. How many nodes do each of these searches visit?

The search for Peach visits 3 nodes. The search for Lime visits 2 nodes. The search for Watermelon visits 5 nodes.

What is the main purpose of Big O Notation?

To represent how much an operation's time will be affected by scaling amounts of data.

Generic methods help programmers to avoid creating lots of overloaded methods and rather make one method to use any kind of data type.

True

O(4) has a _____ runtime complexity.

constant

Because a linear node holds a reference to a generic object, we call it a:

container

For an ArrayList, which of the following operations is not O(1)?

earching for an element in the list.

Big O notation is used to describe the exact execution time of an algorithm to take.

false

Type parameter (<T>) for generic methods is declared after the return type of a method.

false

Given the following class header: public class Athlete<T> { ... } And the following instantiation of the class: Athlete<Curry> curry = new Athlete<>(); What is wrong with the following method, if it is inside the Athlete class? public void addVitamin(T vitamin) { Curry c = (Curry) vitamin; c.chop(); }

he method is not generic, it only works for Curry objects

O(k)

n a linked list of n nodes with both head and tail pointers, what is the worst case complexity of the set(int k, Object x) operation?

Linked nodes have this advantage over arrays for implementing collections:

no capacity issues

Which of the following is/are correct generic method header?

public <T> void min (T [ ] array, T g, T e) { } public <T> void min (T [ ] array, int g, int e) { }

What is the correct syntax to create a class that uses a type-bound generic that must be Comparable?

public class TheClass <O extends Comparable<O>>{...}

Which of the following examples uses class generics correctly? Assume that RepositoryNode is a fully compiling class that also uses class generics.

public class WeirdDataStructure<T> { RepositoryNode<T> first; RepositoryNode<T> last; T centralVal; public WeirdDataStructure(T centermost){ centralVal = centermost; first = last = new RepositoryNode<T>(centermost); } ... }

What scenarios should be considered 'special or edge cases' when creating a method to add a node to a sorted Linked List? Hint: special cases with lists usually involve changing the head/tail references.

the node needs to go at the front of the list the node needs to go at the end of the list the list is empty

What must be true when: - last.getPrev() is null - first.getNext() is null - first == last - last != null

there is only one node in the list

An array is a data structure that stores an ordered list of items, where each item is directly accessible by a positional index.

true

It is possible to declare a multiple-bounded type parameter.

true

public <E extends Comparable<E>> void myMethod(E e1, E e2 ) {...} In the above code, E is an example of a (.......) generic.

type-bound


Related study sets

Module: Unit V – International Trade Agreements and Organizations and Regional Integration

View Set

cell biology final password is cell

View Set

Nclex Review: intracranial class quiz questions

View Set

possible multiple choice questions

View Set