Linked Lists Flashcards

1
Q

Where is data read from?

A

A data source

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

Where is data stored to?

A

A data sink

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

Why is the way we store data in memory important?

A

We want the fastest possible access to data while using the least amount of memory

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

What are the options for storing data in memory?

A

Array or linked list

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

What are the advantages of an array?

A

Elements are contiguous, faster access to elements

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

What are the disadvantages of an array?

A

Can’t be resized

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

What are the trade-offs of the an array?

A

Allocating an: oversized array is a waste of memory, undersized causes error.

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

What are the advantages of a linked list?

A

No need to resize, use only as much memory as needed, elements can be inserted/removed/shifted anywhere

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

What are the disadvantages of a linked list?

A

Elements are not contiguous, access to elements is slower

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

What does a singly linked list consist of?

A

Pointer to head, pointer to tail (optional), set of nodes containing element data and pointer to next node

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

What value should uninitialized pointers have?

A

Zero or null

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

What are some problems with basic linked lists?

A

Same structure mixes element data with list data, each element is hard-coded to point to a specific other element

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

Why separate list nodes from list data?

A

Encapsulation, reuse

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

How do we insert elements into a list?

A

Shifting pointer values

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

Which four cases do we consider when inserting nodes into a linked list?

A

The element is added to an empty list, the element is added in the first position, middle position, and last position

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

How do we remove an element from the list?

A

Shift pointer values and deallocate the memory

17
Q

Which six cases do we consider when removing nodes from a linked list?

A

List is empty, element removed is the only element in the list, element is not found in list, element is removed from first, middle, last

18
Q

When cleaning up a list, remember to..

A

Deallocate nodes, only deallocate data if it own’t be used again

19
Q

What is different about a doubly-linked list?

A

Pointer to head and tail, each node has a pointer forward and backwards

20
Q

What is a dynamic array?

A

An array that is dynamically allocated

21
Q

Why use a dynamic array?

A

They can be resized as needed to accommodate more or less data

22
Q

What are the two kinds of arrays (module context)

A

Static arrays, dynamic arrays

23
Q

What are the two kinds of data that can be stored in an arrray?

A

Actual data or pointers to the data

24
Q

What is a function pointer?

A

Pointer variable that stores the address of a function’s code inside the code segment

25
Q

Why use function pointers?

A

They allow us to choose which function to execute at runtime, but the functions must have the same prototype