4.2 Types of Data Structures Flashcards

1
Q

What is a composite data type?

A

A data type that can group together multiple values of different types under a single name.

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

What are the two composite data types?

A

String, Array

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

What are abstract data types?

A

A logical description of how we view the data and possible operations.

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

3 Abstract data types

A

List, stack, queue

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

What are elementary data types

A

basic building blocks for representing data and used to define variables and specify the kind of values they can store

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

3 Elementary data types

A

Integer, real, boolean, char

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

Do arrays exist in python?

A

No, have to be imported by a library

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

Key differences between arrays and lists

A

Arrays: defined size, data is stored contiguously in memory
Lists: list is free to grow, values are stored in various locations in memory

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

What are Contiguos elements?

A

contiguous elements are positioned in a continuous, uninterrupted sequence

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

What type of data structure is a queue

A

FIFO (first in first out)

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

Functions needed for a linear queue

A

enqueue
dequeue
peek
Check if the queue is empty
Check if the queue is full

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

What is enqueue and how is it acheived (4)

A

Adding items to a queue
Check that queue is not full
Add to the value of the rear pointer
Then add the new item to the position indicated by the rear pointer.

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

What is dequeing and how is it achieved (4)

A

Removing an item
Return value at the front of the queue and deleter or pop
Move remaining items up the queue one by one
Decrement the rear pointer.

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

Difference between circular and linear queues

A

Circular queues do not move items up when an item is dequeued.

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

What is different with the items in a priority queue

A

All items have a level of priority

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

What are static data structures and what is a example

A

Static data structures are fixed in size
Memory cant be reallocated once the program is running.
Array

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

What are abstract data structures

A

can grow or shrink.
Allocates and deallocates memory from the heap

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

What problem may come with abstract data structures

A

may cause overflow(exceeding maximum memory limit).

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

What is a stack

A

A stack is a last in, first out abstract data type

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

What is a matrix

A

An array of tables or values

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

What are the six methods required in a stack

A

push(item) - adds item to the top of the stack.

pop() - removes and returns the item on top of the stack.

isFull() - checks if the stack is full

isEmpty() - checks if the stack is empty

peek() - returns the top item without removing it from the stack.

size() - return the number of items on the stack.

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

What is stack overflow

A

attempting to push an item onto a stack that is full

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

what is stack underflow

A

attempting to pop from a stack that is empty

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

What is the call stack

A

data structure that provides the mechanism for passing parameters and return addresses to subroutines.

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

What is a stack frame

A

A stack frame contains all the parameters, the return address and the local variables for a single call to a subroutine which has not yet completed.

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

What is a dictionary

A

A dictionary is an abstract data type made up of associated pairs each pair has a key and a value.

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

Why are hash tables used

A

a hash table will find any record in a dataset almost instantly, no matter how large the data set.

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

What is a hash table

A

a data structure that creates a mapping between the keys and values.

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

What causes a collision in a hash table

A

when an algorithm generates the same address for different primary keys.

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

What is the fix for a collision in hash tables

A

linear probing happens, this is where the item is put in the next free slot in the table following a collision

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

What is rehashing (3)

A

process of resizing and reorganizing a hash table when it becomes too full or inefficient.

It involves creating a new, larger hash table

reinserting all existing elements using a new hash function or the same one with a larger table size.

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

What features must a circular queue have

A

They must have a front and rear pointer. They must have a size attribute.

the front pointer is simply adjusted when an item is removed from the queue - the data is not deleted.

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

6 functions/features of a dictionary

A

Add
Delete
Amend
Return the value associated with a key
Return True or False depending on whether the key is in the dictionary,
Return the length of the dictionary.

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

Python function to get a list of the key:value pairs of a dictionary named thisdict

A

x = thisdict.items()

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

Python function to return the keys of a dictionary

A

x = thisdict.keys()

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

How is a new record added to a hash table (3)

A

Hash table has an algorithm applied to the key value,

the result is the location in the table where the record should be stored.

If location is not empty the use next free location.

37
Q

What are graphs

A

Graphs are abstract data structures representing complex relationships between the items of data.

a set of nodes connected by edges

38
Q

What is a weighted graph

A

a type of graph where each edge (connection between nodes) has a numerical value associated with it

39
Q

What is a vertex/node

A

vertices/nodes can represent any discrete object or entity on a graph

40
Q

what is a edge/arc

A

a relationship or connection between two nodes in a graph.

41
Q

What is the difference between directed and undirected graph

A

In an undirected graph, edges do not have a direction associated with them.

In a directed graph, each edge has a direction associated with it.

42
Q

How do adjacency matricies represent a graph

A

For an undirected graph with
n nodes, the adjacency matrix is a
n×n matrix.

43
Q

compare the use of adjacency matrices and adjacency lists to represent graphs

A

Adjacency list appropriate when there are few edges between nodes
when edges rarely change

44
Q

What is a tree

A

a connected, undirected graph with no cycles.

45
Q

What is a rooted tree

A

a tree in which one nopde/vertex has been designated as the root.

A rooted tree has parent-child relationships between nodes.

46
Q

How do we create a dictionary in python

A

my_dict = {key: value, key: value etc}

47
Q

How do we check for a value in a dictionary

A

Use the in keyword

if 2 in mydict.values():
print(True)

48
Q

what are tuples

A

are lists that cant be changed once created, they are an immutable and static.

49
Q

what are dynamic data structures

A

organisations or collections of data in memory that have the flexibility to grow or shrink in size.

50
Q

what are the advantages and disadvantages of dynamic data structures

A

P:
makes efficient use of memory because the data structure only uses as much as it needs.

N:
Risk of overflow
if it exceeds its limit.
Harder to program because it needs to keep track of the data structures size and the location of items inside.

51
Q

What are the advantages and disadvantages of static structures

A

P:
Memory allocation is fixed, which means there will be no issues with adding and removing items from the data structure.

Easier to program

N:
Data set aside at the start may not be utilised.

Memory can’t be reallocated once the program is running

52
Q

A data structures is immutable if

A

The structure/ data cannot be changed during run time

53
Q

what are the applications of stack

A

performing depth first searches on graph data structures

keep track of user inputs

used in RPN

54
Q

What is queue overflow

A

attempting to enqueue an item to a full queue

55
Q

whit queue underflow

A

attempting to dequeuean item from a empty queue

56
Q

describe the steps involved in adding an item to a stack(3)

A

check stack full
increment stack pointer
insert data item at new pointer

57
Q

describe the steps in removing an item from a stack (3)

A

check for stack underflow
copy output data item indicated by back pointer
decrement the rear pointer

58
Q

How do we represent a graph using an adjacency list

A

List all nodes,

Each node points to a list of all the adjacent to nodes to which it is linked

this can be implemented using dictionaries,

graph = {
0: [1, 2],
1: [3],
2: [3],
3: []
}

dictionary keys represent the nodes, values represent connected nodes

59
Q

What are the advantages and disadvantages of representing a graph using an adjacency matrix

A

Checking for presence or absence of an edge only requires checking the corresponding element in the matrix O(1)

A sparse graph with nodes but few edges will mean much of the matrix is empty wasting memory

60
Q

What are the advantages and disadvantages of representing a graph using an adjacency list

(3)

A

Disadvantages:

Checking for presence or absence of an edge requires traversing the linked list of all corresponding nodes O(k)

Advantages:
more space efficient than a matrix for a sparsely connected graph

uses less memory

61
Q

What are the applications of graphs

A

map networks

62
Q

What is an adjacency matrix

A

For a graph with
n vertices, the adjacency matrix
A is an n×n matrix where:

A[i][j]=1 if there is an edge from vertex

A[i][j]=0 if there is no edge between them.

63
Q

What is an adjacency list

A

n adjacency list is another way to represent a graph, using a collection of lists (or dictionaries) where each node stores a list of its adjacent (connected) nodes.

64
Q

What is meant by connected in the definition for a tree, which is a connected undirected graph with no cycles

A

It is always possible to find a path from one node to another

65
Q

What is meant by undirected in the definition for a tree, which is a connected undirected graph with no cycles

A

The edges between nodes are bi-directional there is no arrow pointing in one direction

66
Q

What is meant by no cycles in the definition for a tree, which is a connected undirected graph with no cycles

A

there is no path in the tree that returns to the start node

67
Q

What is a binary tree

A

a rooted tree where each node can only have one, zero or two pointers/edges

each node can have at most two children

68
Q

What are operations that can be performed on a tree

A

add node
delete node
binary search return data in node
traversals
searches

69
Q

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

A

a binary tree is a rooted tree where each node can have at most two child nodes,

rooted tree can have more

70
Q

what are the characteristics of a good hashing algorithim

A

be calculated quickly
result in as few collisions as possible
use as little memory as possible

71
Q

What problems may linear probing cause

A

prevents other items from being stored in their correct location

can result in clustering

72
Q

What is meant by clustering in the context of hash tables

A

when linear probing results in several positions being filled around common collision values

73
Q

What is an alternative to having to deal with collisions when using hash tables (2 ways)

A

By using a 2d hash table

allows for more than one item to be placed at the same position known as chaining

OR

Create an second table for collisions known as an overflow table

74
Q

What are the applications for hash tables

A

file systems linking a file name to the file path

75
Q

What are the three opeartions that can be performed on a hash table

A

Add new item to hash table
Delete
Retrieve

76
Q

Describe the process of adding an item to a hash table

A

Calculate position of item using hash function
If empty insert item
if full, either linear probe or check overflow table

77
Q

Describe the process of removing an item from the hash table

A

calculate position of item using hashing function
if position contains item, delete
if no check overflow table, increment position until item is discovered or end of overflow table is reached

78
Q

Uses of dictionaries

A

Storing and retrieving data efficiently
Implementing other data structures

79
Q

what is a vector

A

a series of numbers that represent information such as position or force

80
Q

what is vector addition known as

A

translation

81
Q

what is the convex combination of two vectors defined as

A

the shaded area between two vectors

82
Q

What is the formula for the convex combination of vectors

A

(a*u) + ( Beta * v)

au + betav

where u and v are vectors
a + beta = 1
a and beta must be larger than 0

83
Q

What is meant by the dot product of two vectors

A

number formed when multiplying each component of the first vector by the matching component of the second vector

then adding those two numbers together

84
Q

What are the applications of dot product.

A

Graphical applications
finding the angle between two vectors

85
Q

Describe how to find the angle between two vectors uding dot product (4 steps)

A
  1. calculate dot product
  2. calculate length of vectors using pythagoras
  3. Multiply the lengths
  4. use formula.

(dot product of vectors a and b) / (lengtha * lengthb) = cosx

86
Q

What is the formula for cos x of two vectors

A

(dot product of vectors a and b) / (lengtha * lengthb) = cosx

87
Q

What is meant by static allocation

A

Memory is assigned at compile-time and does not change at runtime.

88
Q

What is meant by Dynamic allocation

A

Memory is assigned at runtime and can grow or shrink.