Data Structures Flashcards
(43 cards)
Define an interface
A set of procedures that operate on the data structure
Why is an abstract data type ‘abstract’?
Because we are not concerned with the implementation of the data structure but rather what operations we can perform using the data structure
Define strong encapsulation in terms of ADTs
Encapsulation is strong if details of how the data structure is stored is completely hidden from the user because it means the user has no conceptual idea of how the ADT is stored and implemented
Define a queue
An ordered collection of items which are added at the tail and removed from the head
Why are queues beneficial?
They provide FIFO functionality meaning that items can be easily reversed and traced back
How do you use a structure in C to define a queue?
You create a structure which has two properties, one being the data contained in that position in the queue and the second being a pointer to the next item in the queue
How do you add an item to a queue in C?
- Check whether the queue is full
- Check whether the head pointer is NULL
- If the head pointer is NULL then set the head pointer equal to the element you want to add
- If the head pointer is not NULL then determine the position of the tail of the queue and reassign that pointer so it points to the element you want to add
Define homogeneous
Consists of elements with all the same data type
Define heterogeneous
Consists of elements of different data types
Describe byte addressable memory
Memory can be represented as an array of bytes with each cell having a unique address written in hexadecimal
What is a word?
The smallest unit of addressable memory in a computer
What is the size of a word?
The size of a word varies from machine to machine but we assume a word is 32 bits long
How many bits are required to store an integer?
32
What are the 3 aspects of a variable?
- A symbolic name given by the programmer
- The value is contains
- An address where it resides in memory
Define variable scope
The functions of a program in which a variable can be accessed
Why do we have to use pointers in C?
We can only return one variable from a function in C so, in order to change variables in other scopes in a function, we use pointers to the variables
What is indirection?
A method of referring to an item without referring to the item itself .e.g. referring to the memory address in which a variable is stored rather than referring to the variable itself
What does ‘*’ mean?
This is the dereferencing operator because it returns the value stored at the address contained within the operand
What does ‘&’ mean?
This is the address-of operator and it returns the address of its operand
What does it mean if an operator is unary?
It only takes one input
What are the three stages to evaluating an operation?
- Fetch
- Evaluate
- Store
Define record
A heterogeneous compound item
What is the disadvantage of using arrays?
Arrays are homogeneous meaning that you cannot model any entities that consist of values of different data types using arrays
What is a field?
An item which makes up a record