Data Structures Flashcards
What are elementary or primitive data types?
Primitives are predefined data types that are independent of all other kinds and include basic values of particular attributes, like text or numeric values. They are the most fundamental type and are used as the foundation for more complex data types. Most computer languages probably employ some variation of these simple data types.
E.g. real, Boolean, char, integer
What are composite data types?
Data types made up of two or more other data types.
E.g. list, array, string (a list of characters)
What are abstract data types?
Abstract data types are a logical description of how we view the data and possible operations, independent of the implementation.
E.g. stack, queue
We are only concerned with what the data is representing and not how it’s structured.
We are creating an encapsulation around the data.
Encapsulation is a form of information hiding.
What are some examples of queues in real life?
Queueing at a shop or a ticket booth, print job queue, waiting in a line, waiting at the doctor/dentist etc.
What is a queue?
A queue is an abstract data type that holds an ordered, linear sequence of items. You can describe it as a first in, first out (FIFO) structure; the first element to be added to the queue will be the first element to be removed from the queue. New elements are added to the back or rear of the queue. When an element is removed, the remaining elements do not move up to take the empty space.
How are pointers used in queues?
It’s very wasteful of CPU cycles to refill memory locations with blanks – pointers can be used instead.
Pointers: front and rear.
Front points to the next item to remove and rear points to the last item added.
What is a priority queue?
A priority queue is one where each element in the queue has a priority. When new elements are added to the queue, they are inserted ahead of those of lower priority and behind elements of equal priority. A real-world example would be a queue in the school canteen. Students join the queue at the end of the line of other students but prefects can join ahead of students, but behind other prefects.
What does the ‘enqueue(data)’ operation do?
Adds an element to the queue (the element is added to the back unless it’s a priority queue).
What does the ‘dequeue()’ operation do?
Returns an element from the front of the queue and removes this element from the queue.
What does the ‘is_empty()’ operation do?
Checks whether the queue is empty, returns True if it’s empty and False otherwise.
What does the ‘is_full()’ operation do?
Checks whether the queue is full, returns True if it’s full and False otherwise.
What does the ‘size()’ operation do?
Returns the size of the queue.
What are some problems with implementing a queue?
Space in the array cannot be reused. The queue may appear to be full even when there are no items in it.
How does a circular queue work?
A circular queue algorithm overcomes the problem of reusing the spaces that have been freed by dequeuing from the front of the array.
The MOD function is used to change the pointers.
E.g. (Current index + 1) MOD 5 for a queue with 5 items.
What is a static data structure?
Static data structures are fixed in size.
They cannot grow, shrink, or be freed during execution.
An array is a static data structure.