06 Data structures Flashcards

(23 cards)

1
Q

Data structure

A

object in program that holds a collection of data

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

array

A

holds components of a vector, or a list of names

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

Why is it useful to use lists?

A

we can perform operations on the list, like checking length, sorting names and editing it

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

nested list

A

list inside a list

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

list

A

sequence of data, constructed using square brackets

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

len

A

returns the length of the list

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

enumerate

A

iterate over a list and get position of each member in the list

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

How does counting differ in python?

A

Starts from 0

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

append

A

add elements to a list

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

indexing

A

assigning number to element
indices start from 0 and run to (length-1)

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

Why is it better to iterate rather than index?

A

there are data structures that support iterations but which do not support indexing

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

Heterogeneous data structure

A

Store mixed types
python lists are an example

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

Homogenous data structures

A

store only one type
arrays are an example - more efficient generally

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

list comprehension

A

succinctly built lists from other lists

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

What is the difference between a tuple and list?

A

It is a list that cannot be changed after it has been created - it is immutable
Tuples also use round brackets

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

Why is it useful to see a list that cannot be changed?

A

safer since cannot be accidentally modified in the program
permits implementations to possibly exploit this to optimise for speed

17
Q

dictionary

A

Can build a map from keys and values
Each entry separated by comma

18
Q

How do you declare a dictionary

A

Curly brackets
Entry separated by comma

19
Q

Why is choosing the right data structure an important decision in programming

A

Affects the program’s efficiency, memory usage, flexibility, and ease of development

20
Q

What is the general trade-off between flexible and simple data structures?

A

More flexible data structures are usually less efficient and may use more memory than simpler ones

21
Q

What should you prioritise when efficiency is not critical?

A

Choose a data structure that provides the needed functionality, flexibility and ease of use

22
Q

Why should safety be considered when choosing a data structure?

A

Some data structures prevent modification, reducing the risk of errors

23
Q

Why should you use iterators rather than indexing

A

Allows switching from data structures that support indexing to data structures that do not support indexing