Data Structures Flashcards
(43 cards)
Tuple properties
Has elements of mixed types
It is immutable
Use round brackets () to indicate a tuple
Define dynamic
The number of elements can change
Define static
Number of elements cannot change
Define record
Composed of a fixed number of fields of different data types
Can be implemented as an object
Arrays (size, contents, data types)
Size: static
Contents: mutable
Data types: single
Tuple (size, contents, data types)
Size: static
Contents: immutable
Data types: mixed
Record (size, contents, data types)
Size: static
Contents: mutable
Data types: mixed
List (size, contents, data types)
Size: dynamic
Contents: mutable
Data types: mixed
Stacks properties
LIFO- last in first out
Single pointer (points to top of stack)
Pushing stack steps
- Check if stack is full
- If full -> report error, stop
- Increment the stack pointer
- Insert new data item into cell pointed to by the stack pointer
- Stop
Popping stack steps
- Check if stack is empty
- If empty -> report error, stop
- Copy data item from cell pointed to by the stack pointer
- Decrement the stack pointer
- Return the data
- Stop
Peeking stack steps
- Check if stack is empty
- If empty -> report error, stop
- Copy data item from cell pointed to by the stack pointer
- Return the data
- Stop
Enqueue steps
- Check if queue is full
- If full -> report error, stop
- Else increment rear pointer
- Insert new item at rear pointer
- Stop
Dequeue steps
- Check if queue is empty
- If empty -> report error, stop
- Else item = queue[head]
- Increment head pointer
- Return item
- Stop
Queue properties
FIFO- first in first out
Two pointers- head and tail pointer
Abstract data type
Peeking queue steps
- Check if queue is empty
- If empty -> report empty, stop
- Else
- Copy data item from cell pointed to by the head pointer
- Return the data item
- Stop
What does isEmpty() do?
Test for empty list
What does append(item) do?
Adds a new item to the end of a list
What does remove(item) do?
Remove first occurrence of an item from the list
What does count(item) do?
Return the number of occurrences in the list
What does len() do
Returns the number of items in the list
What does index(item) do
Return the position of the item
What does insert(pos,item) do
Add a new item at position pos
What does pop() do
Remove and return the last item in the list