Topic 2:Data Structures Flashcards

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

The static implementation is less efficient at inserting new items into the list than the dynamic implementation.
Explain why this is the case.

A

-Not possible to simply insert item into middle of a list
-Must move all the items that come after the new process down in the array
-Moving items is time consuming/ in dynamic implementation, insertion is achieved by adjusting pointers

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

Explain the differences between a static and data structure.

A

-Static data structures have storage determined at compile time whilst a dynamic structure can grow and shrink during run time
-Static data structure can waste storage space if the number of items stored are relatively smaller than the size of the structure whereas the dynamic only uses the storage space necessary
-Static data structure has fixed size where dynamic can change

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

Explain two differences between a dynamic data structure and a static data structure.

A

-Static has a fixed size pre determined at compile time whilst a dynamic data structure grows and shrinks during run time
-Static structures waste space if the number of items stored are significantly smaller than the size of the structure
-Dynamic structure require memory to store pointers to the next item , static structures store data in consecutive memory locations

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

Explain how a single stack can be used in the implementation of the repeat action and undo action

A

Stack is used to store the pointers actions.
Each time an action is completes it is pushed onto the top of the stack
Unless it is an undo action
When repeat action is used the top item from the stack is used to indicate the action to complete, when the repeat action is used the result of the peek function is used to indicate the action is complete
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
5
Q

State the type of error that occurs if the user tries to complete an undo action before they have completes any other action

A

Stack empty error// stack underflow

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

Explain the situation where it is more appropriate to represent a graph using an adjacency list instead of an adjacency matrix

A

Adjacency list appropriate when there are few edges between vertices // when graph is sparse
When edges rarely change
When the presence/absence of specific edges does not need to be

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

What is an array?

A

A data structure that can store the same data type contiguously in memory .
Has random access to all elements via it’s direct index

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

What is a Linked lists

A

A data structure that can store data non contiguously in memory.
They are dynamic .

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

What is the advantage of an array?

A

They allow random access to the elements

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

What is a disadvantage of an array?

A

They are a static data structure with a fixed sized which is set at compile time

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

What us a hash table?

A

An array that we call a hash table that is coupled in with a hash function. They compose of a primary key and a value(key value pairings).

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

What is a collision?

A

A collision occurs when different inputs produces the same hash

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

How can you avoid a collision?

A

Creating a larger hash table and using a different hash function

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

How do you rehash a table?

A

A larger hash table is created
Each existing value in the table is inserted into the new table
This new position is determined by a new hashing algorithm

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

Explain how a value is stored in a hash table

A

Hashing algorithm is applied to the key
The result is an index of where to store the value in the array
It is possible for a collision to occur when to keys provide the same hash
A collision handling method would be used and this could be using the next available memory location to store the value

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

Why is hashing used?

A

So that searching, adding and deleting can be done efficiently
To speed up searching adding and deleting

17
Q

What is a dictionary?

A

A dictionary is an abstract general purpose data structure.
Used for storing groups of data
Has a set of keys
Each key has a single value associated with it
When the key is supplied the associated value is returned

18
Q

Pairs in a dictionary are held in any sort of order
True or Flase

A

False

19
Q

What is a stack?

A

A FILO abstract data structure (first in last out ). Based on an array. Which has a top pointer

20
Q

What operations are used in a stack data structure?

A

Pop- Remove element from the top of stack
Push-Add an item to the top of stack
Peek-Return the top value of the stack

21
Q

What is a queue?

A

This is an FIFO abstract data structure(FIFO). Which has a front and rear pointer

22
Q

What are the operations applied to a queue?

A

Enqueue- Add an item to the queue
Dequeue- Remove an item from the queue

23
Q

What is a tree?

A

A tree is an undirected, connected graph with no cycles

24
Q

What is a rooted tree?

A

A rooted tree is a tree in which one vertex has been designated as the root

25
Q

What are the advantages and disadvantages of the adjacency matrix?

A

-A:Time efficient(can be searched very easily)
-D:Memory inefficient(stores every possible edge)

26
Q
A