2 - Fundamentals of Data Structures Flashcards

1
Q

What is the difference between an abstract data type and a data stucture?

A

An abstract data type is a theoretical description of a way of organising data, with particular features and access restrictions.

A data structure is a concrete realisation of an abstract data type in code.

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

Explain the circumstances in which it is more appropriate to represent a graph using an adjacency list instead of an adjacency matrix.

A

Adjacency list appropriate when
* the graph is sparse
* when edges are rarely changed
* when the presence of specific edges does not need to be tested frequently.

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

Explain what an abstraction is.

A

Omitting unnecessary details from a representation, storing only those details which are necessary in the context of the problem being solved.

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

Explain the differences between static and dynamic data structures.

A
  • Static data structures have fixed size at runtime, whereas the size of dynamic data structures can change at runtime.
  • Static data structures typically store data in consecutive memory locations whereas dynamic structures typically do not.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain why a static implementation of a priority queue is less efficient than a dynamic implementation.

A

For a static implementation, when an item is inserted all items that come after must be moved down/shuffled back in the array.
With a dynamic implementation pointers can be changed so that the item in front points to the inserted item and the inserted item points to the next item (or is null)

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

Explain how a value is stored in a hash table.

A

The hashing algorithm is applied to the key.
The result is an index of where to store the value in an array.
It is possible that the hashing algorithm might generate the same key for two different values
A collision handling method is used, for example by storing the value at the next empty index in the array.

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

Describe the steps involved in rehashing.

A

A larger hash table is created.

Each value in the existing table is inserted into the new table in a position determined by a new hashing algorithm.

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

Why is hashing used?

A

So that searching, adding and deleting can be done efficiently.

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

In the context of storing data in a file, explain what a hash function is.

A

A hash function is a function that computes a record position within a specified range from a key field value.

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

Explain what a collision is and how one might be dealt with.

A

A collision is when two keys compute the same hash value. They can be dealt with by storing the record in the next available location in the file.

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

Why is a circular queue often a better choice of data structure than a linear queue?

A

Items in a linear queue are all shuffled forward when an item is deleted from the front of the queue, whereas items don’t need to shuffle forward in a circular queue. This makes circular queues more time efficient when removing an item.

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

What are the advantages and disadvantages of dynamic data structures over static data structures?

A

Advantages:
• No wasted memory
• Can grow as more data is added to the data structure
• Resources only allocated as they are needed

Disadvantages:
• Additional memory needed for pointers
• Can result in memory leak
• Can take longer to access an item directly

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

Describe the steps involved in adding an item to a linear queue that has been implemented as a static data structure using an array.

A

Check that the queue is not already full, if it isn’t, then add 1 to the value of the rear pointer then add the new item to the position in the array indicated by the rear pointer.

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

Describe the steps involved when adding an item to a priority queue, implemented as a static data structure using an array, that are not required when adding an item to a linear queue.

A

Starting with the item at the rear of the queue, move each item back one place in the array until find an item with the same or higher priority than the new item. Then add the new item in the position before that item.

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

What is a graph?

A

A graph is a collection of vertices and a collection of edges connecting these vertices.

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

What is a weighted graph?

A

A graph with a weight associated with each edge.

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

What is a vertex/node?

A

An object in a graph.

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

What is an edge/arc?

A

A line representing a connection between two vertices in a graph.

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

What is a directed graph?

A

A graph where the edges have a direction.

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

What is an undirected graph?

A

A graph where no edges have a direction.

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

What is a tree?

A

A connected, undirected graph with no cycles.

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

What are the main operations that can be performed on a stack and what do they do?

A
  • Push - adds an element to the top of the stack
  • Pop - removes an element from the top of the stack and returns it
  • Peek - returns a copy of the element from the top of the stack
  • Is Empty - Checks whether the stack is empty
  • Is Full - Checks whether a stack is at maximum capacity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are the main operations that can be performed on a queue and what do they do?

A
  • Enqueue - adds an element to the back of the queue
  • Dequeue - removes the element at the front of the queue and returns it
  • Is Empty - checks whether the queue is empty
  • Is full - checks whether the queue is at maximum capacity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is a hash table

A

an abstract data structure that implements an associative array (dictionary)

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

What is a hash function

A

A hash function is an algorithm that converts a hash key to a hash value

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

What is a hash key

A

The plain text inputted into the hashing function

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

Define Hash value

A

The result of a hashing algorithm

28
Q

What is a collision

A

This occurs when the hash function produces the same hash value for 2 or more keys

29
Q

What is open addressing?

A

a collision resolution technique where collisions are resolved by probing sequentially or using an interval in order find a free position for the hash value

30
Q

What is closed addressing?

A

a collision resolution technique where collisions are resolved by using linked lists. In this way a pointer is stored in the position instead of a hash value which links to a list containing: the key value/ data and the pointer to the next node.

31
Q

What are the requirements for a hash function

A

Must be repeatable/ provide a uniform distribution of hash values/ minimize clustering/collisions and must be fast to compute.

32
Q

Give three different applications of hashing

A

Protection of data such as passwords/ comparing images/ databases

33
Q

How would a computer retrieve data from a hash table that uses open addressing where a collision has occurred.

A

The hash table indexes to the position. It will then iterate until an empty position is found the hash value in question is found.

34
Q

How would a computer retrieve data from a hash table that uses closed addressing where a collision has occurred.

A

The hash table indexes to the position. It will then follow the pointer to the linked list and then iterate until the hash value of interest is found or the list ends.

35
Q

What problem might occur with open addressing

A

Deleted items can be seen as empty positions and hence the collided hash value may never be reached. There needs to be a a distinction between the empty and deleted positions.

36
Q

What is a graph

A

An abstract data type that can be used to represent complex/ non linear relationships between objects

37
Q

What is a meant by a sparse graph

A

A graph where there are very few connections between nodes

38
Q

What is a meant by a dense graph

A

A graph where there are many connections between nodes

39
Q

What is an adjacency matrix

A

A 2D array of vertices containing the connections between all nodes in a graph

40
Q

Advantages of adjacency matrix

A

Ease of access (indexing) allows for swift and efficient testing of nodes.

41
Q

Disadvantages of adjacency matrices

A

Static amount of memory/Can waste space if graph is sparse

42
Q

Best application of adjacency matrices

A

Dense graphs

43
Q

Adjacency List

A

A list that stores all relationships between nodes in the heap.

44
Q

Advantages of adjacency list

A

Easy to add nodes/Memory cannot be wasted as it is only assigned when needed./Dynamically assigned memory

45
Q

Disadvantages of adjacency list

A

Cannot be indexed so has to be iterated through which task more processing time

46
Q

Best application of adjacency list

A

Sparse graph

47
Q

Root Node

A

Starting node in a tree

48
Q

Branch

A

A path from a root to an end point

49
Q

Child

A

A node that comes directly after a node when tracing a path from a root node

50
Q

Parent

A

A node that comes directly before a node when tracing a path from a root node

51
Q

Subtree

A

A tree that is part of another tree.

52
Q

Leaf Node

A

A node that has no children

53
Q

Cycle

A

A closed path that starts and ends at the same node when it only visits a node once

54
Q

Circuit

A

A closed path that starts and ends at the same node but it can visit a node multiple times

55
Q

Loop

A

Edge that starts and finishes at the same vertex

56
Q

Rooted Tree

A

A tree with one node that has been designated as the root

57
Q

Binary Tree

A

A tree where every node has at most 2 children nodes

58
Q

Uses of a trees

A

Pathfinding Family trees Syntax trees

59
Q

What is a stack

A

A stack is an abstract data type that holds an ordered/ linear sequence of items. In contrast to a queue/ a stack is a last in/ first out (LIFO) structure. Stack only needs one pointer

60
Q

What is a queue

A

A queue is an abstract data type that holds an ordered/ linear sequence of items. You can describe it as a first in/ first out (FIFO) structure; the first element to be added to the queue will be the first element to be removed from the queue. Needs two pointers

61
Q

Uses of stacks

A

recursion / Reversing queues / RPN (reverse polish notation)

62
Q

What the three different types of queue

A

Linear/ circular / priority

63
Q

What is a linear queue

A

items are added to the end and removed from the back. Space is not reused

64
Q

What is a circular queue

A

reuses empty space at the front cause by elements being removed. It does this by moving the end pointer to the start and iterating through.

65
Q

What is a priority queue

A

one where each element in the queue has a priority. When new elements are added to the queue/ they are inserted ahead of those of lower priority and behind elements of equal priority.

66
Q

Uses of queues

A

Interrupt buffers Printer queues CPU time management