4.2 - Funamentals of data structures Flashcards

1
Q

What is a static data structure?

A

A data structure which reserves memory for a set amount of data. Meaning that it has limited capacity for data

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

What is the advantage of a static array?

A

They are efficient in terms of being able to access elements directly by index

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

What are the disadvantages of a static array?

A
  • Memory is wasted if its full capacity isn’t used
  • if insufficient space has been allocated, the program may crash or not work properly
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a dynamic data structure?

A

A data structure which has a non-fixed memory capacity with the number of data items it can hold only being limited by the overall memory allocation to the program.

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

What are the advantages of dynamic data structures?

A
  • They are memory efficient
  • its size is not predetermined
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the disadvantage of dynamic data structures?

A

The elements cannot be readily accessed directly by index but rather sequentially by memory location

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

What is a queue?

A

An abstract data type that holds an ordered linear sequence of items in the form FIFO

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

How is the order of a queue kept?

A

A pointer is maintained at the front to indicate the element in the front of the queue and a pointer is maintained at the rear to identify the last item in the queue

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

What is an abstract data type?

A

An abstract data type is the building blocks of a data type/data structure, defining the behaviour and properties of it, without specifying its implementation.

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

What is a concrete data type?

A

A concrete data type provides a specific implementation of the abstract data type that determines how the data is stored and accessed in memory.

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

What is a data type?

A

A data type specifies the format of the data and the range of values that can be assigned to it. It defines the set of operations that can be performed on the data and the rules for performing these operations.

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

What is a data structure?

A

A data structure defines the way data is organized and stored in memory. It specifies how the individual data items are related to each other and how they can be accessed and manipulated efficiently.

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

What is a priority queue?

A

A queue where each item inserted into the queue is given a certain level of priority. That item is put in from of all items of a lower priority but ahead of those of higher priority.

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

What are the main operations on a queue?

A

enqueue(data) - adds an element to the queue
dequeue() - returns an element from the front of the queue
is_empty() - check whether the queue is empty
is_full() - check whether the (static only) queue is at maximum capacity

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

Difference between abstract data type and concrete data type?

A

An abstract data type is the framework of the data type, for example a stack is a first in last out data structure and has functions such as pop and append related to it. Whereas a concrete data type is the implementation of the abstraction, for example the stack can be implemented using an array.

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

Examples of data types?

A

Integer: used to represent whole numbers
Float: used to represent decimal numbers
Boolean: used to represent true/false values
Character: used to represent single letters or symbols
String: used to represent a sequence of characters

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

Examples of data structures?

A

Array: a collection of data items of the same type, stored in contiguous memory locations
Linked List: a collection of nodes, each containing data and a reference to the next node in the sequence
Queue: a data structure that allows access to only the oldest added item, using the First-In-First-Out (FIFO) principle
Tree: a hierarchical data structure consisting of nodes, with a single root node and zero or more child nodes at each level

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

What is a linear queue?

A

A queue stored in an array where, as more items are enqueued and dequeued, the pointers move up the array.
It is limited by the length of the array in which it is stored, so the end of the array will eventually be reached if elements are not constantly moved up to the start of the array which can be time consuming.

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

What is a circular queue?

A

A queue which reuses the empty slots at the front of the array when elements are removed from the queue. When the rear pointer reaches the last position of the array, it wraps back round to the start of the array. The front pointer moves similarly as items are dequeued.

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

What is a graph?

A

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

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

What are records?

A

Records are a type of data structure containing several fields used to store data. Each field within a record is usually identified by a name, and the data in each field can be of different types, such as numbers, strings, or dates.

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

What does a graph consist of?

A

Nodes (or vertices) which are connected by edges (or arcs)

23
Q

What makes 2 nodes neighbours?

A

When they are connected by an edge.

24
Q

What is the degree of a node?

A

The number of nodes that is connected to it (i.e. the number of neighbours that it has)

25
Q

What is a loop in a graph?

A

An edge that connects a node to itself

26
Q

How are records implemented?

A

Records are in built data structures in certain languages, however in python you can use a class where each attribute represents a field.

27
Q

What is persistent data (file handling)?

A

Persistent data is data that is stored in secondary storage and will be available whenever the application is used. All persistent data is stored in files.

28
Q

What is a path in a graph?

A

A sequence of nodes that are connected by edges

29
Q

What is a cycle in a graph?

A

A closed path, meaning that it starts and ends at the same node with no nodes being visited more thatn once

30
Q

What is an undirected graph?

A

A graph which allows you to move in either direction between nodes.

31
Q

What is a directed graph?

A

A graph where the edges have direction, meaning that you can only move between nodes in specific directions

32
Q

How can data/persistent data be stored?

A

Persistent data can be stored as a single file, or for larger systems it can be stored a collection of related files. Some applications use databases. Databases are large complex file systems where all of the low level file organisation and access is managed for you. However for smaller applications, a more simple file structure is needed.

33
Q

What is a weighted graph?

A

A graph where its edges have a cost to follow that direction. An example being that the distances between towns.

34
Q

What is a tree?

A

A connected, undirected graph with no cycles and 0 or more child nodes

35
Q

What is a stack?

A

A stack is an abstract data type/structure, that holds an ordered, linear sequence of items. A stack is a first in, last out data structure, meaning items can only be retrieved from the top of the stack.

36
Q

What does it mean that a graph is connected?

A

That there is a path from any node to any other node and no node is disconnected from the others

37
Q

What are the main operations of a stack?

A

push(data): adds an element to the top of the stack
pop(): removes an element from the top of the stack
peek(): returns a copy of the element on the top of the stack without removing it
is_empty(): checks whether a stack is empty
is_full(): checks whether a stack is at maximum capacity when stored in a static (fixed-size) structure

38
Q

What is the difference between a tree and a rooted tree?

A

While a tree can start its traversals from any node on the tree, a rooted tree has a single node (or root) with no parent nodes which all traversals start from

39
Q

What is a hash table?

A

A hash table is a data structure that implements an associative array (a dictionary). In an associative array, data is stored as a collection of key-value pairs. The position of the data within the array is determined by applying a hashing algorithm to the key - a process called hashing. The hashing algorithm is called a hash function.

40
Q

What is the root of tree?

A

The start node for tree traversals in rooted trees

41
Q

What are the advantages of a hash table?

A

A hash table allows for very efficient lookup, insertion, and deletion of values based on their keys. They have an average time complexity of O(1) for lookup, insertion, and deletion operations. Worst-case time complexity for these operations can be O(n), where n is the number of keys in the table, if there are many collisions.

42
Q

What is the leaf of a tree?

A

The end point of a tree graph with no child nodes.

43
Q

What is a branch of a tree?

A

A path from the root (starting node) of the tree to a leaf (end point)

44
Q

What is the height of a tree?

A

The number of edges that connects the root node to the leaf node that is furthest away from it, i.e. the longest branch

45
Q

How many edges does a tree have?

A

The number of nodes minus 1

46
Q

What is a binary tree?

A

A rooted tree where each node has at most 2 child nodes

47
Q

What is a binary search tree?

A

A binary tree which is ordered to optimise searching. For every parent node, the nodes on the left-hand side have a smaller value than the parent node and the nodes on the right-hand side have a large value than the parent node.

48
Q

What is a dictionary?

A

A concrete data structure that defines an unordered collection of data as a set of key-value pairs.
Each key must be unique and has an associated value. The key must be a simple type like integers or strings but the value can be any type

49
Q

What is a hash function?

A

A hash function in a hash table is the algorithm which allocates an index in an array, for each key in the hash table. This means that each key corresponds to an index in the array of values.

50
Q

What are the standard dictionary operations?

A
  • retrieve a value associated with a particular key
  • insert a new key-value pair into the collection
  • remove a key-value pair into the collection
  • update a value associated with a key
51
Q

What is the benefit of using a key to directly access items stored within a dictionary

A

It provides much quicker access to unordered data than searching through the data set using linear search or binary search

52
Q

What is rehashing?

A

Rehashing is the process of creating a new hash table with a larger capacity and moving the key-value pairs from the old table to the new table to reduce collisions and maintain performance.

53
Q

What are the steps of adding an item into a static stack data structure?

A

Check stack is not full, increase rear pointer by one, place item.

54
Q

When is it beneficial to use an adjacency matrix over an adjacency list?

A

When there are more adjacencies between nodes on a graph.