1.4.2 Data Structures Flashcards

(44 cards)

1
Q

What’s an array?

A

An ordered, static set of elements that can only store 1 data type.

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

What is a 1D array?

A

A linear array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. Create a 1D array called fruits with 5 elements in psuedocode.
  2. Write code to access an element in the array.
  3. Write code to change an element in the array.
  4. Write code to print the length of the array.
  5. Write code to iterate over the array
A
  1. array fruits[5]
    fruits[0] = “banana”
    fruits[1] = “apple”
    fruits[2] = “orange”
    fruits[3] = “blueberry”
    fruits[4] = “cherry”
  2. print(fruits[0])
    print(fruits[2])
  3. fruits[1] = pear
  4. length = len(fruits)
    print(length)
  5. for element in fruits
    print(element)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s a record?

A

A group of related fields which is a single entity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. In psuedocode define a record type called “personDataType” with fields: “ID”, “firstName” and “surname”.
  2. Declare an instance of the Person record.
  3. Assign values to that variable’s fields.
  4. Access the fields of the Person record.
A
  1. personDataType = record
    integer ID
    string firstName
    string surname
    endRecord
  2. DECLARE person1:personDataType
  3. person1.ID = 101
    person1.firstName = “John”
    person1.surname = “Smith”
  4. OUTPUT person1.firstName
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can a 2D array be visualised?

A

As a table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. Write psuedocode for a 2D array named “board” with rows 8, and columns 9.
  2. Write code to assign “rook” to the element in the first row, first column.
A
  1. Array board[8,9]
  2. board[0,0]=“rook”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can a 3D array be visualised?

A

A multi-page spreadsheet.

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

What is a list?

A

A data structure that consists of a number of items where the items can occur more than once. And can store elements of more than one data type and each element is stored non-contiguously.

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

Give 1 difference of lists and arrays

A

Lists can contain elements of more than one data type, arrays can only contain elements of one data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. Create a list named “pets” in pseudocode with elements “dog”, “cat” and “fish”.
  2. Write a for loop that runs through the whole list, printing each element individually.
A
  1. list pets = [“dog”, “cat”, “rabbit”, “fish”]
  2. for pet in pets:
    print pet
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What do these list operations do:
1. isEmpty()
2. append(value)
3. remove(value)
4. length()
5. index(value)
6. insert(position, value)
7. pop()

A
  1. isEmpty() checks if the list is empty.
  2. append(value) adds a new value to the end of the list.
  3. remove(value) removes the value the first time it appears in the list.
  4. length() returns the length of the list.
  5. index(value) returns the position of the list.
  6. insert(position, value) inserts a value at a given position.
  7. pop() returns and removes the last value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a tuple?

A

An immutable data structure that stores an ordered set of values of any type.

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

What is a linked list?

A

A dynamic data structure that is used to hold an ordered sequence of items.
The items which form the sequence do not have to be in contiguous data locations.

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

What does a node contain?

A

A data field and a point field.

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

What’s a data field contain?

A

The value of the actual data which is part of the list.

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

What’s a pointer field contain?

A

The address of the next item in the list.

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

Give 1 advantage of linked lists

A

Values can easily be added or removed by editing the pointers.

19
Q

Give 2 disadvantages of linked lists compared to arrays

A
  1. Linked lists store pointers which means that more memory is required compared to an array.
  2. Items in a linked list are stored in a sequence, meaning they can only be traversed within that order so an item cannot be directly accessed as is possible in an array.
20
Q

What’s a stack?

A

A last in first out (LIFO) data structure where items can only be added to or removed from the top of the stack.

21
Q

Give 2 examples of stacks in a computer

A
  1. Undo button
  2. Back page button
22
Q

What do these stack operations do:
1. isEmpty()
2. push(value)
3. peek()
4. pop()
5. size()
6. isFull()

A
  1. isEmpty() checks if the stack is empty by checking the value of the top pointer.
  2. push(value) adds a new value to the top of the stack.
  3. peek() returns the top value of the stack.
  4. pop() removes and returns the top value of the stack.
  5. size() returns the size of the stack.
  6. isFull() checks if the stack is full and returns the boolean value.
23
Q

What is a queue?

A

A First in First out (FIFO) data structure where items are added to the end of the queue and removed from the front, that holds an ordered sequence of items.

24
Q

What are 3 types of queues?

A
  1. Linear Queue
  2. Circular Queue
  3. Priority Queue
25
What do these queue operations do: 1. enQueue(value) 2. deQueue(value) 3. peek() 4. isEmpty() 5. isFull()
1. enQueue(value) adds an element to the back of the queue. 2. deQueue(value) removes an element from the front of the queue. 3. peek() return the value of the item from the front of the queue. 4. isEmpty() check whether the queue is empty. 5. isFull() check whether the queue is full (if the size has a constraint).
26
What is a linear queue?
A FIFO data structure that consists of an array.
27
What is a circular queue?
A static array that has a fixed capacity
28
What is a graph?
A set of vertices/nodes that are connected by edges/pointers.
29
What are 3 types of graph? Explain each
1. Directed Graph: The edges can only be traversed in one direction. 2. Undirected Graph: The edges can be traversed in both directions. 3. Weighted Graph: A value is attached to each edge.
30
What are 2 ways computers are able to process graphs?
1. Adjacency matrix 2. Adjacency
31
What are 2 ways of traversing a graph?
1. Breadth first search 2. Depth first search
32
What happens in breadth-first traversal?
1. Visit the root node. 2. Move to the left-most node under the root. 3. Output each node, moving from left to right. 4. Continue through each level of the tree.
33
What happens in depth-first traversal?
Depth first goes to the left node, this becomes a new tree. It continues going to the left until a leaf. It then returns this, then goes right and repeats from the start. Follow left, follow right, take root.
34
Identify 2 differences between a graph and a tree
1. A graph has cycles, a tree doesn’t. 2. A tree has a hierarchy (e.g. Parent/Child), a graph doesn’t.
35
What is a tree?
A connected form of graph that has a root node at the top of the tree and leaves at the bottom. Nodes are connected to others nodes using branches/edges.
36
What is a binary tree?
A rooted tree where every node has a maximum of 2 nodes.
37
What’s a node?
An item in a tree.
38
What is an edge?
Connects two nodes together and is also known as a branch or pointer.
39
What is a root node?
A single node which does not have any incoming nodes.
40
What is a child node?
A node with incoming edges.
41
What is a parent node?
A node with outgoing edges
42
What is a subtree?
A subsection of a tree consisting of a parent and all the children of a parent.
43
What’s a leaf node?
A node with no children.
44
What is a hash table?
An associative array which is coupled with a hash function.