Fundamentals of Data Structures Flashcards

1
Q

What is a queue?

A

A FIFO (First in, first out) data structure

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

What is a stack?

A

A LIFO (Last in, first out) data structure

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

What’s a graph?

A

A data structure made up of nodes which have a cyclical structure

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

What is a tree?

A

A data structure made up of nodes which isn’t cyclical.

Usually hierarchical.

The top level is known as the “root node”

The bottom level nodes are known as “leaf nodes”

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

What is a hash table?

A

A data structure where a hash function is used to mark the position in the table where data should be stored.

This allows us to access data directly rather than a search

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

What is a dictionary?

A

A collection of key-value pairs in which the value is accessible via the associated key

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

What is a dynamic data structure?

A

A data structure that changes in size to store their contents.

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

What is a static data structure?

A

A method of storing data where the amount of data stored (and memory used t store it) is fixed

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

Discuss the advantages and disadvantages of dynamic data structures compared to static data structures.

A

Advantages of dynamic:
There’s no wasted memory, static allocates at creation dynamic allocates as it’s needed.
No limit on the number of items which can be added, static has a finite/fixed limit.

Disadvantages of dynamic:
Can take longer to add a new item to the structure, because it has to allocate memory.
Can cause a memory leak, if memory that’s no longer needed isn’t returned to the heap

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

What is a linear queue?

A

Organised as a list or line of data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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; [increment address]

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
12
Q

What is a priority queue?

A

Queue where each item has a priority, and items are kept sorted with the highest priority item in front (priority is signified as subscript numbers)

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

What is a circular queue?

A

The last node is connected back to the first node in nature

Its static; has a limited number of elements

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

What is meant by the term ‘push’?

A

A process which adds an item to a data structure typically to a stack.

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

What is meant by the term ‘pop’?

A

A process which removes an item from a data structure typically from a stack.

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

What is meant by the term ‘peek’?

A

A process which allows you to inspect a data structure and returns the item at the front or top without removing it.

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

What is a weighted graph?

A

A graph in which each edge has a value associated with it

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

What is an Adjacency Matrix used for?

A

To represent a graph by listing each node and indicating where there is an edge between pairs.

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

What is an Adjacency List?

A

A collection of lists used to represent a finite graph, where each list escribes the set of adjacent nodes in the graph.

20
Q

How do you make an Adjacency Matrix?

A

Look at graph, if there is an edge between them, put a 1.
If not, put a 0.

If it’s weighted:
Instead of 1, put the weight. If no edge, put infinity symbol.

On directed graph only do when you could go in that direction.

21
Q

When is it good to use an adjacency list instead of an adjacency matrix?

A

When the graph is sparse.

When edges are rarely changed.

22
Q

What is a rooted tree?

A

A tree in which one node has been designated as the root and ever edge is directed away from it.

23
Q

What is binary tree?

A

A tree where each node can only have 0, 1 or 2 leaf nodes

24
Q

Describe the steps involved in adding a record to a hash table

A

Take your key value and put it through a hashing algorithm.

The hash number (the result) is the location in the table where the data should be stored.

If the location found isn’t empty:

A hash collision has occurred, and you should move onto the next available location.

With large lists, a hash cluster may occur where many data items aren’t in the correct location as per the hashing algorithm. Instead, you can create a linked list and store multiple pieces of data in the same location

25
Q

What is a linked list?

A

A list of nodes or elements of data connected by pointers

26
Q

What is meant by the term ‘hash collision’?

A

When two different inputs to a hash function produce the same output as a hash value

27
Q

What is meant by the term ‘rehashing’?

A

Increasing the size of a hash tables array and restoring all the items into the array using the hash

Typically happens when a hash table starts to become full or when an insertion fails

28
Q

What is hash clustering?

A

After a hash collision, you put it in another memory address near to the desired one because it was full.

But then if you want to add something else which should have the memory address that was just taken, it’ll then create another collision.

This will repeat that process; this can get tedious with a large block of data.

29
Q

What is hash overflow?

A

Overflow attempts to overcome clustering by using a linked list

If a collision occurs, it creates a linked list which is attached to the collision key.

Instead of going to the next memory address it attaches a “tail” to the data currently in the desired memory address. So, you go the memory address, check if the data is the one you’re looking for; if not move down the “tail”

30
Q

What is a Stack Frame?

A

A structure stored on the stack where all information associated with a function call is recorded.

This could include Parameters, Local Variables

31
Q

What is a Pointer?

A

A variable which stores the memory address of another variable.

32
Q

What is an opcode?

A

Mathematical command

33
Q

What is an operand?

A

data

34
Q

What is Dot/Scalar product?

A

An algebraic operation that takes two equal-length sequences of numbers (usually coordinate vectors) and returns a single number.

[1,3]
[4,5]

Dot product = 1x4 + 3x5 = 19

35
Q

How do pointers work in a queue?

A

when an item is removed from a queue the front pointer moves to the next item that is now at the front of the queue.

when an item is added to a queue the rear pointer points at the newly added item.

36
Q

How can you implement a linear queue as an array or list?

A

two ways:

  1. as items leave the queue, all of the other items move up soi that the front of the queue is always the first element of the structure.
  2. a linear queue can be implemented with pointers to the front and rear of the queue. An integer holding the size of the array is needed, as well as a variable giving the current number of items in the queue. When items are added and removed from the queue a space is created at the front of the queue which cannot be filled, and items are added until rear pointer points to the last element of the data structure.
37
Q

What is meant by the term ‘heap’ in relation to dynamic data structures?

A

the portion of memory from which space is allocated and de-allocated as required.

38
Q

Functions of a call stack

A

store information about active subroutines while a computer program is running.

call stack keeps track of addresses of the instruction that control should return to when subroutine ends.

parameters required for a subroutine may be held on a call stack, each call to a subroutine will be given a space on the call stack for these values.

local variable are also held on a call stack because its much more efficient than using dynamic memory allocation, which uses heap space.

39
Q

What algorithm is used to find the shortest path on a unweighted graph?

A

Breadth First Traversal

40
Q

How do you search for an item in a Hash Table?

A

When an item is looked up in a hash table, the key is hashed . This hash code is used as an index into the hash table to locate the item

41
Q

How do you delete a value from the Hash Table?

A

Search for item you wish to delete. Once the key is found remove the key-value pair from the list.

42
Q

How do you add an item to a circular queue?

A
  1. Check if full
  2. If not full, increment the rear pointer (wrap around if needed)
  3. Add item to the rear position
43
Q

How to remove item from circular queue?

A
  1. Check if empty
  2. If not empty increment the front pointer by 1
  3. Dequeue element from front of queue
44
Q

Describe the steps involved in adding an item to a priority queue.

A

Starting from rear of queue, move each item back one place.

Until you reach the start of the queue or an item with the same or higher priority.

Add the new item before that item.

45
Q

What is a vector?

A

A vector can be represented as a list of numbers, a function, or a way of representing a geometric point in space

46
Q

Advantages of a circular queue over a linear queue?

A

Circular queues use memory more efficiently by reusing space,

have faster enqueue and dequeue operations,

are simpler to implement since they avoid shifting elements,

and are suitable for memory-constrained applications due to their efficient use of available memory.