3-Data Structures (Arrays Lists Stacks Queues) Flashcards
Properties of a linear data structure
There is a UNIQUE first element
There is a UNIQUE last element
Every component has a unique predecessor (except the first)
Every component has a unique success (except the last).
If any are false, it’s nonlinear.
What are the 2 methods for accessing data stored in a linear structure
Sequential access - by accessing all elements preceding N,
Direct access, any element can be accessed directly.
What are homogeneous structures?
All the same type
Direct- array
What are heterogeneous structures?
All different types
Direct- record
General sequential access structure?
List
LIFO sequential access structure?
Stack
FIFO sequential access structure?
Queue
Example of a non linear strucutre
Set
Domain of an array (contents)
A collection of fixed number of components of the same type
A set of indexes used to access the data stored. One to one relationship.
Advantages of linked lists
- Fair use of memory
- Size of the structure does not need to be declared in advance
- Insertions and deletions are cheaper
Disadvantages of linked lists
Algorithms are more complex, harder to read and harder to debug
Allocation and de-allocation of memory space impose some overhead to the performance of the algorithm
What is the SIEVE OF ERATOSTHENES
Gives all prime numbers between 2 and N
What are linked lists
It consists of a collection of records called nodes each containing at least one member that gives the location
of the next node in the list.
What is a list?
It is a linear structure that provides only sequential access to its elements
• It normally has two “special” named elements called head and tail.
Main advantage over arrays is easy insertion and deletion of nodes
• Mostly when implemented using dynamic allocation
When examining a list, what cases do we have to consider?
• When examining a list, we most often have to consider three separate cases
• The node is the first node of the list
• The node is an “interior” node
• The node is the last node of the list
The above is the reason why some programs choose to use sentinels in their
linked lists.