2214 RealizeIT Module 5 Questions

Ace your homework & exams now with Quizwiz!

True or False: If a list ADT has operations like Sort or PrintReverse, the list is clearly implemented using an array.

False

True or False: The length of an array-based list equals the list's array allocation size.

False

Given a specified existing node in a singly-linked list, the _____ operation removes the node after the specified list node.

RemoveAfter

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? - Doubly-Linked, Unsorted List - Singly-Linked, Sorted List - Doubly-Linked, Sorted List - Singly-Linked, Unsorted List - ArrayList

Singly-Linked, Sorted List

True or False: An array-based list can have a default allocation size of 0.

False

The _____ operation for a doubly-linked list removes a provided existing list node.

Remove

Select all of the following that are true. - Forward traversal algorithms use the next pointers of each node, and reverse traversal algorithms use the prev (previous) pointers. - A search algorithm will generally stop as soon as it finds a node containing the item searched for. - A list must contain at least two nodes before traversal algorithms will function. - By default, a search algorithm will fail and throw an exception if the item searched for is not present in the list. - Doubly-linked lists allow for forward traversal algorithms to work, unlike singly-linked lists. - Both singly and doubly linked lists can run both forward and reverse traversal algorithms.

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

Which operations below are standard operations you might want to perform with a list collection? Assume the list is not sorted - Peek at back - Add to back - Add to front - Remove from front - Peek at front - Remove (element) - Add after (element) - Remove from back

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

Which operations below are standard operations you might want to perform with a list collection that is sorted? - remove (element) - add - remove from back - add to front - peek at front - remove from front - peek at back - Add to back

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

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 sorts into the middle of the list - the node needs to go at the end of the list - the list is empty - if the node's element is the same datatype as the others - 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 - the node needs to go at the front of the list

If you have a double-linked list and you remove the last item in the list, how many pointers are updated (not including the temp pointer to the element)? - 1 - 3 - 4 - 2

2

Type the list after the given operations. Each question starts with an empty list. Type the list as: 5, 7, 9 2) - Append (list, 3) - Append (list, 2) - Append (list, 1) - Remove (list, 3)

2, 1

Type the list after the given operations. Each question starts with an empty list. Type the list as: 5, 7, 9 1) - Append (list, 3) - Append (list, 2)

3, 2

Given a list with items 40, 888, -3, 2, what does GetLength(list) return?

4

Given the following code that creates and initializes a LinkedList: LinkedList<String> wordsFromFile = new LinkedList<String>(); wordsFromFile.add("The"); wordsFromFile.add("fowl"); wordsFromFile.add("is"); wordsFromFile.add("the"); wordsFromFile.add("term"); At what index does the following statement insert the word "end"? Enter a number. wordsFromFile.add("end");

5

Given the following code that creates and initializes a LinkedList: LinkedList<String> wordsFromFile = new LinkedList<String>(); wordsFromFile.add("The"); wordsFromFile.add("fowl"); wordsFromFile.add("is"); wordsFromFile.add("the"); wordsFromFile.add("term"); Given the original list initialization above, how many elements does wordsFromFile contain after the following statement? Enter a number. wordsFromFile.add(4, "big");

6

Given a new node, the _____ operation for a doubly-linked list inserts the new node after the list's tail node.

Append

Given a new node, the _____ operation for a singly-linked list inserts the new node after the list's tail node.

Append

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 - Doubly-Linked, Sorted list - Sorted List - Singly-Linked List

ArrayList

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? - ArrayList - Doubly-linked list, unsorted - Doubly-linked list, sorted - Singly-linked list, unsorted - Singly-linked list, sorted

Doubly-linked list, sorted

Given a new node, the _____ operation for a singly-linked list inserts the new node after provided existing list node.

InsertAfter

Given a new node, the ______ operation for a doubly-linked list inserts the new node after a provided existing list node.

InsertAfter

After the following operations will Search(list, 2) find an item? - Append(list, 3) - Append(list, 2) - Append(list, 1) - Remove(list, 2)

No, After the appends, the list is 3, 2, 1. After the remove, the list is 3, 1. So 2 will not be found.

What would be the complexity of the size() method for the linked implementation of a list, if there was no count variable? -O(log n) -O(n) -O(n^2) -1

O(n)

Given a new node, the _____ operation for a singly-linked list inserts the new node before list's head node.

Prepend

Given a new node, the _____ operation of a doubly-linked list inserts the new node before the list's head node and points the head pointer to the new node.

Prepend

A doubly-linked list contains the following items: 838 <-> 764 <-> 637 <-> 188 <-> 937 Where 838 is the 'head' of the list, 937 is the 'tail', and the 'count' is 5. Three searches are ran on this list: 1. The first search looks for 637, and follows a normal, forward traversal. 2. The second search looks for 188, and follows a reverse traversal (the search begins from the tail and uses the node's previous pointers) 3. The third search looks for 520, and follows a reverse traversal. How many nodes do each of these searches visit? - The search for 637 visits 2 nodes./The search for 188 visits 3 nodes./The search for 520 visits 6 nodes. - The search for 637 visits 4 nodes./The search for 188 visits 3 nodes./The search for 520 visits 5 nodes. - The search for 637 visits 3 nodes./The search for 188 visits 2 nodes./The search for 520 visits 6 nodes. - The search for 637 visits 3 nodes./The search for 188 visits 2 nodes./The search for 520 visits 5 nodes. - None of these searches will be able to run, as searches do not function on doubly-linked lists.

The search for 637 visits 3 nodes. The search for 188 visits 2 nodes. The search for 520 visits 5 nodes.

True or False: An item can be appended to an array-based list, provided the length is less than the array's allocated size.

True

True or False: Given a list with items 'Z', 'A', 'B', Sort(list) yields 'A', 'B', 'Z'.

True

What is the contents of list, after the following code is run? Assume list was initialized to hold strings. list.add("a"); list.add("w"); list.add("d"); list.add("c"); list.remove(0); list.remove(2); - ["w" "c"] - ["a" "c"] - ["a" "d"] - ["w" "d"] - ["a" "w"] - ["d" "c"]

["w" "d"]

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

[a->y->x]

Assume you are adding an item 'F' to the end of this list. You have created a new linear node called temp that contains a pointer to 'F'. What lines of code appropriately update the list? - back = temp; back.setNext(temp); numNodes++; - back.setNext(temp); back = temp; numNodes++; - back = temp; back.getNext(setNext(temp); numNodes++; - back.getNext(setNext(temp); back = temp; numNodes++;

back.setNext(temp); back = temp; numNodes++;

Given the following code that creates and initializes a LinkedList: LinkedList<Double> accelerometerValues = new LinkedList<Double>(); accelerometerValues.add(9.8); accelerometerValues.add(10.2); accelerometerValues.add(15.4); Complete the statement to assign currentValue with the element at index 2. currentValue = accelerometerValues._______

get(2)

Answer the questions given the following code that creates and initializes a LinkedList and a ListIterator. For every question, assume that the ListIterator is located before the first list element (i.e., the starting position). LinkedList<Integer> numbersList = new LinkedList<Integer>(); ListIterator<Integer> numberIterator; numbersList.add(3); numbersList.add(1); numbersList.add(4); numberIterator = numbersList.listIterator(); What value does numberIterator.hasNext() return after three calls to numberIterator.next().

false

Given numList is: 5, 8, 2, 1. ListTraverse(numsList) visitis _____ nodes(s) - one - two - four

four

Given the following code that creates and initializes a LinkedList: LinkedList<Double> accelerometerValues = new LinkedList<Double>(); accelerometerValues.add(9.8); accelerometerValues.add(10.2); accelerometerValues.add(15.4); Complete the statement to print the first list element. System.out.println(accelerometerValues._______ );

get(0)

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

it will throw an exception

A _________ algorithm visits all nodes in the list once and performs an operation on each node.

list traversal

Type the list after the given operations. Type the list as: 5, 7, 9 numsList: 1 ListInsertAfter(numsList, node 1, node 6) ListInsertAfter(numsList, node 1, node 4)

numsList: 1, 4, 6

Type the list after the given operations. Type the list as: 4, 19, 3 numsList: 10, 20, 30, 40, 50, 60 ListRemoveAfter(numsList, node 40) ListRemoveAfter(numsList, node 20)

numsList: 10, 20, 40, 60

Type the list after the given operations. Type the list as: 4, 19, 3 numsList: 2, 5, 9 ListRemoveAfter(numsList, node 5)

numsList: 2, 5

Type the list after the given operations. Type the list as: 5, 7, 9 numsList: 23, 17, 8 ListInsertAfter(numsList, node 23, node 5)

numsList: 23, 5, 17, 8

Type the list after the given operations. Type the list as: 5, 7, 9 numsList: 5, 9 ListInsertAfter(numsList, node 9, node 4)

numsList: 5, 9, 4

Type the list after the given operations. Type the list as: 4, 19, 3 numsList: 3, 57, 28, 40 ListRemoveAfter(numsList, null)

numsList: 57, 28, 40

Type the list after the given operations. Type the list as: 5, 7, 9 numsList: 77 ListInsertAfter(numsList, node 77, node 32) ListInsertAfter(numsList, node 32, node 50) ListInsertAfter(numsList, node 32, node 46)

numsList: 77, 32, 46, 50

Type the list after the given operations. Type the list as: 4, 19, 3 numsList: 91, 80, 77, 60, 75 ListRemoveAfter(numsList, node 60) ListRemoveAfter(numsList, node 77) ListRemoveAfter(numsList, null)

numsList: 80, 77

Type the list after the given operations. Type the list as: 4, 19, 3 numsList: 9, 4, 11, 7 ListRemoveAfter(numsList, node 11)

numsList: 9, 4, 11

A __________ visits all nodes starting with the list's tail node and ending after visiting the list's head node.

reverse traversal

Given a key, a _______ algorithm returns the first node whose data matches that key, or returns null if a matching node was not found.

search

What must be true when: - last.getPrev() is null - first.getNext() is null - first == last - last != null + there are 0 nodes in the list + there is only one node in the list + first == null + there are only two nodes of the same element

there is only one node in the list

Answer the questions given the following code that creates and initializes a LinkedList and a ListIterator. For every question, assume that the ListIterator is located before the first list element (i.e., the starting position). LinkedList<Integer> numbersList = new LinkedList<Integer>(); ListIterator<Integer> numberIterator; numbersList.add(3); numbersList.add(1); numbersList.add(4); numberIterator = numbersList.listIterator(); What does numberIterator.hasNext() return the first time?

true

Each node in a doubly-linked list contains data and ____ pointer(s).

two

Given the following code that creates and initializes a LinkedList: LinkedList<String> wordsFromFile = new LinkedList<String>(); wordsFromFile.add("The"); wordsFromFile.add("fowl"); wordsFromFile.add("is"); wordsFromFile.add("the"); wordsFromFile.add("term"); Write a statement to insert the word "not" between the elements "is" and "the".

wordsFromFile.add(3, "not");


Related study sets

Intro to Kinesiology ch 10 butte college

View Set

MODULE 4: ADVENT OF A NATIONAL HERO

View Set

Chapter 03: Gross Income: Inclusions and Exclusions

View Set

Chapter 33: Coronary Artery Disease and Acute Coronary Syndrome

View Set