[Unit 1.4.2] Data Structures Flashcards

data structures

1
Q

define “data structure”

A

collection of data organised for efficient processing

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

define “primitive data types”

A

single values (integers/floats)

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

define “compound data types”

A

combine primitive data types (records/dates)

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

what is a linear data structure

A

ordering data in a sequential order. each element is connected to the one before and after.

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

what is a non linear data structure

A

data organised with a hierarchy like a family tree

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

what are the two types of linear data structures

A

static:
fixed size, change content. memory allocated at compiler time

Dynamic:
change size, change content. memory allocated during run time as needed.

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

what are records

A

data structures consists of fixed number of attributes (fields/columns)

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

three similarities between records and OOP

A

-bundle related properties together
-define attributes (to manipulate data)
-can have multiple instances

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

four differences between records and OOP

A

-record is data structure. class is template for data structure
-classes have methods
-classes can change visibility of properties
-classes have inheritance

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

what are the features of an array

A

same data type
static
stored contiguously
mutable

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

what are the features of a list

A

different data types
dynamic
stored contiguously
mutable

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

what are the features of a tuple

A

different data types
static
immutable

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

what are the features of a linked list

A

dynamic
data does not have to be stored contiguously
each item is called a node

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

what two features is a node comprised of

A

data and pointer

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

what is the pointer in a node

A

contains the address of the next node

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

what does it mean if a pointer is null

A

end of linked list
node not linked to another (if one has been deleted)

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

what is the head pointer (linked lists)

A

points to location of first node

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

what is the free space pointer and what does it mean if it is null (linked lists)

A

indicates next free element (if null then list is full)

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

what is the tail pointer (linked lists)

A

indicates location of last node

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

what are the three types of linked lists

A

single linked
doubly linked
circular linked

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

what is a single linked list

A

navigation is forwards only

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

what is a doubly linked list

A

navigation can be forwards or backwards
(must have two pointers (previous&next))

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

what is a circular linked list

A

last node links to first node.
can be single linked or doubly linked.

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

differences between array and linked list (4)

A

accessing data faster in array
uses less memory per item in array
array is static data structure
slow to add/remove data in array

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

how do you add a node to a linked list

A

-check free storage pointer is not NULL
-traverse list to free node and add data
-update pointer of previous node to new item
-update pointer of new item to same as previous node used to point to
-if list was empty update head pointer
-update free storage pointer to next free location

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

how do you delete a node from a linked list

A

-check if list is empty (output error if yes)
-traverse to node of item to delete
-update pointer of deleted node to NULL
-update previous node pointer to same as deleted item was
-if deleted node was the first. update head pointer
-update free storage pointer if required

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

how do you traverse a linked list

A

-check if list is empty (error if yes)
-begin at node of head pointer
-print
-follow pointer to next node
-repeat until pointer is NULL (end of list)

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

what is a queue

A

linear data structure that stores elements sequentially.

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

what does FIFO stand for?

A

first in first out

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

what are the two main operations performed on queues

A

enqueue (add to end)
dequeue (remove from start)

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

what are the two types of pointers in a queue

A

front/head
back/rear/tail

32
Q

what happens if you enqueue a full queue

A

queue overflow error

33
Q

what happens if you dequeue an empty queue

A

queue underflow error

34
Q

what are some real life uses of queues

A

print queue
CPU scheduling
modelling situations like traffic jams

35
Q

why are linear queues inefficient

A

they run out of space quickly. you could shuffle up each item after dequeue but this is inefficient and takes time on longer queues

36
Q

what is a circular queue

A

front and rear end are connected
requires less memory
more efficient

37
Q

what is a priority queue

A

each element has a priority

38
Q

how does a priority queue work

A

when you add element. it is inserted ahead of lower priorities, but behind equal or higher priorities.

39
Q

how do you enqueue an item

A

check if queue is full
-print error message if it is
increment rear pointer by 1
add element to location of rear pointer

40
Q

how do you dequeue an item

A

check if queue is empty
-print error message if it is
take item at location of front pointer
increment front pointer by 1

41
Q

how do you enqueue an item in a circular queue

A

check if queue is full
-print error message
change rear pointer to (rear +1) MOD maxsize of queue
add element to location of rear pointer

42
Q

how do you dequeue an item in a circular queue

A

check if queue is empty
-print error message
take item at location of front pointer
change front pointer to (front + 1) MOD maxsize of queue

43
Q

what is a stack

A

linear data structure, stores elements sequentially

44
Q

a stack is a LIFO. what does LIFO mean

A

Last in first out

45
Q

is a stack: static or dynamic?

A

it can be static or dynamic

46
Q

what does push() do

A

add item to top of stack

47
Q

what does pop() do

A

remove item from top of stack

48
Q

define “stack overflow”

A

when you try to push() a full stack

49
Q

define “stack underflow”

A

when you try to pop() an empty stack

50
Q

what are stacks used for

A

reversing order of set of data items
used for calculations
used for handling interrupts.

51
Q

how do you push a stack

A

check if stack is full
-print error message
increment top pointer by 1
add element to location of top pointer

52
Q

how do you pop a stack

A

check if stack is empty
-print error message
take element from location of top pointer
decrease top pointer by 1

53
Q

what are the features of a tree data structure

A

non linear
data represented hierarchically
nodes connected by edges
each tree has a root node

54
Q

define “node”

A

fundamental element of tree. contains data. may link to another node

55
Q

define “root” in terms of a tree data structure

A

top most node in tree.
no parent

56
Q

define “parent” in terms of a tree data structure

A

node has one or more child nodes

57
Q

define “child” in terms of a tree data structure

A

node that descends from another node

58
Q

define “leaf” in terms of a tree data structure

A

node with no children

59
Q

define “edge” in terms of a tree data structure

A

connection between two nodes.
may also be called a pointer

60
Q

define “subtree” in terms of a tree data structure

A

tree formed by a node and its descendants

61
Q

define “binary tree”

A

special rooted tree where every node has, at most, two child nodes

62
Q

define “Binary search tree” (BST)

A

binary tree where nodes are ordered allowing for efficient searching

63
Q

what are the properties of a binary search tree

A
  • nodes of left subtree are less than root node
  • nodes of right subtree are more than root node
  • each subtree is also a BST, has the same properties
64
Q

what are the 3 things in every binary tree

A

data
left pointer
right pointer

65
Q

what are the two types of tree traversal

A

depth first
breadth first

66
Q

what are the three types of depth first tree traversal

A

pre-order
post-order
in-order

67
Q

how does pre order tree traversal work

A

visit root node
traverse left subtree recursively in pre-order
traverse right subtree recursively in pre-order

68
Q

how does post order tree traversal work

A

traverse left subtree recursively in post-order
traverse right subtree recursively in post-order
visit root node

69
Q

how does in-order tree traversal work

A

traverse left subtree recursively in in-order
visit root node
traverse right subtree recursively in in-order

70
Q

define backtracking

A

undoing a step, returning to previous node after exploring all possible paths from the current node

71
Q

how does breadth first tree traversal work

A

visit each node level by level
typically left to right

72
Q

how do you insert an item into a binary search tree

A
  • check if full, output error if so
  • create new node with required data
  • if binary tree is empty the new node becomes first item. create start pointer
  • if it isn’t empty:
  • start at root
  • if new node is less follow left pointer
  • if new node is more follow right pointer
  • repeat until pointer is null
  • if it is less set left pointer to new node
  • if it is more set right pointer to new node
73
Q

how do you delete a leaf node in a binary search tree

A
  • check if node to be removed is less or more than parent
  • if less change left pointer of parent to null
  • if more change right pointer of parent to null
  • add deleted node to free storage list
74
Q

how do you delete a node with one child in a binary search tree

A
  • check if node to be removed is less or more than parent
  • if less, update parent left pointer to point to only child
  • if more update parent right pointer to point to only child
  • add deleted node to free storage list
75
Q

how do you delete a node with two children in a binary search tree

A
  • find smallest value in right subtree and swap with deleted node
  • if there are no left nodes in right subtree, upshift subtree by one
  • delete leaf node (the new one that was swapped)
  • add deleted node to free storage list