SCC121: weeks 6-10 Flashcards
(34 cards)
Describe a queue data structure
-First in First out data structure.
-Items are added to the tail of the list and removed from the head.
What are some key processes associated with queues?
-Queue()- creates a new queue
-enqueue()- adds a new item to the queue
-dequeue()-removes an item from the list
-isEmpty()- checks if the given queue is empty
-size()- returns the size of the list
Why are abstract data types “abstract”??
-Abstract data types are theoretical concepts of how data can be stored.
-ADT definitions describe what operations should be performed, not HOW it is implemented/coded.
-when realised/implemented, ADTs become Data Structures.
Data Structures vs ADTs
-data structures are a physical representation of how data is stored structurally in memory.
-ADT is a theoretical overview of the data structure and the functions needed to manipulate it.
describe the concept of byte addressable memory.
memory can be seen as an array of bytes. each byte/ cell of the array has a unique address.
What is word size?
-number of bits the CPU can process at once
-we assume a word is 32 bits in size unless told otherwise
-differs across machines
-memory addresses increase by word size/8 (size of a byte)
-typically ints are word size.
What are the 4 pieces of information associated with a variable?
-name
-value
-address
-type
Why use pointers?
-Avoids passing copies of variables, memory efficient
-variables are local to the function they are declared in
-pointers allow programmers to pass memory addresses between functions, pass by value, pass by reference
what is a heterogenous data structure?
A data structure that can hold data of multiple types.
Give an example of a heterogenous data type.
-records
-has components of varying types, called fields
-fields are identified by name, not index.
How would a 2D array be created in C?
int 2dArray[x][y];
how would a 2D array be created in java?
int [][] rating = new int[x][y];
How would you go about populating a 2D array in C?
- a nested loop can be used to traverse every row and cell.
Why use an Array?
-one word identifier for a group of variables.
-random access, elements don’t need to be sequentially traversed through
What are the problems of an Array?
-fixed size, does not allow dynamic appending
-insertions and deletions are costly
define - what is it used for?
-defining constants
Why are constants useful?
defined in one place- only need to be changed in one place.
describe the difference between passing by reference and passing by value.
-passing by reference:
a pointer to a variable is passed as a parameter to a function
-passing by value:
the variable itself is passed to the function, not the memory location the value is stored at.
describe the key features of a stack
-items are inserted and removed from the tail
-a first in last out data structure
what are the necessary functions for a stack ADT?
-Stack()
-push()
-pop()
what are some errors that can occur when using stacks?
-overflow error when push() used on a full stack
-underflow error when pop() used on an empty stack
what are some common uses of stack ADTs?
-program execution: call stack
-syntax applications: evaluating expressions and parentheses matching
-searching/traversal: depth traversal
Describe the concept of a doubly linked list
-each value/piece of data in the list is stored along with a pointer to the next and previous item in the list.
-If the value of the previous or next pointer is nil or ‘/’ this suggests the item is the first or last in the list.
-allows dynamic appending the data structure, no set size
describe a singly linked list
-no previous pointer stored along with data, only the pointer to the next value
-cannot be traversed in reverse order
-removing values always requires traversal