4.2 data structures Flashcards

1
Q

how do dynamic ds work

ds = data structure

A

allocate and deallocate memory from the heap

heap an area of memory used specifically for this purpose

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

differences between dynamic and static data structures

A
  • static ds have a fixed size;
  • dynamic ds only take up the amt of storage space required for the actual data;
  • dynamic ds require pointers to the next item;
  • static ds store data in consecutive memory locations;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

advantages of dynamic data structures

A
  • no wasted memory;
  • no limit on number of items that can be added;
  • resources only allocated as they are needed;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

disadvantages of dynamic data structures

A
  • additional memory needed for pointers;
  • can result in memory leak;
  • can take longer to access an item directly;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a dictionary

A

a collection of key-value pairs in which the value is accessed via the associated key;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

circular queue advantage

A
  • items in a linear queue are all shuffled forward when an item is DELETED;
  • this means circular queues are more time efficient;
  • free spaces can be reused
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

when to use a linear queue over a circular queue

A

when a queue is small in size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

attribute of a circular queue

A

a pointer to the front;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is a priority queue

A

system that aims to deal with tasks on FIFO basis, but after giving them a priority order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

remove an item from a circular queue

method

A
  1. check the queue is empty;
  2. compare the value of the front pointer with the max size of the array;
  3. if equal, then front pointer becomes 1;
  4. otherwise, add 1 to the front pointer;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

adding an item to a linear queue

method

A
  • check that the queue is not already full;
  • add 1 to the value of the rear pointer;
  • then add the new item to the position indicated by the rear pointer;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

adding an item to a priority queue

method

A
  • starting with the item at the rear of the queue, move each item back one piece in the array;
  • until you find an item with the same OR higher priority than the item to add;
  • add the new item in the position before that item;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is a tree

A

connected, undirected graph; with no cycles;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is a rooted tree

A
  • a tree with one vertex designated as the root;
  • has a parent-child relationship between the nodes;
  • root is the only node with no parent and all other nodes are descendants of the root;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is a binary tree

A
  • rooted tree;
  • where each node has at most two child nodes;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

common application of a binary tree

A

binary search tree;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

pre-order traversal

A

follow the left of the node - go round and underneath tree, whenever line touches left of node, visit

18
Q

in-order traversal

A

follow the bottom of the node - go round and underneath tree, whenever line touches bottom of node, visit

19
Q

post-order traversal

A

follow the right of the node - go round and underneath tree, whenever line touches right of node, visit

20
Q

stack frame components

A
  • local variables;
  • return address;
  • parameters;
  • register values;
21
Q

peeking a stack

what does it do

A

returns the value of the top element without removing it

22
Q

implemening repeat and undo operations with one stack

method

A
  1. stack is used to store the actions;
  2. each time an action is completed it is pushed onto the TOP of the stack;
  3. unless it is an undo action;
  4. when repeat action is used, the result of peek function is used to indicate the action to complete;
  5. when undo action is used, the top item is popped from the stack of actions;
23
Q

reverse order of items in a queue with a single stack

method

A
  • (until queue empty) repeatedly remove (the front item) from the queue and push it on to the stack
  • (until stack empty) repeatedly pop items from the stack and add them to (the rear of) the queue
24
Q

what does a front pointer do

A

points to the next item to remove

25
what does a rear pointer do
points to the last item added
26
overflow
trying to push onto a stack that is full
27
underflow
trying to pop from an empty stack
28
what is a hash table
a data structure that creates a mapping between keys and values;
29
why is a hash table a suitable choice to implement a dictionary?
allows direct access to the value being looked up;
30
adding a record to a hash table | method
- hash algorithm applied; - to key value; - result is location in table where the record should be stored; - if location is not empty; - then use next free location;
31
rehashing | method
- larger hash table is created; - each value in the existing table is inserted into the new table; - in a position determined by a new hashing algorithm;
32
when does a collision occur in a hash table
when two key values compute the same hash;
33
when is it not suitable to use a hash table?
- when searches need to be done based on multiple different properties of an item;
34
finding an item in a hash table | method
- apply hash function to the specified ID; - this will give the position in the array where that item has been stored; - if another item is in that position then use a method to check if a collision occurred when adding items to hash table - if location is empty, then the item does not exist;
35
when to use an adjacency matrix over an adjacency list
- when graph/matrix is not sparse; - when edges are frequently changed; - when presence of specific edges needs to be tested frequently;
36
what is a weighted graph
a graph where each edge has a value associated with it
37
when to use an adjacency list over an adjacency matrix?
- when graph/matrix is sparse; - when edges are rarely changed; - when presence/absence of specific edges does not need to be tested;
38
what is a stack?
- a FIFO ds where new items are added to the **top** of the stack; - and items are removed from the top of the stack;
39
uses of stacks in a computing system
- call stack - back buttons in a web browser - undo buttons in an editor
40
hashing algorithm | method
- an algorithm is applied to the primary key; - to generate an address; - where the data is stored;
41
improving the performance of a hash table
- **increase the size of the table** and rehash all entries; - so that the load factor is reduced and there are **fewer collisions**;
42
effect of multiplying a vector by a scalar
the vector is scaled in size, but does not change direction