Chapter 10 - Data Types & Structures Flashcards

(49 cards)

1
Q

record

A
  • a composite data structure used to store of data of different types under one identifier
  • contains a fixed number of fields, each with its own name and type
  • creates a more structured and readable approach to storing and managing data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

array

A
  • ordered, static set of elements
  • can only store 1 data type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

array index

A

identifies the position of each element in the array

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

array lower bound

A

array first element

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

array upper bound

A

array last element

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

what is a linear search

A
  • type of searching method that starts with the first value in a dataset and checks every value one at a time until all values have been checked
  • can be performed even if the values are not in order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

describe the steps of a linear search

A
  1. check the 1st value
  2. IF it is the value required, stop
  3. ELSE, move to the next value and check
  4. REPEAT UNTIL you have checked all values and have not found the value you are looking for
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how does a linear search go through an array?

A

in order, from the lower bound (first) to the upper bound (last)

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

what is a bubble sort?

A
  • it is a simple sorting algorithm that starts at the beginning of a dataset and checks pairs of values and swaps them if they are not in the correct order
  • one complete comparison of the dataset from beginning to end is called a ‘pass’, sometimes multiple passes are needed to fully sort the dataset
  • the bubble sort stops when there are no more swaps to make
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

describe the steps of a bubble sort

A
  1. compare the first 2 values in the dataset
  2. IF they are in the wrong order, swap them
  3. check the next 2 values in the dataset
  4. repeat steps 2 and 3 until the end of the dataset
  5. IF any swaps were made during a pass, REPEAT from the start
  6. ELSE no swaps were made, algorithm stops - the dataset is ordered
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is file handling?

A

the use of programming techniques to work with data stored in files

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

file handling techniques

A
  • opening
  • reading
  • writing
  • closing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

pseudocode for opening a text file for reading

A

OPENFILE file.txt FOR READ

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

pseudocode for opening a text file for writing/creating a new file

A

OPENFILE file.txt FOR WRITE

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

pseudocode for closing a text file

A

CLOSEFILE file.txt

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

pseudocode for reading a line in a text file

A

READFILE file.txt, line

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

pseudocode for writing a line in a text file

A

WRITE file.txt, “string”

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

pseudocode for checking the end of a file

A

IF NOT EOF(file.txt) THEN

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

pseudocode for appending to a file

A

OPENFILE file.txt FOR APPEND

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

what is an abstract data type?

A

a collection of data and a set of operations on that data

21
Q

what are 3 common ADTs

A
  • stacks
  • queues
  • linked lists
22
Q

what is a stack?

A
  • ADT that stores data using the Last In, First Out principle
  • first item pushed onto the stack (added) will be the last one to be popped of (removed)
  • uses a base pointer which points to the first item in the stack and a top pointer which points to the last item in the stack
23
Q

what is the operation for checking if a stack is empty by checking the value of the top pointer?

24
Q

push(value)

A
  • adds a new value to the end of a list
  • needs to check that the stack isn’t full before pushing
25
peek() [for stacks]
- returns the top value of the stack without removing the value - it first checks that the stack is not empty by looking at the value of the top pointer
26
pop()
- removes and returns the top value of the stack - it first checks that the stack is not empty by looking at the value of the top pointer
27
size()
returns the size of the stack
28
isFull()
- compares the stack size to the top pointer to check if the stack is full - returns a boolean value
29
how is data pushed to a stack
1. the stack needs to be checked first if it is full; if an item is pushed onto a full stack a stack overflow error occurs 2. data is pushed to the position of the pointer 3. once pushed, the pointer will increment by 1, signifying the top of the stack
30
how is data popped from a stack
1. the stack needs to be checked first if it is empty; if an item is popped from an empty stack a stack underflow error occurs 2. data is popped from the position of the pointer 3. once popped, the pointer will decrement by 1, signifying the new top of the stack
31
what is a queue?
- an ADT that stores data in the order they arrive, using the First In First Out principle - first item added is the first one removed
32
how do you remove an item from a queue?
deQueue(value) removes item from the front and returns it
33
how do you add an item to a queue?
enQueue(value) adds an item to the back of the queue
34
peek [for queues]
returns the value of the item at the front of the queue without removing it
35
isEmpty()
checks whether the queue is empty
36
isFull() [queues]
checks whether the queue is full (if it has a size constraint)
37
what are linear queues?
data structure that consists of an array
38
how are items added to a linear queue?
1. check that queue is not full 2. if the queue is not full, the item is added to the next available space in the queue starting from the front and the rear index pointer is incremented by 1 3. if the queue was originally empty, both the front and rear pointer must be changed from null to the first index of the queue
39
how are items removed from a linear queue?
1. make sure that queue is not empty 2. if queue is not empty the item at the front of the queue is returned and the front index pointer is incremented by 1
40
what are circular queues?
- static array with a fixed capacity - reuses empty slots at the front of the array left when items are dequeued - as items are enqueued and the rear index pointer reaches the end of the array, it wraps around the array to point to the start of the array as long as the array isn't full - when items are dequeued the front index pointer would wrap around until it passes the rear index pointer, indicating that the queue is empty
41
how are items added to a circular queue?
1. first must check that the queue is not full 2. it is full if the next position to be used is already occupied by the item at the front of the queue 3. if the queue is not full, the rear index pointer moves to reference the next free position so the item can be added
42
how are items removed from a circular queue?
1. first make sure that the queue is not empty 2. if the queue isn't empty the item at the front is returned 3. if this was the only item in the queue the rear and front pointers are reset; if not the front pointer moves to reference the next item
43
what is a linked list?
- an ADT that stores a chain of items called nodes, where each node contains a data field and a pointer (an address) to the next node in the list - new nodes are usually added to the start of the chain, and each node links to the next
44
how to traverse a linked list?
1. check if the linked list is empty 2. start at the node the pointer is pointing to 3. output the item at the current node 4. follow the pointer to the next node repeating through each node until the end of the linked list is reached which is indicated when the pointer field is null/empty
45
what is the advantage of using a linked list?
it is easy to add and remove nodes
46
what are the disadvantages of using a linked list?
- memory is wasted when nodes are "removed" as they are only ignored and not actually deleted - more memory is needed than an array as storing pointers take up space - nodes in a linked list are stored in a sequence and must be traversed in order and cannot be directly accessed as possible in an array
47
how do you add nodes in a linked list?
1. check that there is free memory to insert the new value 2. add the new value to the end of the list and update the NextFree pointer 3. update the pointer field
48
how do you remove nodes from a linked list?
update the pointer field to ignore the node to be removed - this doesn't remove the node, but ignores it, so it is not traversed
49
pseudocode for declaring a 2d array
DECLARE _arrayname_: ARRAY[x, y] OF _datatype_