1.4.2 Data structures - Nathan Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Define the term ‘array’

A

An array is a data structure that holds a number of elements of the same data type

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

Where does array indexing start?

A

Array indexes start at ‘0’. (at least, in most programming languages such as Python)

ADDITIONAL EXPLANATION:
So in the following array:
[“toast”, “eggs”, “ketchup”]

The ‘0th’ element is “toast”, the ‘1st’ element is “eggs” and the ‘2nd’ element is “ketchup”

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

How are the contents of an array stored in memory?

A

The contents of arrays are stored contiguously in memory (meaning one after another). This means that the position of each element of the array can be computer from the array’s base address.

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

Can the contents of an array be changed while the program is running?

A

The contents of an array are mutable - so they can be changed while the program is running

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

What’s the difference between a one dimensional array and a two dimensional one?

A

One dimensional array: an array containing data types such as integers, strings, etc

Two dimensional array: an array containing arrays: e.g:
my2dArray = [[1, 65, 3, 2],
[62, 7, 1, 6],
[6, 3, 76, 2]]

Where the first element of this array is, [1, 65, 3, 2]

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

What is a record?

A

A record is a data structure containing a fixed number of variables, called fields. Each field has an identifier (a name) and a data type. Each field can have a different data type.

PSEUDOCODE EXAMPLE:
PlayerRecord = RECORD
player_number: Integer
first_name: String
last_name: String
date_of_birth: Date
position: String
injured: Boolean
ENDRECORD

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

What is a list?

A

A list is an abstract data type. It describes a linear collection of data items in an order.

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

What operations can be done on a list?

A

create - create a new list
add - add a new element to the list
delete - delete an element from the list
traverse - visit the elements in the list one at a time

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

What is a tuple?

A

A tuple is an ordered sequence of of immutable elements (meaning the elements can’t be changed while the program is running).

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

Do elements in a tuple all have to be the same data type?

A

No, the elements of a tuple can all be different data types - e.g a mix of integers and strings

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

What is a linked list?

A

A linked list is a dynamic data structure - where each node points to the next one, forming a sequence with a start and end.

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

Why is it important that a linked list is dynamic?

A

Because a linked list is dynamic, it’s size can be changed at runtime.

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

What does a node in a linked list contain?

A

Nodes in a linked list contain the data relating to the element, and a pointer to the next node.

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

What is a graph?

A

A graph is an abstract data type that can be used to represent complex, non-linear relationships between objects. They can be undirected, or directed (contain arrows).

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

What is a stack?

A

A stack is an abstract data type that holds an ordered, linear sequence of items. It is LIFO (last-in-first-out), similar to a stack of plates.

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

What are the main operations of a stack?

A

Push() - add element to top of stack
Pop() - remove element from top of stack
Peek() - return copy of element on top of stack (without removing it)
is_empty() - check whether the stack is empty
is_full() - check whether stack is at maximum capacity (if stored in a static (fixed-size) structure)

17
Q

Name an application of a stack

A

One application of a stack is maintaining an ‘undo’ list

18
Q

What is a queue

A

A queue is an abstract data type that holds an ordered, linear sequence of items. It is FIFO (first-in-first-out), similar to a queue of people at a cafe.

19
Q

What are the main operations of a stack?

A

enqueue(data) - add element to queue
dequeue() - return an element from front of queue & remove it
is_empty() - check whether the stack is empty
is_full() - check whether stack is at maximum capacity (if the size of the queue is constrained)

20
Q

What are some applications of a queue

A

Queues can be used for queuing up print tasks, or for simulations (e.g traffic or shopping simulations)

21
Q

What is a tree?

A

A tree is a type of graph that’s undirected, and doesn’t contain cycles

22
Q

What’s a binary tree?

A

A binary tree is a tree where each node has at most 2 children

23
Q

What are some applications of trees?

A
  • Syntax trees in compilers
  • Used to represent boolean expressions to simplify them
24
Q

What is a hash table?

A

A hash table is a type of data structure in which information is stored in an easy-to-retrieve and efficient manner, using key-value pairs

25
Q

What is hashing

A

Hashing is the process of transforming any given key or a string of characters into another value

26
Q

What is a data structure

A

A data structure is a collection of data that is organised to allow efficient processing

27
Q

What’s a static data structure?

A

A static data structure reserves memory for a set amount of data

28
Q

What’s a dynamic data structure?

A

A dynamic data structure is a memory efficient data structure with a capacity that isn’t fixed

29
Q

What’s a dictionary?

A

A dictionary is an abstract data type that defines an unordered collection of data as a set of key-value pairs

30
Q

How do you create a dictionary in Python?

A

results = {“Detra”: 17,
“Nova”: 84,
“Charlie”: 22,
“Hwa”: 75,
“Roxann”: 92,
“Elsa”: 29}