Unit 7 - Data Structures Flashcards
define array
a finite, ordered set of elements of the same type.
what is a 2-dimensional array
a collection of data elements arranged in a grid-like structure with rows and columns
define tuple
an ordered set of values, which could be elements of any type (images, sound files, strings,etc) that is immutable, which means that elements cannot be changed, and you cannot dynamically add elements or delete elements form a tuple.
what’s the difference between static and dynamic data types
dynamic data types - change size when required (lists grow when items are added and shrink when items are removed). it does this with the aid of heap (specific area of memory)
static data types - cannot change size (array)
what is an abstract data type
one that is created by a programmer
- a logical description of how the data is viewed and the operations that can be performed on it
what is an elementary data type
defined within the programming language
what are the four operations with a queue
- enQueue(item)
- deQueue
- isEmpty
- isFull
what is a queue
a queue is a first in first out data structure. new elements can only be added to the end of the queue, and elements may only be retrieved from the front of the queue
applications of queues
- printing from computers (print queue)
- typing on a keyboard
- simulations
what does enQueue(item) do
add a new item to the rear of the queue
what does deQueue() do
remove the front item from the queue
what does isEmpty() for queues do
test to see whether the queue is empty
what does isFull() for queues do
test to see whether queue is full
what is a circular queue
one way of overcoming the limitation of a static data structure by reusing the spaces that have been freed by dequeuing from the front of the array. If you see a MOD and a length function when looking at lists you will know that it is a circular queue.
pseudocode to initialise a circular queue
pseudocode to test for an empty queue
pseudocode to test for a full queue
pseudocode to add an element to the queue
pseudocode to remove an item from the queue
what is a priority queue
it acts like a queue in that items are dequeue by removing them from the font of the queue. however, the logical order of items within the queue is determined by their priority, with the highest priority items at the front of the queue and the lowest priority items at the back.
what is a list
an abstract data type consisting of a number of items in which the same item may occur more than once
what are the main operations on lists
- isEmpty()
- append(item)
- remove(item)
- search(item)
- length()
- index(item)
- insert(pos, item)
- pop()
- pop(pos)
what does isEmpty() on lists do
test for empty list
what does append(item) do
add a new item to list to the end of the list
what does remove(item) do
remove the first occurrence of an item from list
what does search(item) do
search for an item in the list
what does length() do
return the number of items
what does index(item) do
return the position of item
what does insert(pos, item) do
insert a new item at position pos
what does pop() do
remove and return the last item in the list
what does pop(pos) do
remove and return the item at position pos
what is a linked list
a linked list is a dynamic data structure used to hold an ordered sequence
- items which form the sequence are not necessarily held in contiguous data locations
- each item in the list is called a node and contains a data field and a next address field called a link or pointer field
- the data field holds the actual data associated with the list item, and the pointer field contains the next item in the sequence
- the link field indicates that there are no further items by the use of a null pointer
pseudocode the enQueue() list
procedure enqueue(item)
if q.isFull() then
print (“queue full”)
else
q.append(item)
endif
endprocedure
pseudocode for deQueue(item) on lists
procedure dequeue(item)
if q.isEmpty() then
print(“queue empty”)
else
q.pop(0)
endif
endprocedure
pseudocode for isFull() on lists
function isFull()
return(len(q) == maxSize))
endfunction
pseudocode for isEmpty() on lists
isEmpty()
return(len(q) == 0)
endfunction
how to add nodes to a linked list
data is put into the node pointed to by the nextfree pointer