Linked Lists Flashcards
Where is data read from?
A data source
Where is data stored to?
A data sink
Why is the way we store data in memory important?
We want the fastest possible access to data while using the least amount of memory
What are the options for storing data in memory?
Array or linked list
What are the advantages of an array?
Elements are contiguous, faster access to elements
What are the disadvantages of an array?
Can’t be resized
What are the trade-offs of the an array?
Allocating an: oversized array is a waste of memory, undersized causes error.
What are the advantages of a linked list?
No need to resize, use only as much memory as needed, elements can be inserted/removed/shifted anywhere
What are the disadvantages of a linked list?
Elements are not contiguous, access to elements is slower
What does a singly linked list consist of?
Pointer to head, pointer to tail (optional), set of nodes containing element data and pointer to next node
What value should uninitialized pointers have?
Zero or null
What are some problems with basic linked lists?
Same structure mixes element data with list data, each element is hard-coded to point to a specific other element
Why separate list nodes from list data?
Encapsulation, reuse
How do we insert elements into a list?
Shifting pointer values
Which four cases do we consider when inserting nodes into a linked list?
The element is added to an empty list, the element is added in the first position, middle position, and last position