1.4.2 Data Structures Flashcards

1
Q

What is an arrary?

A

A data structure for storing a finite, ordered set of data of the same data type within a single indentifer

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

What are 3 features of arrays

A
  • Static
  • Ordered, made up of elements which each have an index (starting from zero)
  • Stored contiguously in memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you count the numbers of elements in an array?

A

length = len[array_name]

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

How do you define an array?

A

array_name = [“firstelement”,”secondelement”,”thirdelement”]

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

How do you update a value in an array?

A

array_name[2] = “2nditem”

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

How do you output a value from an arrary?

A

print(arrary_name[2])

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

What is a 2D array?

A

Can be visualised as a table or spreadsheet. Arrays inside of an array.

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

How do the indexes work in a 2D array?

A

array_name[row,column]

The row is called first then the column

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

What are 3D arrays?

A

A 3D array can be visualised like a pile of 2D arrays.
Think of a stack of spreadsheets.

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

How do the indexes work in 3D arrays?

A

array_name[row, column, depth]

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

What is a tuple?

A

A data structure for storing an immutable, ordered set of data, which can be different data types within a single identifier.

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

What does immutable mean?

A

Cannot be modified morethan once

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

What are 4 features of a tuple?

A

Mixed data types
Fixed size
Ordered
Immutable

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

What is a list?

A

A data structure that stores a sequence of data values, each with a unique index

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

What are 4 features of lists?

A

Ordered
No predefined scope - dynamic
Multiple data types
Stored non-contigously

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

Why are lists easy to initalise?

A

There is no need to define attributes in advance.

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

What is a record?

A

A data structure that stores data in elements called fields, organised based on attributes

18
Q

What are 3 attributes of records?

A

Stores multiple values under one identifier
Can hold different data types
Unordered

19
Q

Why are collections of records usually stored in an array?

A

So they can be accessed using an index

print(array_name[0].sort)

20
Q

Which operation checks if a list is empty?

A

.isEmpty()

21
Q

Which operation adds a new value to the end of a list?

A

.append(value)

22
Q

Which operation removes the value the first time it appears in the list?

A

.remove(value)

23
Q

Which operation searches for a value in the list?

A

.search(value)

24
Q

Which operation returns the length of the list?

25
Q

Which operation returns the position of the item in a list?

A

.index(value)

26
Q

Which operation inserts a value at a given position in a list?

A

.insert(position,value)

27
Q

Which operation returns and removes the last value in a list?

28
Q

Which operation returns and removes the value in the list at the given position?

A

.pop(position)

29
Q

What is a stack?

A

Last in first out data structure (LIFO)
Uses one pointer to point to the top of the stack

30
Q

Where are stacks used?

A

Web browser history
Undo buttons

31
Q

How do you add a item to a stack?

32
Q

How do you remove the top item from a stack?

33
Q

How do you return the value at the top of stack without removing it?

34
Q

What are the 2 possible errors you could get when pushing/popping?

A

Popping an item from an empty stack will produce an underflow error
Pushing an item onto a full stack will produce an overflow error

35
Q

What is a queue?

A

A first in first-out data structure (FIFO)
Uses two pointers, one to store the location of the front of the queue and one to store the location of the back of the queue.

36
Q

Where are queues used?

A

Printer queues
Keyboard buffers

37
Q

How can you add an item to the back of the queue?

38
Q

How can you remove an item from the front of the queue?

39
Q

How can you output the item from the front of the queue without removing it?

40
Q

What are the 2 possible errors you can get when dequeuing/enqueuing?

A

Dequeuing an empty queue will produce an underflow error
Enqueuing a full queue will produce an overflow error

41
Q

What is a circular queue?

A

Circular queues use arrays to make the front of the queue attached to the end of the queue