Section 7 - Data Structures Flashcards

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

Define what is meant by the term ‘array’

A

Finite

Ordered set of elements of the same type

Types: Integer, real, or char

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

Define what is meant by a ‘two-dimensional array’

A

Visualised as table

Elements referred to by row and column number

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

Define what is meant by an ‘n-dimensional array’

A

Set of elements of the same type

Indexed by n integers

x represents a particular element

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

Define what is meant by the term ‘tuple’

A

Ordered set of values

Elements of any type e.g. strings, integers, or real numbers

Immutable - elements cannot be changed, deleted, or added

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

Where would you store data permanently so that you can read or update it at a future data?

A

Stored in a file on a disk

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

Define what is meant by the term ‘records’

A

A file consists of a number of records

A record contains a number of fields, each holding one data item

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

Define what is meant by an ‘Abstract data type’

A

Logical description of how the data is viewed and the operations that can be performed on it.

Created by the programmer rather than defined within the programming language

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

What type of data structure is a ‘Queue’

A

First In First Out (FIFO)

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

Define what is meant by a ‘Queue’

A

An ordered collection of items which are added at the rear of the queue, and removed from the front.

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

Give an example of where a queue may be used in the workplace

A

Output waiting to be printed is stored in a queue on disk.

Several people may send work to be printed at more or less the same time.

Output is printed on a first come first serve basis as soon as the printer is free.

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

How would you add a new item to the rear of the queue using a queue operation?

A

enQueue(item)

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

How would you remove an item from the front of the queue and return it using a queue operation?

A

deQueue()

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

How would you test to see if the queue is empty using a queue operation?

A

isEmpty()

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

How would you test to see whether the queue was full using a queue operation?

A

isFull()

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

Define what is meant by a ‘dynamic data structure’

A

Collection of data memory

Able to shrink and grow in size, aided by the heap

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

Define what is meant by ‘The Heap’

A

Portion of memory from which space is automatically allocated or de-allocated as required

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

What is a potential drawback of a ‘dynamic data structure’

A

May cause an overflow, if it exceeds the maximum memory limit

Program may crash

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

What data structures benefit from the implementation of dynamic data structures?

A

Queues and Lists

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

How do Queues benefit other dynamic data structures?

A

Queues - maximum size of data is not known in advance. Given some arbitrary maximum to avoid causing memory overflow

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

How do dynamic data structures such as lists benefit other data structures?

A

Lists - many methods and functions such as append, remove, length, insert, search, and pop may already be written and can be used in the implementation of other data structures such as queue or stack

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

Define what is meant by a linear queue

A

Array with a pointer to the front and back of the queue.

Integer holds the size of the array needed, as a variable giving the number of items currently in the queue.

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

What is a problem of using a linear queue?

A

As many items are added and deleted, space is created at the front of the queue which cannot be filled making the size of the array smaller and wait times longer for larger queues.

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

Name one way of overcoming the limitations of a static data structure such as an array.

A

Implement the queue as a circular queue, the array fills up and the rear pointer points to the last element of the array.

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

What are the disadvantages of using a circular queue over a dynamic data structure?

A

Longer programming times

Less flexible if the maximum number of items is not known in advance

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

Define what is meant by a priority queue

A

Dequeued by removing items from the front of the queue.

Determined by priority, highest priority at the front, and lowest priority at the back. New items could join the front rather than the rear of the queue.

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

How would you initialise a circular queue?

A

procedure initialise
front = 0
rear = -1
size = 0
maxSize = size of array
endprocedure

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

How would you test for an empty circular queue?

A

function isEmpty
if size == 0 then
return True
else
return False
endif
endfunction

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

How would you test if a circular queue was full?

A

function isFull
if size == maxSize then
return True
else
return False
endif
endfunction

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

How would you add an element to a circular queue?

A

procedure enqueue(newItem)
if isFull then
print (“Queue full”)
else
rear = (rear+1) MOD maxSize
q[rear] = newItem
size = size + 1
endif
endprocedure

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

How would you remove an item from a circular queue?

A

function dequeue
if isEmpty then
print (“Queue empty”)
else
item = q[front]
front = (front+1) MOD maxSize
size = size - 1
endif
return item
endfunction

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

Define what is meant by the term ‘list’

A

Abstract data type consisting of a number of items in which the same item may occur more than once

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

How do you add a new item to a list?

A

append(item)

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

How do you remove an item from a list?

A

remove(item)

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

How do you search for an item in a list?

A

search(item)

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

How do you return the number of items in a list?

A

length()

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

How do you return the position of an item in a list?

A

index(item)

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

How do you insert a new item at a certain position in a list?

A

insert(pos, item)

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

How do you remove and return the last item in a list?

A

pop()

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

How do you remove and return an item at a certain position in a list?

A

pop(pos)

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

When might you use an array over a list?

A

The programming language does not support the list data type and the maximum number of data items is small, and known in advance

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

Define what is meant by a linked list

A

Dynamic data structure used to hold an ordered sequence each item is called a node and contains a data field and a next address field called a pointer.

42
Q

What does the data field hold in a node (linked list)?

A

Actual data associated with the item or node in the list

43
Q

What does the pointer field contain in a linked list?

A

Contains the address of the next item in the sequence

44
Q

What does a pointer variable point to in a linked list?

A

The address of the first node in the list

45
Q

What does the notation Names[p].name mean?

A

Holds the name in the node[p], that is, the node pointed to by p

46
Q

What does the notation Names[p].pointer mean?

A

Holds the value of the pointer in the node[p]

47
Q

Define what is meant by a stack

A

Last in, First Out data structure items are added to the top and removed from the top

48
Q

What are stacks used for in computing?

A

Used in calculations, and to hold addresses when subroutines are called.

49
Q

What type of data structure is a stack?

A

Static and dynamic data structure

50
Q

How do you add a new item to the top of a stack?

A

push(item)

51
Q

How do you remove and return the top item from a stack?

A

pop()

52
Q

How do you return the top item from a stack but not remove it?

A

peek()

53
Q

How do you test to see whether a stack is empty, and return a Boolean value?

A

isEmpty()

54
Q

How do you test to see whether a stack is full, and return a Boolean value?

A

isFull()

55
Q

What does the function append(item) do?

A

Append or push an item onto the top of the stack

56
Q

How can you tell when a stack is full if implemented as an array?

A

A full stack can be tested for by examining the value of the stack pointer.

57
Q

What occurs if you try to push an item onto a full stack?

A

Overflow occurs though an error message can be given to the user to avoid this.

58
Q

What will happen if the stack pointer was -1 and you tried to pop an item of a stack?

A

Underflow will occur

59
Q

What is the function of a call stack?

A

Store information about the active subroutines while a computer program is running.

60
Q

What does the call stack do with addresses of instructions?

A

Keeps track of the address of the instruction that control should return to when a subroutine ends (the return address).

61
Q

Define what is meant by a recursive subroutine

A

A subroutine that may contain several calls to itself, so that with each call, a new item/return address is pushed onto the stack.

62
Q

What happens when a recursive subroutine ends?

A

The return addresses that have been pushed onto the stack each time the routine is called are popped one after the other, each time the end of the subroutine is reached.

63
Q

How do you pass a parameter to a subroutine?

A

To pass parameters to a subroutine, the calling program pushes them on the stack in the reverse order so that the last parameter to pass is the first one pushed, and the first parameter to pass is the last one pushed.

64
Q

Define what is meant by the term ‘parameter’

A

A named variable is passed into a function or computes one or more outputs.

65
Q

How are local variables utilised by subroutines?

A

Frequently uses local variables which are accessible and usable only within the subroutine.

Each separate call to a subroutine gets its own space for its local variables.

66
Q

Define what is meant by a stack frame

A

A call stack composes of stack frames. Each stack frame corresponds to a call to a subroutine that has not yet been terminated.

67
Q

How would you access data fast without having to look through all the data records? Algorithm?

A

Hashing Algorithm

68
Q

What is the function of a hashing algorithm?

A

Applied to the value in the key field of each record to transform it into an address

69
Q

Name a common hashing algorithm used to generate a common address sequence.

A

Divide the key by the number of available addresses and take the remainder as the address

70
Q

What is it called when you hash to a location already occupied by another address?

A

A synonym, bound to occur with any hashing algorithm.

71
Q

What is it called when two record keys hash tot the same address?

A

A Collision

72
Q

Define what is meant by a hash table

A

Collection of items stored in such a way that they can quickly be located

73
Q

What is the ‘folding method’?

A

An alternate method for determining hash values. Divides the item into equal parts, and adds the parts to give the hash value. If the value is too large divides it by the number of available cells.

74
Q

How would you create a hash function for alphanumeric strings?

A

Use ASCII code for each character add each value up and divide by the number of cells available in the table

75
Q

What is the name given when an empty slot needs to be found after a collision between record addresses?

A

Rehashing

76
Q

What are the primary uses of hashing tables?

A

Efficient lookup e.g. person’s telephone number given their name, or visa versa. Store data such as user codes and encrypted passwords that need to be looked up and verified quickly

77
Q

Name one data structure that hash tables are used in the implementation of

A

A Dictionary

78
Q

Define what is meant by the term ‘dictionary’

A

Abstract data type consisting of associated pairs of items, where each pair consists of a key and a value.

79
Q

What would be used to implement a dictionary?

A

Either a static or a dynamic data structure

80
Q

Define what is meant by the term hash function

A

A function that takes a set of inputs of any arbitrary size and fits them into a table or other data structure that contains fixed-size elements.

81
Q

Define what is meant by the term ‘graph’

A

Set of vertices or nodes connected by edges or arcs.

82
Q

What name is given to a bidirectional graph?

A

Undirected graph

83
Q

What name is given to a graph where all the edges are all one-way?

A

Directed graph

84
Q

What is meant by the term ‘weighted’

A

Shows the cost to go from one vertex/node to another.

85
Q

What are the two possible implementations of a graph?

A

Adjacency matrix and Adjacency list

86
Q

How is information stored in an adjacency matrix/two-dimensional array?

A

Each row and column represents a node.

Value stored at intersection of row i and column j means there is an edge connecting node i and column j

87
Q

What are the advantages of adjacency matrices?

A

Convenient, easy to add an edge

Time efficient/constant time operations

Sequential access is easier for dense graphs when you need to transverse all outgoing edges

88
Q

Disadvantages of adjacency matrices?

A

Uses a static two-dimensional array - harder to add and delete nodes

The larger the graph the more memory space is needed

For a sparse graph, space will be wasted for not storing many edges

89
Q

How is information stored in an adjacency list?

A

List of all nodes created

Each node points to a list of all adjacent nodes (directly linked)

90
Q

Advantages of Adjacency lists?

A

Uses much less memory to represent a sparsely connected graph.

Time-efficient/easier to add +delete vertices

91
Q

Disadvantages of Adjacency lists?

A

Large memory complexity

92
Q

What are the two ways to traverse a graph so that every node is visited?

A

Depth-first transversal

Breadth-first transversal

93
Q

What happens during depth-first traversal?

A

Go as far down one route as you can go before backtracking and taking the next route. Whenever there is a choice of routes go left.

94
Q

What happens during a breadth-first traversal?

A

Visit all neighbours of a node, then all the neighbours of the first node visited, all the neighbours of the second node, and so on.

95
Q

What are some applications of graphs?

A

Computer networks - nodes represent computers and weighted edges represent the bandwidth between them.

Roads between towns - edge weights as distances

96
Q

Define what is meant by the term ‘binary tree’

A

Rooted tree, each node has a maximum of two children. Easy to search quickly for a particular item.

97
Q

How do you construct a binary tree?

A

Place the first item at the root

For each item in the list, visit the root, which becomes the current node, and branch left if the item is less than the value at the current node, and right if the item is greater than the value at the current node. Continue to do this until a leaf node is reached.

98
Q

What are the three different ways of traversing a binary tree?

A

Pre-order traversal

In-order traversal

Post-order traversal

99
Q

How does pre-order traversal work?

A

As you pass to the left of a node, output the data in that node

100
Q

How does in-order traversal work?

A

As you pass underneath a node, output the data in that node.

101
Q

How does post-order traversal work?

A

As you pass to the right of a node, output the data in that node

102
Q

How can a binary search tree be stored?

A

Using an array of records with each node consisting of a left pointer, data item, and a right pointer.

A list of tuples, or three separate lists of arrays, one for each pointer and one for the data item.