Data structures Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Explain differences between static data-structures and dynamic data-structures (2 marks)

A

static data-structures have storage size determined at compile time, dynamic data-structures can grow/shrink during run-time
static data structures don’t store pointers so typically use less storage space, whereas dynamic data structures do store pointers to the next item so use more storage space

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

Two differences between static and dynamic data-structures (2 marks)

A

Static data-structures have a storage size determined at compile time, dynamic can grow/shrink in run-time
Dynamic require memory to store pointers to the next items which static data-structures don’t need

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

What is a stack?

A

A Last-In-First-Out (LIFO) abstract data type

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

Why is a static implementation less efficient at inserting new items into a list than a dynamic implementation? (2 marks)

A

Not possible to simply insert an item into middle of list
In a dynamic implementation, insertion achieved by adjusting pointers

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

Explain how a stack can be used to implement a repeat action and an undo action on a stack (5 marks)

A
  1. Stack is used to store user actions
  2. Each time an action is completed it is pushed onto the top of the stack
  3. unless it’s an undo action
  4. when repeat action is used then the top item from the stack is used to indicate the action to complete
  5. when undo action is used the top item is popped from the stack of actions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a graph?

A

A diagram consisting of joining vertices to edges.

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

What is a directed graph?

A

A diagram consisting of vertices, joined by directed edges

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

Explain the circumstances in which it is more appropriate to represent an adjacency list instead of an adjacency matrix (2 marks)

A

(1 mark) Adjacency list appropriate when the graph is sparse
(1 mark) When edges rarely changed

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

Describe a tree data structure

A

No cycles
Has a root node
Each root node has at most 2 child nodes

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

Explain how a value is stored in a hash table (4 marks)

A

-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
-in which case a collision handling method is used

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

Explain the steps of rehashing (3 marks)

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

Why is hashing used? (1 mark)

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

Explain what a hash function is (2 marks)

A

A function applied to a key which generates a hash value

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

Explain what a collision is and how to deal with it (2 marks)

A

When two keys compute the same hash value
Store 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
15
Q

What is a heuristic technique?

A

A heuristic technique employs a method of finding a solution that might not be the best

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

What is a heuristic?

A

Using experience to make an informed guess to find the polynomial time solution to an intractable problem