Section 2 Data structures Flashcards

(41 cards)

1
Q

What is a stack frame

A

Stack frames are used to store information about running a program. This is used as a call stack when running programs as it can be used when a subroutine is running to call functions and pass parameters and arguments.

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

What is a stack?

A

A data structure that follows the LIFO (Last In, First Out) principle.

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

What are common stack operations?

A

push, pop, peek/top, isEmpty.

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

Example of stack use?

A

Undo/redo in editors, function call management (call stack).

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

How is a stack implemented?

A

Using arrays or linked lists.

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

What is a queue?

A

A data structure that follows the FIFO (First In, First Out) principle.

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

Common queue operations?

A

Enqueue, dequeue, isEmpty, peek/front.

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

What is a linear queue?

A

It is a FIFO structure organised as a line of data such as a list. The max size of this type of queue is fixed in this case. can be dynamic though

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

What is a circular queue?

A

A queue that wraps around to reuse empty slots when the end is reached.

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

What is a priority queue?

A

A priority queue adds a further element to the queue which is the apriority of each item.

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

Example of queue use?

A

Print spooling, task scheduling, buffering in networks.

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

What is a graph?

A

A collection of nodes (vertices) connected by edges.

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

Difference between directed and undirected graphs?

A

Directed edges have a direction; undirected edges don’t.

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

Difference between weighted and unweighted graphs?

A

Weighted graphs have numerical values (weights) on edges.

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

Ways to represent graphs?

A

Adjacency list (sparse) or adjacency matrix (dense).

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

Graph applications?

A

Social networks, maps, routing.

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

Difference between an adjacency list and a matrix?

A

List: Only stores data where there is an edge, so it takes up less space. The list has to be passed to check for agencies, so it takes more time. Where there is fewer edges, lists are better.
Matrix: Stores a value for every combination of node adjacencies so it requires more memory. Adjacency can be identified more quickly as every combo is already stored. Acts as a look-up table. Where there are many adges this method would be more suitable where there are more edges

18
Q

What is a hash table?

A

A structure that maps keys to values using a hash function.

19
Q

What is a hash function?

A

A function that converts a key into an index in an array.

20
Q

What is a collision?

A

When two keys map to the same index.

21
Q

Collision resolution methods?

A

Linear probing, chaining (linked lists), rehashing.

22
Q

Example use of hash tables?

A

Symbol tables in compilers, caching, Python dictionaries.

23
Q

What is a dictionary in computing?

A

A collection of key–value pairs, where each key is unique.

24
Q

How are dictionaries implemented?

A

Often as hash tables.

25
Key dictionary operations?
insert(key, value), lookup(key), delete(key).
26
Example use of dictionary?
Word-meaning pairs, storing user data by ID.
27
What is a vector?
A dynamic array that can resize automatically as elements are added.
28
Difference between array and vector?
Arrays have fixed size; vectors can grow or shrink.
29
Typical vector operations?
Append, insert, delete, access by index.
30
How are vectors implemented?
When full, allocate a larger array and copy elements.
31
What type of data is best stored using trees?
Data with an inherent hierarchical structure (e.g., file systems).
32
Why are trees described as dynamic data structures?
Because they allow easy addition and deletion of nodes.
33
Why are trees efficient for searching and sorting?
They can be searched and sorted using standard tree traversal algorithms (e.g., in-order traversal).
34
How are trees used in programming languages?
They are used to process syntax of statements, such as in compilers and interpreters.
35
What is a binary search tree (BST)?
A directed and rooted tree where each node has at most two branches (left and right).
36
What type of data is commonly stored in a BST?
Data entered in a random order that needs to be automatically sorted.
37
What is the rule for inserting items into a BST?
If the new item’s value is less than the current node, go left; if greater, go right.
38
How does a BST maintain order?
The structure automatically sorts data as it is entered.
39
What is meant by traversing a BST?
Moving through the nodes to search for or extract data.
40
When does insertion stop in a BST?
When an empty branch is reached — the new value is placed there.
41
Example use of BSTs?
Searching and sorting algorithms, symbol tables, and databases.