Week 9: Linked Lists Flashcards

1
Q

Nodes for a linked list will be _____ dynamically created or deleted in the ______

A

Nodes for a linked list will be OBJECTS dynamically created or deleted in the HEAP

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

In SINGLY linked lists, nodes will contain:

A

Two member variables:

  • Item value
  • NODE* next
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In node objects, data objects can be either

A

Simple or complex data structures

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

For singly linked lists. If you have a LIST structure, you should keep track of the _____ and ____

A

Head node and count

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

A createList() function should take in what parameter?

A

void

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

A createList() function has what return type?

A

LIST*

list pointer

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

A createList() function does what after dynamically creating the list?

A

Have an if statement checking whether or not the list was properly created

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

A createList() function should do what after creating the list and ensuring it was created?

A

Set head to NULL and count to 0

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

An insertList() function to insert a node to a list has what parameters

A

LIST* pointer to a list and a void* data item pointer

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

An insertList() function to insert a node to a list, what are the steps that must be taken?

A
  1. Create a NODE* pointer
  2. Assign the new NODE* pointer’s data pointer to the data item parameter
  3. Assign the new NODE* pointer’s next pointer to the list’s head
  4. Assign the LIST* head pointer to the new node
  5. Increment the list count
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

To search for an item in a linked list, you must begin the search at the ____ of the list

A

Head of the list

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

For a searchList() function, what are the parameters?

A

LIST* pointer and the value to be searched for

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

For a searchList() function, what is the variable created in the function?

A

A node pointer NODE* nP to traverse the list

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

For a searchList() function, what is used to traverse the list? What does it look like?

A

A for loop

for (NODE* nP = LIST->head; nP != NULL; nP = nP->next)

or

NODE* nP;

for (nP = LIST->head; nP != NULL; nP = nP->next)

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

For a searchList() function, what is within the for loop?

A

if (nP->dataPtr == value) return nP;

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

For a searchList() function, what should return at the end of the function and when would this be the case?

A

NULL should return and it will only be reached if the item is not found within the list

17
Q

To remove a node from a list you must traverse the list while keeping track of the ____

A

Previous node

18
Q

To fully free a node from a list, you must…

A

free the data pointer AND the node itself

19
Q

You must always remember to do what after removing a node from a list?

A

Decrement the counter

and free the memory

20
Q

For a deleteNode() function, the type of iteration used is ___. What does it look like and why?

A

For loop iteration;

NODE* nP, prev;

for(nP = list->head, prev = NULL; nP != NULL && nP->dataPtr != value; prev = nP, nP = nP->next)

THERE IS NOTHING CONTAINED WITHIN THE FOR LOOP AS IT WILL RETURN REGARDLESS AND THE RETURN VALUE INDICATES WHETHER OR NOT THE VALUE WAS FOUND

21
Q

For a deleteNode() function, after the ____ loop, the three possibilities are…

What do they mean?

A
  1. current == NULL

Indicates the list is empty OR the item was not found

  1. previous == NULL

Indicates the item was found at the beginning of the list

  1. Neither of the above

The item was found somewhere in the middle of the list

22
Q

For a deleteNode() function, after the ____ loop, the three ____ statements are…

A

FOR LOOP

if (current == NULL) {…}

if (previous == NULL) {…}

else {..}

23
Q

For a deleteNode() function, after the ____ loop, if curr == NULL what does that mean and what code should execute?

A

It means that either the list was empty or that the item was found.

If this is the case, the only statement should be:

return list;

24
Q

For a deleteNode() function, after the ____ loop, if previous == NULL what does that mean and what code should execute?

A

This means that the value was found in the first node of the list.

If this is the case, the following lines ofcode should execute:

list->head = current->next;

25
Q

For a deleteNode() function, after the ____ loop, if the else statement executes what does that mean and what code should execute?

A

This means the value was found somewhere in the middle of the list.

In this case, the following lines of code should execute:

previous->next = current->next;

26
Q

For a deleteNode() function, if an item is deleted, what happens next?

A

This means that an item needs to be freed:

free(node->dataPtr);

free(node);

27
Q

A doubly linked list typically has pointers to both the ____ and ____ of the list as well as both ____ and ____ varibales in the node structure.

A

A doubly linked list typically has pointers to both the HEAD and TAIL of the list as well as both NEXT and PREVIOUS varibales in the node structure.

28
Q

A tradeoff to making a doubly-linked list is that it requires…

A

Additional bytes to store the PREVIOUS variable

29
Q

Circularly linked lists avoid the use of ____ references in the list

A

Avoid the use of NULL references in the list

30
Q

In a doubly-linked circular node, the predecessor of the head node is the ___ node and the successor of the tail node is the ____ node

A

In a doubly-linked circular node, the predecessor of the head node is the tail node and the successor of the tail node is the head node