data structures Flashcards

1
Q

what is a queue

A

an ordered set of items which area added at the tail and removed from the head - fifo

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

what are the 5 operations needed to use a queue

A

Queue() - creates an empty queue
dequeue()
enqueue(item)
IsEmpty()
size()

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

what is an abstract data type

A

defines a data type logically rather than structurally

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

data structure

A

the physical representation of the structure of data being stored in memory

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

strong encapsulation

A

completely hides the details on howl the data structure is stored from the user

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

records

A

a compound item with components of various different types called fields

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

what does malloc do

A

dynamically allocates marmot and return the base location for the allocated space
e.g. student = malloc(sizeof(student));

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

what is a pro of 2d arrays

A

very fast access compared to a list using indexing

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

what are cons of 2d arrays

A

has a fixed size and doesn’t resize easily (you have to copy the contents into a bigger array)
insertions and deletions can be costly

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

what is a stack

A

adt - filo

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

bounded stacks

A

have a max size

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

stack overflow

A

trying to push when the stack is full

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

stack underflow

A

trying to pop when the stack is empty

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

what are some common applications for stacks

A

function calls
depth first search
evaluating expressions
braces matching

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

list

A

stores a set of items in a linear order

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

doubly linked lists

A

each data entry has a next and previous order

17
Q

singly linked lists

A

each data entry has a next pointer therefore they can only be traversed forward

18
Q

what is theoretical time complexity

A

the relationship between the size of the input and the algorithm running time

19
Q

what is a recursive function

A

a function that calls itself

20
Q

what are some positives of iteration

A

stack overflows are less likely as memory usage is controlled explicitly by the programmer
can execute quicker s there’s no overhead from the creation/destruction of the stack frame

21
Q

why should you use recursion (positives)

A

naturally recursive functions are more concise compared to expressing them iteratively
languages that support recursion can eliminate some of the extra cost to performance and stack overflows

22
Q

key

A

unique identifier for what you want to store and remove

23
Q

how can you deal with collisions in indexed retrieval

A

use indexed arrays; recomputing the array when you want to insert new data
using chains

24
Q

how can chains help with collisions

A

when storage is based on the first letter you can have an index pointing to a chain for each one
dynamic so extra objects can be added easily
no need to recompute the index

25
Q

what does a hashing function do

A

converts a key into an integer which is then used for indexing a storage array

26
Q

how can you minimise collisions in a hash table

A

larger array - a wide range of index values
can use multiplication as well as addition to get your index
uniform hashing; each key is equally as likely to map to an array location

27
Q

why is shift usually used for hashing tables

A

hashing is meant to be quite fast however multiplication and division are quite slow