Data structure Flashcards

1
Q

array

A

An array allows you to store multiple items of the same data type under a shared common name.

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

Arrays can store data of the same data type contiguously in memory. This means…

A

… random access to all element is available via its direct index.

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

Limitations of arrays:

A

A
They can only store one data type
- They’re a static data structure (their scope is predetermined)

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

record

A

an unordered data structure which is accessed through an attribute. It can store many different data types

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

What are pythons versions of arrays?

A

Lists and tuples

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

Tuples

A

Tuples are lists that cannot be edited and is said to be immutable.

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

immutable

A

structure and data cannot be changed at run time.

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

mutable

A

structure and data can be changed at run time.

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

Static data structure

A

size of the structure cannot change at run time

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

Dynamic data structure

A

size of the structure can change at run time.

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

Stack data structure

A

A stack is known as a LIFO, a single pointer is used to point to the top item of the stack, when a new item is pushed onto the stack the pointer is incremented. When an item is popped off the stack the pointer decrements to point to the new top of the stack.

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

LIFO

A

last in first out - the last item you push to the top of the list is the first item you pop off the stack.

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

Queue data structure

A

A queue is known as a FIFO structure. A pair of pointers is used to point to the front and back of the queue. If an item is popped from the queue the front pointer points to the item being popped. If an item is pushed onto a queue the tail pointer increments by one and points to the new end of queue.

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

FIFO

A

first in first out - because the new items get pushed to the back of the queue and new items get popped from the front of the queue.

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

Algorithm for insertion into a stack:

A

1)Check to see if the stack is full
If the stack is full report error
and stop
2)Increment the stack pointer
Insert new data item into
location pointed to by the
stack pointer and stop

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

Algorithm for deletion/fetching from a stack:

A

1)Check to see if the stack is empty

2)If the stack is empty report an error and stop

3)Copy the data item in location pointed to by the stack pointer/ delete the data item
Decrement the stack pointer

17
Q

Algorithm for insertion into a queue:

A

1)Check to see is the queue is full

2)If the queue is full report an error ad stop

3)Insert new data item into location pointed to by the head pointer

4)Increment the head pointer and stop

18
Q
A
19
Q

LIFO

A

last in first out - the last item you push to the top of the list is the first item you pop off the stack.

20
Q

Queue data structure

A

A queue is known as a FIFO structure. A pair of pointers is used to point to the front and back of the queue. If an item is popped from the queue the front pointer points to the item being popped. If an item is pushed onto a queue the tail pointer increments by one and points to the new end of queue.

21
Q

FIFO

A

first in first out - because the new items get pushed to the back of the queue and new items get popped from the front of the queue.

22
Q

Algorithm for insertion into a stack:

A

Check to see if the stack is full

If the stack is full report error and stop

Increment the stack pointer

Insert new data item into location pointed to by the stack pointer and stop

23
Q

Algorithm for deletion/fetching from a stack:

A

Check to see if the stack is empty

If the stack is empty report an error and stop

Copy the data item in location pointed to by the stack pointer/ delete the data item
Decrement the stack pointer

24
Q

Algorithm for insertion into a queue:

A

Check to see is the queue is full

If the queue is full report an error ad stop

Insert new data item into location pointed to by the head pointer

Increment the head pointer and stop

25
Q

Algorithm for deletion/fetching from a queue:

A

Check to see if the queue is empty

If the queue is empty report an error and stop

Copy data item in location pointed to by the tail pointer/ delete the data item
Increment tail pointer and stop

26
Q

linked lists

A

A list of data together with a set of links to sort the data. Data is stored in the order its input and pointers are used to link the data into the desired order

27
Q

uses of linked lists

A

Implementing undo functionality
Dealing with browser cache
Helping with operating system job queues

28
Q

Adding data from linked lists

A

Store the data at the location indicated by the free storage pointer

Alter the free storage pointer to the next free storage space

Set the pointer for the item that will precede it to the new data item

Update the pointer for the new data item to that previously stored in the item the preceded it (i.e. the next data item)

29
Q

Traversing data from linked lists

A

Set the pointer to the start value
Repeat:
a. Go to the node
b. Output the data at the node
c. Set the pointer to the value of the next item pointer at the pointer
d. until pointer = 0/null

30
Q

Removing data from linked lists

A

If the item to remove is in the first position
a. Then update starting pointer value of item you want to delete and update all the pointers
Else if the item is in any other position
a. Update the pointer value in the preceding node from the one you want to delete to the value of the pointer in the item to be removed and all the succeeding data items pointers
Update the free storage

31
Q

Searching for an item in a linked list

A

Set the pointer to the start value
Repeat:
a. Go to node (pointer value)
b. If the data at the node is the search item
i. Then Output the data and stop
c. Else
i. Set the pointer to the value of the next item pointer at the node
d. Until pointer = 0
Output data not found

32
Q

Benefits of Hash tables

A

Speed of lookup, deletion and insertion of items is fast

33
Q

hash table

A

an array which is coupled together with a hash function. The value from the hash function (hash value) maps the initial key to a fixed index in the hash table

34
Q

collision

A

the same hash value is given by two different keys.

35
Q

collision solution

A

Storing the key in the next available space
- adding a linked list to the location where the hash value is repeated

36
Q

clustering

A

when there is a collision and the key is stored in the next available space increasing the likelihood of collisions