Week 5 - Data Structures Flashcards

1
Q

What’s one of the biggest advantages of hash tables?

A

They combine the best of two worlds - arrays and linked lists

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

What’s the biggest disadvantage of hash tables?

A

Huge memory consumption

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

What’s the O of hash tables?

A

O(n)

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

What’s a hash function?

A

It’s a function that sorts elements within a hash table

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

What are tries?

A

Tries are data structures with trees, whose nodes are arrays

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

What’s the O of tries?

A

O(1) - constant search time

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

What’s the biggest disadvantage of tries?

A

Huge memory consumption

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

What do structures do?

A

Structures provide a way to unify several vars. of different types into a single new var. type

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

What structures are used for?

A

Structures are used to group elements of different data types that have a logical connection

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

What’s the difference between “typedef struct” and “struct”?

A

“typedef” allows us to create an alias for the struct. This alias is then used later to define variables of that type without having to write the “struct” keyword

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

Where are structures defined?

A

Structs are defined in separate .h files or atop of our programs, outside of any function

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

How can elements (aka members) of structs be access?

A

Using the dot operator (.)

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

How can we dynamically allocate structs?

A

Using the malloc function

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

What’s an example of dynamically allocated struct using the arrow operator?

A

(*mycar).year = 2011; can be replaced by mycar → year = 2011;

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

In how many directions can we move in a singly-linked list?

A

One direction only

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

What’s the problem with singly-linked lists moving in one direction only?

A

We cannot delete a node

17
Q

In how many directions can we move on doubly-linked lists?

A

Two directions: foward and backward

18
Q

What’s the downside of doubly-linked lists moving in both directions (foward and backward)?

A

We need to add an extra pointer to the structure definition, so more memory will be consumed

19
Q

What are singly and doubly linked lists good for?

A

Insertion and deletion of elements

20
Q

What’s the time singly and doubly linked lists take to insert and delete elements respectively?

A

Constant time

21
Q

What’s the downside of singly and doubly linked lists?

A

We lose the ability to randomly access lists elements, so accessing elements will take linear time

22
Q

Why are tries considered the holy grail of data scructs?

A

That’s because they provide a way to insert, delete and lookup in constant time

23
Q

What do tries combine together to store data?

A

Structs and pointers

24
Q

What’s one of the biggest advantages of tries?

A

They have no collision risk (two pieces of data will never have the same path)

25
Q

What’s the downside of tries?

A

Memory consumption

26
Q

What’s the reason to use stacks?

A

Make sure that the last element to be added is the first one to be removed

27
Q

What do we need to consider before selecting a data struct?

A

How fast we want to:
* Insert data
* Delete data
* Look up data