Data structure Flashcards
array
An array allows you to store multiple items of the same data type under a shared common name.
Arrays can store data of the same data type contiguously in memory. This means…
… random access to all element is available via its direct index.
Limitations of arrays:
A
They can only store one data type
- They’re a static data structure (their scope is predetermined)
record
an unordered data structure which is accessed through an attribute. It can store many different data types
What are pythons versions of arrays?
Lists and tuples
Tuples
Tuples are lists that cannot be edited and is said to be immutable.
immutable
structure and data cannot be changed at run time.
mutable
structure and data can be changed at run time.
Static data structure
size of the structure cannot change at run time
Dynamic data structure
size of the structure can change at run time.
Stack data structure
A stack is known as a LIFO, a single pointer is used to point to the top item of the stack, when a new item is pushed onto the stack the pointer is incremented. When an item is popped off the stack the pointer decrements to point to the new top of the stack.
LIFO
last in first out - the last item you push to the top of the list is the first item you pop off the stack.
Queue data structure
A queue is known as a FIFO structure. A pair of pointers is used to point to the front and back of the queue. If an item is popped from the queue the front pointer points to the item being popped. If an item is pushed onto a queue the tail pointer increments by one and points to the new end of queue.
FIFO
first in first out - because the new items get pushed to the back of the queue and new items get popped from the front of the queue.
Algorithm for insertion into a stack:
1)Check to see if the stack is full
If the stack is full report error
and stop
2)Increment the stack pointer
Insert new data item into
location pointed to by the
stack pointer and stop