Data Structures Flashcards Preview

A-Level Computer Science OCR > Data Structures > Flashcards

Flashcards in Data Structures Deck (72)
Loading flashcards...
1

array

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

2

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

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

3

Limitations of arrays:

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

4

record

an un-ordered data structure which is accessed through an attribute. It can store many different data types.

5

What are pythons versions of arrays?

Lists and tuples

6

Tuples

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

7

immutable

structure and data cannot be changed at run time.

8

mutable

structure and data can be changed at run time.

9

Static data structure

size of the structure cannot change at run time

10

Dynamic data structure

size of the structure can change at run time.

11

Stack data structure

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.

12

LIFO

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

13

Queue data structure

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.

14

FIFO

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.

15

Algorithm for insertion into a stack:

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

16

Algorithm for deletion/fetching from a stack:

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
4. Decrement the stack pointer

17

Algorithm for insertion into a queue:

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

Algorithm for deletion/fetching from a queue:

1. Check to see if the queue is empty
2. If the queue is empty report an error and stop
3. Copy data item in location pointed to by the tail pointer/ delete the data item
4. Increment tail pointer and stop

19

linked lists

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.

20

uses of linked lists

1. Implementing undo functionality
2. Dealing with browser cache
3. Helping with operating system job queues

21

Adding data from linked lists:

1. Store the data at the location indicated by the free storage pointer
2. Alter the free storage pointer to the next free storage space
3. Set the pointer for the item that will precede it to the new data item
5. Update the pointer for the new data item to that previously stored in the item the preceded it (i.e. the next data item)

22

Removing data from linked lists:

1. 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
2. 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
3. Update the free storage

23

Traversing data from linked lists:

1. Set the pointer to the start value
2. 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

24

Searching for an item in a linked list:

1. Set the pointer to the start value
2. 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
3. Output data not found

25

Benefits of Hash tables

Speed of lookup, deletion and insertion of items is fast

26

hash table

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.

27

collision

the same hash value is given by two different keys.

28

collision solution

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

29

clustering

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

30

solution clustering

combine hashtable with linked lists as overflow spaces