LinkedList Flashcards
What interface does LinkedList implement?
LinkedList implements List, which extends from Collection
What are the LinkedList methods?
add(x) = adds item x to the
listset(x,y) = set location x to the value y
get(x) = get the item at location x
size() = returns the # of items in the list
remove() = removes an item from the list
clear() = removes all items from the list
What is a LinkedList when implementing ListNode
?
A linked list is a group of nodes. Each node contains a value and a refence to the next node in the list.
What is a Node?
A node typically has a data component and a reference to the next node.
What would be the output of: ListNode x = new ListNode("10", new ListNode("11", new ListNode("12",null))); out.println(x.getValue()); out.println(x.getNext().getNext().getValue()); out.println(x.getNext().getValue());
10
12
11
How do you remove the first node?
front = front.getNext();
this shifts the list to the next node
What is a DoubleNode?
A doubly node typically has a data component and a reference to the next node and the previous node.
Each node can go both ways
Doubly nodes can be used to make a circular linked list where the front points at the back and vice versa.
What is the Big-O Notation?
Big-O notation is an assessment of an algorithm’s efficiency. Big-O notation helps gauge the amount of work that is taking place.
List all the Big-O Notations to the LL commands:
traverse all nodes = O(N)
search for an item = O(N)
remove any item = O(N)
location unknown get any item = O(N)
location unknown add item at the end = O(N)
add item at the front = O(1)