ITSC 2214 Test 2 Chapters 5-7
Use the following declarations to answer the question: String s1 = "Sticky Rice"; String s2 = "STICKY" String s3 = "sticky"
!(s2.compareTo(s3) == 0) && (s3.compareTo(s2) > 0)
Number of comparisons for an insertion sort algorithm given a length of N is ___
(N - 1) * (N/2)
binary search middle is calculated by:
(low_index + high_index)/2 > remember that / drops the fraction so (0 + 5)/2 = 2
The important thing to understand about linked nodes are:
1. They are not necessarily stored contiguously in memory, the way that arrays are 2. They don't provide random access through indexing. You typically have to traverse a set of nodes to get to a specific node 3. If you need to insert a node in the middle of a linked node structure (such as a linked list), it is much easier to do than in an array, because you don't need to shift all the other elements over
Answer the following questions assuming each comparison takes 1 µs. Given a list of 1024 elements, what is the runtime for linear search if the search key is less than all elements in the list?
1024 > Linear search assumes the elements are not sorted and will check all elements if the key is not found. Thus, linear search's runtime is proportional to the number of list elements.
Answer the following questions assuming each comparison takes 1 µs. Given a list of 1024 elements, what is the runtime for binary search if the search key is less than all elements in the list?
11 Binary search's runtime is proportional to log (base two) of the number of list elements. [log₂1024] + 1 = 11
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)?
2
Given sorted list: { 4 11 17 18 25 45 63 77 89 114 }. How many list elements will be checked to find the value 77 using binary search?
2 > Binary search first checks the value 25 at index 4 ((0+9)/2 = 4), then searches the right sublist at index 7 ((5+9)/2 = 7) finding the value 77.
Assume you have a linked list data structure with n nodes. It is a singly-linked list that supports generics, so it can hold any type of object. How many references are in this data structure, including references that are null?
2n + 1
Given sorted list: { 4 11 17 18 25 45 63 77 89 114 }. How many list elements will be checked to find the value 17 using binary search?
3 > Binary search first checks the value 25 at index 4 ((0+9)/2 = 4), then searches the left sublist at index 1 ((0+3)/2 = 1), and then searches the right sublist at index 2 ((2+3)/2 = 2), finding the value 17.
Given sorted list: { 4 11 17 18 25 45 63 77 89 114 }. Given an array with 32 elements, how many list elements will be checked if the key is less than all elements in the list, using binary search?
5 > Binary search checks indices 15, 7, 3, 1, and 0. After checking index 0, the algorithm returns -1, indicating the key was not found.
1) Given numQueue: 5, 9, 1 (front is 5) What are the queue contents after the following push operation? Type the queue as: 1, 2, 3 Push(numQueue, 4)
5, 9, 1, 4
Given the following code using a queue X: X.enqueue(new Integer(4)); X.enqueue(new Integer(3)); Integer y = X.dequeue(); X.enqueue(new Integer(7)); X.enqueue(new Integer(2)); X.enqueue(y); X.enqueue(new Integer(9)); y = X.dequeue(); X.enqueue(new Integer(3)); X.enqueue(new Integer(8)); What is the value returned by X.first()?
7
If you have a queue with 700 items in it, how many linear nodes would be in use?
700
Remove singly-linked list head node (special case):
> If curNode is null, the algorithm points sucNode to the head node's next node, and points the list's head pointer to sucNode. > If sucNode is null, the only list node was removed, so the list's tail pointer is pointed to null (indicating the list is now empty).
Remove node after curNode in singly-linked list:
> If curNode's next pointer is not null (a node after curNode exists), the algorithm points sucNode to the node after curNode's next node. > Then curNode's next pointer is pointed to sucNode. If sucNode is null, the list's tail node was removed, so the algorithm points the list's tail pointer to curNode (the new tail node).
LinkedList vs. ArrayList
> LinkedList and ArrayList are ADTs implementing the List interface. > Although both LinkedList and ArrayList implement a List, a programmer should select the implementation that is appropriate for the intended task. > A LinkedList typically provides faster element insertion and removal at the list's ends (and middle if using ListIterator), whereas an ArrayList offers faster positional access with indices.
A common approach for implementing a linked list is using two data structures:
> List data structure > List node data structure
Comparable
> declares the compareTo() method > Classes implementing the Comparable interface must define a custom implementation of the compareTo() method
A special node named ___ is created to ___ after which regular items can be inserted
> head > represent the front of the list
List
> interface defined within the Java Collections Framework defines a Collection of ordered elements, i.e., a sequence. > The List interface supports methods for adding, modifying, and removing elements.
You create a class called DogLeash and you want collections containing DogLeash objects to be ordered by the length of the leash. What do you need to do with your class in order to make this possible? Choose all that apply.
> make the DogLeash class implement the Comparable interface > Include a getter for the leashLength property > Include a leashLength property > add a compareTo() method that compares two dog leashes based on the leashLength property
bubble sort:
> repeatedly swaps adjacent elements if they are in wrong order > a pass is completed once the last element is compared, then algorithm then starts another pass, repeating the same procedure, adding additional passes until no swaps are made and the list is in order Example: First Pass ( 5 1 4 2 8 ) -> ( 1 5 4 2 8 ) ( 1 5 4 2 8 ) -> ( 1 4 5 2 8 ) ( 1 4 5 2 8 ) -> ( 1 4 2 5 8 ) ( 1 4 2 5 8 ) -> ( 1 4 2 5 8 ) Second Pass ( 1 4 2 5 8 ) -> ( 1 4 2 5 8 ) ( 1 4 2 5 8 ) -> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) -> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) -> ( 1 2 4 5 8 )
Which of the following methods is a valid compareTo() method for comparing Employee objects based on the numYears property, which indicates how long the employee has been with the company? @override public int compareTo(Employee e) { if (e.getNumYears() > this.getNumYears()) return -1; if (e.getNumYears() < this.getNumYears()) return 1; return 0; } @override public int compareTo(Object o) { if (o.numYears > this.numYears) return -1; if (o.numYears < this.numYears) return 1; return 0; } @override public int compareTo(Employee e) { if (e.getNumYears() > this.numYears) return -1; if (e.getNumYears() < this.numYears) return 1; return 0; } @override public int compareTo(Object o) { Employee e = (Employee) o; if (e.numYears > this.numYears) return -1; if (e.numYears < this.numYears) return 1; return 0; } @override public int compareTo(Object o) { if (! (o instanceof Employee) return 0; Employee e = (Employee) o; if (e.getNumYears() > this.numYears) return -1; if (e.getNumYears() < this.numYears) return 1; return 0; }
@override public int compareTo(Employee e) { if (e.getNumYears() > this.getNumYears()) return -1; if (e.getNumYears() < this.getNumYears()) return 1; return 0; } @override public int compareTo(Employee e) { if (e.getNumYears() > this.numYears) return -1; if (e.getNumYears() < this.numYears) return 1; return 0; } @override public int compareTo(Object o) { if (! (o instanceof Employee) return 0; Employee e = (Employee) o; if (e.getNumYears() > this.numYears) return -1; if (e.getNumYears() < this.numYears) return 1; return 0; }
List data structure
A list data structure, called a header node, is a data structure containing the list's head and tail, and may also include additional information such as the list's size
Which of the following operations are more efficient when using a linked list than with an array list?
Add item to beginning of list (prepend). Insert item into middle of list.
Which operations below are standard operations you might want to perform with a list collection? Assume the list is not sorted
Add to front Remove from back Peek at front Remove (element) Peek at back Add after (element) Remove from front Add to back
LinkedList.add(index, newElement)
Adds newElement to the List at the specified index. Indices of the elements previously at that specified index and higher are increased by one. List's size is increased by one.
LinkedList.add(newElement)
Adds newElement to the end of the List. List's size is increased by one.
ListIterator.add(newElement)
Adds the newElement between the next and previous elements and moves the ListIterator after newElement.
What is the best, average and worst case for linear search, assuming you want to know if target is in the collection?
Best case: target is first item in collection Average case: target is found halfway through iteration of collection Worst case: target is not found in collection
Which of the following are not true when working with linked list Queues?
Can view any element if you have the index Can add at any index point
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?
Doubly-linked list, sorted
node
Each item in a list ADT
A queue processes elements in a _____ manner.
FIFO
In the linear search, the elements should be in a particular order within the array.
False
The top variable keeps track of the number of elements in a LinkedStack implementation
False
A linked list must have a header node
False > A header node is optional. A programmer can alternatively use variables to maintain a list's head and tail, or size. Header nodes are a convenient structure for managing a list's head and tail.
The following statement sorts an ArrayList called prevEmployees. Assume prevEmployees is an appropriately initialized ArrayList of EmployeeData elements. sort(prevEmployees); (True/False)
False sort() is a static method. Therefore, both the Collections class name and a dot should be appended before the method call, as in Collections.sort(prevEmployees)
Given that parkingQueue has no items (i.e., is empty), what does GetLength(parkingQueue) return?
If 0 items exist, length is 0
Remove operation, Removing list's head node:
If curNode points to the list's head node, the algorithm points the list's head pointer to the successor node
Remove operation, Removing list's tail node:
If curNode points to the list's tail node, the algorithm points the list's tail pointer to the predecessor node
Insert in middle of doubly-linked list:
If the list's head pointer is not null (list is not empty) and curNode does not point to the list's tail node, the algorithm updates the current, new, and successor nodes' next and previous pointers to achieve the ordering {curNode newNode sucNode}, which requires four pointer updates: point the new node's next pointer to sucNode, point the new node's previous pointer to curNode, point curNode's next pointer to the new node, and point sucNode's previous pointer to the new node.
Insert after doubly-linked list tail node:
If the list's head pointer is not null (list is not empty) and curNode points to the list's tail node, the new node is inserted after the tail node. The algorithm points the tail node's next pointer to the new node, points the new node's previous pointer to the list's tail node, and then points the list's tail pointer to the new node.
Insert in middle of singly-linked list:
If the list's head pointer is not null (list not empty) and curNode does not point to the list's tail node, the algorithm points the new node's next pointer to curNode's next node, and then points curNode's next pointer to the new node.
Insert after singly-linked list tail node:
If the list's head pointer is not null (list not empty) and curNode points to the list's tail node, the algorithm points the tail node's next pointer and the list's tail pointer to the new node.
Prepend to non-empty singly-linked list:
If the list's head pointer is not null (not empty), the algorithm points the new node's next pointer to the head node, and then points the list's head pointer to the new node.
Prepend to non-empty doubly-linked list:
If the list's head pointer is not null (not empty), the algorithm points the new node's next pointer to the list's head node, points the list head node's previous pointer to the new node, and then points the list's head pointer to the new node
Append to non-empty singly-linked list:
If the list's head pointer is not null (not empty), the algorithm points the tail node's next pointer and the list's tail pointer to the new node
Append to non-empty doubly-linked list:
If the list's head pointer is not null (not empty), the algorithm points the tail node's pointer to the new node, points the new node's previous pointer to the list's tail node, and points the list's tail pointer to the new node.
Append to empty singly-linked list:
If the list's head pointer is null (empty), the algorithm points the list's head and tail pointers to the new node
Prepend to empty doubly-linked list:
If the list's head pointer is null (empty), the algorithm points the list's head and tail pointers to the new node
Append to empty doubly-linked list:
If the list's head pointer is null (empty), the algorithm points the list's head and tail pointers to the new node.
Prepend to empty singly-linked list:
If the list's head pointer is null (empty), the algorithm points the list's head and tail pointers to the new node.
Insert as first node in doubly-linked list:
If the list's head pointer is null (list is empty), the algorithm points the list's head and tail pointers to the new node.
Insert as singly-linked list first node:
If the list's head pointer is null, the algorithm points the list's head and tail pointers to the new node.
Remove operation, Predecessor exists:
If the predecessor node pointer is not null (predecessor exists), the algorithm points the predecessor's next pointer to the successor node
Remove operation, Successor exists:
If the successor node pointer is not null (successor exists), the algorithm points the successor's previous pointer to the predecessor node
Which of the following sort algorithms has this sorting strategy: Sort the first two values in the list Insert the list's third value into the appropriate position relative to the first two sorted values Insert the list's fourth value into its proper position relative to the first three sorted values Continue this process until all the values in the list are completely sorted
Insertion Sort
InsertAfter(list, w, x)
Inserts x after w
Append(list, x)
Inserts x at end of list
Push(queue, x)
Inserts x at end of the queue Ex. Push(queue, 56). Queue: 43, 12, 77, 56
Prepend(list, x)
Inserts x at start of list
Number of comparisons for a selection sort algorithm given a length of N is ___
N * (N/2)
For the following code, what is returned? public String testQueue() throws EmptyCollectionException { String s; Queue<String> queue = new ArrayQueue<Integer>(); queue.add("a"); queue.add("b"); s = queue.remove(); s = queue.remove(); queue.add("c"); queue.add("d"); s = queue.remove(); s = queue.remove(); return s; }
Nothing, the code won't compile. Nothing, an exception is thrown.
The runtime for nearly sorted inputs with C unsorted elements and a length N is __
O((N - C) * 1 + C * N) = O(N)
The addLast(Object) operation in a list implemented with an array has Big O complexity of:
O(1)
The selection sort algorithm runtime is ___
O(N)^2
Insertion sort's typical runtime is ___
O(N^2)
What would be the Big O Complexity for a Bubble Sort method?
O(N^2)
The worst case number of comparisons you will have to do in binary search is:
O(log(n))
The add(int, Object) operation in a list with a linked implementation has what level of complexity?
O(n)
The complexity of a set(index, Object) operation using a linked list implementation of a list is:
O(n)
What would be the complexity of the size() method for the linked implementation of a list, if there were no count variable?
O(n)
Print(list)
Prints list's items in order
PrintReverse(list)
Prints list's items in reverse order
Will of the following lines of code wll compile (assume all needed files have been imported)?
Queue strings = new LinkedList(); Queue strings = new LinkedList< />();
LinkedList creation code:
Queue<T> queue = new LinkedList<T>(); or LinkedList<T> linkedList = new LinkedList<T>();
LinkedList.remove(index)
Removes element at specified index. Indices for elements from higher positions are decreased by one. List size is decreased by one. Returns reference to element removed from List.
ListIterator.remove()
Removes the element returned by the prior call to next() or previous(). Fails if used more than once per call to next() or previous(). Fails if add() has already been called since the last call to next() or previous().
LinkedList.remove(existingElement)
Removes the first occurrence of an element which is equal to existingElement. Indices for elements from higher positions are decreased by one. List size is decreased by one. Returns true if specified element was found and removed.
Remove(list, x)
Removes x
LinkedList.set(index, newElement)
Replaces element at specified index with newElement. Returns element previously at specified index.
ListIterator.set(newElement)
Replaces the element returned by the prior call next() or previous() with newElement.
Pop(queue)
Returns and removes item at front of queue Ex. Pop(queue) returns: 43. Queue: 12, 77
Peek(queue)
Returns but does not remove item at the front of the queue Ex. Peek(queue) return 43. Queue: 43, 12, 77
LinkedList.get(index)
Returns element at specified index.
Search(list, x)
Returns item if found, else returns null
ListIterator.nextIndex()
Returns the index of the next element.
ListIterator.previousIndex()
Returns the index of the previous element.
ListIterator.next()
Returns the next element in the List and moves the ListIterator after that element.
LinkedList.size()
Returns the number of elements in the List.
GetLength(queue)
Returns the number of items in the queue Ex. GetLength(queue) returns 3
ListIterator.previous()
Returns the previous element in the List and moves the ListIterator before that element.
ListIterator.hasNext()
Returns true if ListIterator has a next element. Otherwise, returns false.
ListIterator.hasPrevious()
Returns true if ListIterator has a previous element. Otherwise, returns false.
IsEmpty(queue)
Returns true if queue has no items Ex. IsEmpty(queue) returns false
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
Sort(list)
Sorts the lists items in ascending order
What is the purpose of a list's head node?
The head refers to the first item's node, or refers to nothing if the list is empty.
List node data structure
The list node data structure maintains the data for each list element, including the element's data and pointers to the other list element
After the above list has items inserted as above, if a fourth item was inserted at the front of the list, what would happen to the location of node1?
The object does not have to be moved; only a few reference values change.
After each step in a binary search, what is true?
The searchable collection size decreases by half.
A header node can have additional information besides the head and tail pointers.
True > A list header commonly stores the list size and other data associated with the list itself and not the list nodes.
A linked list has O(n) space complexity, whether a header node is used or not.
True > If a header node is used, O(1) space is needed for the single header node. O(n) + O(1) = O(n).
StackPop points a local variable to the list's head node. (T/F)
True > Removing the head node from the list would otherwise "lose" the head node. The local variable ensure the head node is remembered and can thus be returned at the end of StackPop.
The list is sorted into descending order: {F D C B A} (True/False)
True > The list of characters are in reverse alphabetical order.
The list is sorted into ascending order: {chopsticks forks knives spork} (True/False)
True > The list of strings are in alphabetical order.
You can use the enhanced for loop (shown below) to do a linear search through the elements in a collection. Assume that Datatype implements Comparable and target is of type Datatype. for (Datatype var : Collection) { if (var.compareTo(target) == 0 ) { return true; } }
True, as long as you don't need to return an index of where the target is located
What is the most common way to optimize bubble sort?
Work backwards from the end of the list
When performing a binary search, should the list be pre-sorted?
Yes
What differentiates lists from queues?
You can add and retrieve items from the middle.
list node
a class defined to represent each list item
list
a common ADT for holding ordered data, having operations like append a data item, remove a data item, search whether a data item exists, and print the list
header node
a data structure containing the list's head and tail, and may also include additional information such as the list's size
singly-linked list
a data structure for implementing a list ADT, where each node has data and a pointer to the next node
doubly-linked list
a data structure for implementing a list ADT, where each node has data, a pointer to the next node, and a pointer to the previous node > first node is called the head, and the last node the tail > typically points to the first node and the last node
abstract data type
a data type described by pre-defined user operations, such as "insert data at rear," without indicating how each operation is implemented
Binary search
a faster algorithm for searching a list if the list's elements are sorted and directly accessible (such as an array). > Binary search first checks the middle element of the list. > If the search key is found, the algorithm returns the matching location. > If the search key is not found, the algorithm repeats the search on the remaining left sublist (if the search key was less than the middle element) or the remaining right sublist (if the search key was greater than the middle element).
Linear search
a search algorithm that starts from the beginning of a list, and checks each element until the search key is found or the end of the list is reached
algorithm
a sequence of steps for accomplishing a task
Insertion sort
a sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly inserts the next value from the unsorted part into the correct location in the sorted part
Selection sort
a sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly selects the proper next value to move from the unsorted part to the end of the sorted part > The index variable i denotes the dividing point. Elements to the left of i are sorted, and elements including and to the right of i are unsorted. All elements in the unsorted part are searched to find the index of the element with the smallest value. The variable indexSmallest stores the index of the smallest element in the unsorted part. Once the element with the smallest value is found, that element is swapped with the element at location i. Then, the index i is advanced one place to the right, and the process repeats. > The term "selection" comes from the fact that for each iteration of the outer loop, a value is selected for position i.
queue add()
add(newElement) > Adds newElement element to the tail of the queue. The queue's size increases by one.
Queue's add() method
adds an element to the tail of the queue and increases the queue's size by one
LinkedList
an ADT implemented as a generic class that supports different types of elements
queue
an ADT in which items are inserted at the end of the queue and removed from the front of the queue
ListIterator
an object that points to a location in a List and provides methods to access an element and advance the ListIterator to the next position in the list
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.setNext(temp); back = temp; numNodes++;
A queue is appropriate for which of the following domains:
call center call processing
compareTo(otherComparable)
compares a Comparable object to otherComparable, returning a number indicating if the Comparable object is less than, equal to, or greater than otherComparable > returns 0 if the two Comparable objects are equal > returns a negative number if otherComparable is greater than the Comparable object > returns a positive number if the Comparable object is greater than otherComparable
What type of operation is most critical to count when looking at efficiency of sorting?
comparisons
node
comprised of the data to be stored in each list item
Because a linear node holds a reference to a generic object, we call it a:
container
Assume you have a stack implemented with single-linked nodes, that looks like this: 8 -> 17 -> 23 -> 93 -> 66 'top' is a reference variable that points to the node containing 8. 'count' is an internal int that holds the count of nodes (currently 5) If you want to do push operation with the value 19, what is the pseudocode to achieve this?
create single linked node called temp set temp's element pointer to 19 set temp's next pointer to be the same as top set top to point at temp increment count
queue element()
element() > Returns, but does not remove, the element at the head of the queue. Throws an exception if the queue is empty.
Single-linked nodes
have a reference pointer to an object as well as a pointer to another node
Double-linked nodes
have a reference pointer to an object, a pointer to the previous node and a pointer to the next node
When using a Queue implemented with Linked Nodes how would you gain access to the element of the second node in the list?
head.getNext().getElement();
import LinkedList code:
import java.util.LinkedList;
LinkedList and Queue import code:
import java.util.LinkedList; import java.util.Queue;
import ListIterator code:
import java.util.ListIterator;
programmer must append the class name ___
in angle brackets to "Comparable", as in Comparable<EmployeeData>, in order to tell the compiler that the compareTo() method requires an argument of the indicated class type
null
indicates that a reference variable does not refer to any object
queue push
inserts an item at the end of the queue
InsertAfter operation for a doubly-linked list
inserts the new node after a provided existing list node
the InsertAfter operation for a singly-linked list ___
inserts the new node after a provided existing list node
Append operation for a doubly-linked list
inserts the new node after the list's tail node
Append operation for a singly-linked list
inserts the new node after the list's tail node
the Prepend operation for a singly-linked list ___
inserts the new node before the list's head node
Prepend 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.
interfaces cannot be ___
instantiated and the methods declared by an interface must be overridden and defined by the implementing class
Queue
interface defined within the Java Collections Framework defines a Collection of ordered elements that supports element insertion at the tail and element retrieval from the head
If the head pointer is null, the queue ___
is empty > A value of null indicates that the pointer points to nothing, so the queue is empty.
first-in first-out ADT
items are inserted at the end of the queue and removed from the front
implements
keyword tells the compiler that a class implements, instead of extends, a particular interface
nearly sorted
list only contains a few elements not in sorted order. Ex: {4, 5, 17, 25, 89, 14} is nearly sorted having only one element not in sorted position
Linked nodes have this advantage over arrays for implementing collections:
no capacity issues
An empty stack is indicated by a list head pointer value of ___
null
queue peek()
peek() > Returns, but does not remove, the element at the head of the queue if the queue is not empty. Otherwise, returns null.
Which of the following methods allows you to return the head from a Queue, removing it and not throw an exception if the Queue is empty?
poll()
queue poll()
poll() > Removes and returns the element at the head of the queue if the queue is not empty. Otherwise, returns null.
uppercase letters ___ lowercase letters when considering alphabetical order
precede
An algorithm typically uses a number of steps ___
proportional to the size of the input
Collections
provides static methods that operate on various types of lists such as an ArrayList
Which operations below are standard operations you might want to perform with a list collection that is sorted?
remove from back remove from front remove (element) add peek at back peek at front
queue remove()
remove() > Removes and returns the element at the head of the queue. Throws an exception if the queue is empty.
Which Java queue operations throw exceptions?
remove() element()
Queue's remove() method
removes AND RETURNS the element at the head of the queue
Remove operation for a doubly-linked list
removes a provided existing list node
queue pop
removes and returns the item at the front of the queue
Given a specified existing node in a singly-linked list, the RemoveAfter operation ___
removes the node after the specified list node
search algorithm
returns the first node whose data matches the key, or returns null if a matching node was not found
There are two main types of linear nodes:
singly-linked and doubly-linked
head
singly-linked list's first node
tail
singly-linked list's last node
sort() method
sorts collections into ascending order provided that the elements within the collection implement the Comparable interface > calls the compareTo() method on each object within the ArrayList to determine the order and produce a sorted list
linked nodes (linear nodes)
structures that just allow you to link objects together
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 list is empty the node needs to go at the front of the list the node needs to go at the end of the list
Java supports automatic conversion of an object, e.g., LinkedList, to a reference variable of an interface type, e.g., Queue, as long as ___
the object implements the interface
Sorting
the process of converting a list of elements into ascending (or descending) order
runtime
the time the algorithm takes to execute
list traversal algorithm:
visits all nodes in the list once and performs an operation on each node
reverse traversal algorithm:
visits all nodes starting with the list's tail node and ending after visiting the list's head node > only supported by doubly-linked list
data structure
way of organizing data, commonly used to implement an abstract data type (ADT), and often involving arrays or pointers
to interact with a LinkedList by index ___
you have to iterate through each reference from 0 to the index, since the next reference needs to be checked to find the next item in the LinkedList
Given the following unsorted collection: {87, 12, -14, 28, 167, -455} What will the collection look like after the first iteration of bubble sort?
{12, -14, 28, 87, 167, -455}