Linked List Flashcards

1
Q

Define link list

A

An abstraction of a list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Arrays use ______ memory

A

Static memory
- Can’t grow/shrink (fixed)
- Contiguous Memory!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the BEST aspect of Arrays/ArrayLists

A

Contiguous Memory! (direct access)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the WORST aspect of Arrays/ArrayLists

A

Shifting cost! O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the BEST aspect(s) of Linked List

A

Dynamic & Shifting cost! O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the WORST aspect of Linked List

A

Not contiguous (no direct access)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the ONE job of the head of the list?

A

to POINT to the first part of the linked list!! If we ever lose the head- we will lose the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the class LinkedList do?

A

Controls the list via methods! And holds the head!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the class LLnode do?

A

Creates the object to be stored (the data) and the next field that links the nodes (the next)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

QUICK! How do we traverse a linked list if we want to adjust/print every node?

A

LLnode helpPtr = head;
while(helpPtr != null){
System.out.println(helpPtr.getData());
helpPtr = helpPtr.getNext();
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do we insert a new node into a linked list?

A
  1. Make the new LLnode object you want to insert.
  2. Determine the insertion point
    • helpPtr will point to the insertion points predecessor *
  3. Point to the new nodes successor
  4. Point to the new nodes predecessor

*This means helpPtr.next would access the successor!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do we delete a node from a linked list?

A
  1. Identify what node you are looking to delete
  2. if its the first node- we can just point head to head.next
  3. else? helpPtr should stop at the PREDECESSOR! Meaning when we loop- check helpPtr.next.data!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe the differences between a Linked list and a Doubly linked list:

A

Linked List:
- ONLY points to next
Doubly Linked List:
- Has access to PREVIOUS and NEXT!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In a doubly linked list how would we insert the object Sharron between Harry and Sam?
<- <- helpPtr*
[Harry] -> -> [Sam]*
|
[Sharron]

IN ENGLISH!

A
  1. Sharron -> Sam
  2. Sharron -> Harry
  3. Harry -> Sharron
  4. Sam -> Sharron
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In a doubly linked list how would we insert the object Sharron between Harry and Sam?
<- <- helpPtr*
[Harry] -> -> [Sam]*
|
[Sharron]

IN pseudo-CODE!

A
  1. newNode.next = helpPtr
  2. newNode.prev = helpPtr.prev
  3. helpPtr.prev.next = newNode
  4. helpPtr.prev = newNode
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In a doubly linked list how would we delete the object Harry?

         <-  helpPtr*  <- 

[Bob] -> [Harry]* -> [Sharron]

IN ENGLISH!

A
  1. Bob -> Sharron
  2. Sharron -> Bob
17
Q

In a doubly linked list how would we delete the object Harry?

         <-  helpPtr*  <- 

[Bob] -> [Harry]* -> [Sharron]

IN pseudo-CODE!

A
  1. helpPtr.prev.next = helpPtr.next
  2. helpPtr.next.prev = helpPtr.prev
18
Q

In a circular linked list… we need a ____.

A

SIZE! Because we will never visit a null node! Gotta know when we hit the technical ‘end’.