Computer Science Paper 2

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/170

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

171 Terms

1
New cards

What is Dijkstra's algorithm used for?

Dijkstra's algorithm finds the shortest path between two nodes in a weighted graph.

2
New cards

How does Dijkstra's algorithm prioritize routes?

It uses a priority queue, storing the smallest distances at the front of the list.

3
New cards

What do nodes and edges represent in graphs used in Dijkstra's algorithm?

Nodes can represent devices, and edges represent network traffic.

4
New cards

How are distances represented initially in Dijkstra's algorithm?

Unreachable nodes are denoted by \infty.

5
New cards

What happens in step 2 of Dijkstra's algorithm?

The first node is removed from the queue, and distances to its neighbours are updated.

6
New cards

How does A* algorithm differ from Dijkstra's algorithm?

A* uses two cost functions: actual cost and heuristic cost.

7
New cards

What is a heuristic in the context of the A* algorithm?

A heuristic is an approximate cost to reach the final node from a given node.

8
New cards

In the A* algorithm, how is total cost calculated?

Total cost is calculated by adding the actual cost and the heuristic cost.

9
New cards

What is a key advantage of using the A* algorithm?

It can reduce the total time taken to find the shortest path by prioritizing nodes with lower total costs.

10
New cards

What requirement must edge weights meet for Dijkstra's algorithm to work optimally?

All edge weights must be non-negative (w \geq 0).

11
New cards

What is the initial distance value assigned to the starting node in Dijkstra's algorithm?

The starting node is assigned a distance of 0.

12
New cards

If the heuristic function in the A* algorithm is always 0, which algorithm does it become equivalent to?

It becomes equivalent to Dijkstra's algorithm.

13
New cards

In the A* cost formula f(n) = g(n) + h(n), what does g(n) represent?

g(n) represents the actual cost of the path from the starting node to node n.

14
New cards

What does it mean for a heuristic in A* to be 'admissible'?

An admissible heuristic never overestimates the actual cost to reach the goal, ensuring an optimal solution is found.

15
New cards

What is the purpose of searching algorithms?

Searching algorithms are used to find a specified element within a data structure.

16
New cards

What conditions must be met for the binary search algorithm to be applied?

The binary search algorithm can only be applied on sorted data.

17
New cards

What is the time complexity of the binary search algorithm?

The time complexity of binary search is O(\log n).

18
New cards

Describe the process of the binary search algorithm?

The binary search algorithm finds the middle element, discards one half of the data based on comparisons, and repeats this until the element is found or confirmed not to exist.

19
New cards

Give an example of finding an element using binary search. What happens if the element is not found?

In the example of finding 'Dylan', the algorithm iteratively narrows down the search; if 'Hattie' is not found, it returns 'Not found in data'.

20
New cards

How does linear search operate?

Linear search checks each element one by one until it finds the desired element or reaches the end of the list.

21
New cards

What is the time complexity of linear search?

The time complexity of linear search is O(n).

22
New cards

What advantage does linear search have compared to binary search?

Linear search can be applied to unsorted data unlike binary search.

23
New cards

What was the key observation made when comparing linear search and binary search using the first 20 letters of the alphabet?

Linear search is less efficient than binary search, particularly when the search value is towards the end of the data.

24
New cards

What is the best-case time complexity for both linear and binary search?

The best-case time complexity is O(1), which occurs when the target element is the first one inspected (the first element in linear search or the middle element in the first step of binary search).

25
New cards

What is the worst-case scenario for a linear search?

The worst-case occurs when the target element is the last item in the list or is not present at all, resulting in O(n) comparisons.

26
New cards

What is the space complexity of an iterative searching algorithm?

The space complexity is O(1) because the algorithm only requires a constant amount of extra space regardless of the size of the dataset n.

27
New cards

How is the middle index calculated in binary search to avoid potential integer overflow?

It is typically calculated as mid = low + (high - low) / 2 instead of (low + high) / 2.

28
New cards

In what scenario is linear search preferred over binary search?

Linear search is preferred when the dataset is small, unsorted, or when the data structure does not support random access (such as a standard linked list).

29
New cards

What are sorting algorithms designed to do?

They are designed to take a number of elements in any order and output them in a logical order, usually numerical or lexicographic.

30
New cards

Which sorting algorithms are mentioned in the lecture?

Bubble sort, Insertion sort, Merge sort, Quick sort.

31
New cards

What is bubble sort?

A sorting algorithm that compares and swaps adjacent pairs of elements until the largest element bubbles to the top of the array.

32
New cards

How does bubble sort determine when to terminate?

It can terminate early if a full pass is made without any swaps, indicating the array is sorted.

33
New cards

What is the time complexity of bubble sort?

O(n^2).

34
New cards

What does insertion sort do?

It places elements into a sorted sequence, building the sorted array one element at a time.

35
New cards

What is the time complexity of insertion sort?

O(n^2).

36
New cards

What is merge sort?

A 'divide and conquer' algorithm that recursively divides an input until it is reduced to single elements, and then merges them back in sorted order.

37
New cards

What is the time complexity of merge sort?

O(n \log n).

38
New cards

How does quick sort function?

It selects a pivot element and partitions the other elements into two lists, according to whether they are less than or greater than the pivot.

39
New cards

What is the time complexity of quick sort in the worst case?

O(n^2).

40
New cards

What is the average time complexity of quick sort?

The average time complexity is O(n \log n), which occurs when the pivot splits the array into relatively equal halves.

41
New cards

What is the space complexity of merge sort?

Merge sort has a space complexity of O(n) because it requires additional memory to store the temporary subarrays during the merge process.

42
New cards

What does it mean for a sorting algorithm to be 'in-place'?

An algorithm is 'in-place' if it requires a constant amount of extra space, or O(1) space, to sort the data (e.g., Bubble sort and Insertion sort).

43
New cards

What is a 'stable' sorting algorithm?

A sorting algorithm is stable if it preserves the relative order of records with equal keys.

44
New cards

What is the best-case time complexity for insertion sort?

The best-case time complexity is O(n), which happens when the array is already sorted.

45
New cards

How does the partitioning step work in quick sort?

Partitioning involves picking a pivot and moving all elements smaller than the pivot to its left and all elements larger to its right.

46
New cards

What type of data structure is a stack?

A stack is a first in, last out (FILO) data structure.

47
New cards

What does the top pointer in a stack indicate?

The top pointer indicates the position of the current top element of the stack.

48
New cards

How is the isEmpty function for stacks implemented?

It checks if the top pointer is less than 0.

49
New cards

What does the push operation do in a stack?

The push operation adds an element to the stack.

50
New cards

What operation removes the element from the top of the stack?

The pop operation removes the top element from the stack.

51
New cards

What type of data structure is a queue?

A queue is a first in, first out (FIFO) data structure.

52
New cards

How do you check if a queue is empty?

You check if the front pointer is equal to the back pointer.

53
New cards

What is the purpose of the enqueue operation?

The enqueue operation adds an element to the back of the queue.

54
New cards

What does the dequeue operation do?

The dequeue operation removes the front element from the queue.

55
New cards

What is the first element in a linked list referred to as?

The first element is referred to as the head.

56
New cards

What type of search is performed on a linked list?

A linear search is performed using sequential next operations.

57
New cards

What is the depth-first traversal approach?

Depth first goes as far down the tree as possible before backtracking.

58
New cards

What type of data structure is used in breadth-first traversal?

Breadth-first traversal uses a queue to track nodes at the current level.

59
New cards

What is the result of a depth-first traversal starting from the node labelled 5?

The order of output will be 2, 4, 3, 8, 5.

60
New cards

What algorithm is used for traversing trees in depth first (post-order)?

Depth-first search goes left until no more child nodes are available.

61
New cards

What is depth-first traversal's output method?

Output nodes as they are passed on the right.

62
New cards

What defines the tail of a linked list?

The tail refers to the last item in the linked list.

63
New cards

What is the peek operation in a stack?

The peek operation returns the value of the top element without removing it from the stack.

64
New cards

What is stack overflow?

Stack overflow occurs when an attempt is made to push an element onto a stack that has reached its maximum memory capacity.

65
New cards

What characterizes a doubly linked list?

A doubly linked list contains nodes that have a reference to both the next node and the previous node.

66
New cards

Why is a circular queue used?

It is used to reuse empty spaces at the front of the queue that occur after dequeue operations, maximizing memory efficiency.

67
New cards

How does pre-order tree traversal function?

It visits the root node first, then the left subtree, and finally the right subtree.

68
New cards

What is the time complexity of pushing an item onto a stack?

The time complexity is O(1), as it is a constant time operation.

69
New cards

What is a priority queue?

A specialized queue where each element has a priority, and elements with higher priorities are dequeued before those with lower priorities.

70
New cards

How does in-order traversal work in a Binary Search Tree (BST)?

It visits the nodes in ascending order by traversing the left subtree, the root, and then the right subtree.

71
New cards

What two pieces of information allow you to analyse an algorithm?

● Time Complexity.

● Space Complexity.

72
New cards

What is meant by the time complexity of an algorithm?

The amount of time required to solve a particular problem.

73
New cards

How do you measure of the time complexity?

Big-O Notation

74
New cards

What does the big-O notation show?

The effectiveness of an algorithm.

75
New cards

What is the Big-O notation good for?

It allows you to predict the amount of time taken to solve an algorithm given the number of items stored.

76
New cards

What does a linear time complexity mean?

The amount of time taken to complete an algorithm is independent from the number of elements inputted.

77
New cards

What does a constant time complexity mean?

The amount of time taken to complete an algorithm is independent to the number of inputted elements.

78
New cards

What does a polynomial time complexity mean?

The amount of time taken to complete an algorithm is proportional to the number of items inputted to the power of n.

79
New cards

What does an exponential time complexity mean?

The amount of time taken to complete an algorithm is proportional to 2 to the power of the number of items inputted.

80
New cards

What does a logarithmic time complexity mean?

The time taken to complete an algorithm will increase at a smaller rate as the number of elements inputted.

81
New cards

What is a logarithm?

How many times a certain number (base) is multiplied together to reach another number.

82
New cards

What is space complexity?

The space complexity is the amount of storage space an algorithm takes up.

83
New cards

What is an algorithm?

An algorithm is a series of steps that complete a task.

84
New cards

How do you reduce the space complexity?

Try to complete all of the operations on the same data set.

85
New cards

How do you reduce the time complexity of an algorithm?

You reduce the amount of embedded for loops, and then reduce the amount of items you complete the operations on i.e. divide and conquer.

86
New cards

What is the Big-O notation of a linear

search algorithm?

O(n)

87
New cards

What is the Big-O notation of a binary search algorithm?

O(log(n))

88
New cards

What is the Big-O notation of a bubble sort algorithm?

O(n^2 )

89
New cards

What is meant by a computable problem?

A problem that can be solved using an algorithm.

90
New cards

Give three limiting factors to computable problems

Three from:

● Processing power

● Processor speed

● Computer memory

● Time

91
New cards

State two factors which may be considered during the Problem Definition phase

- Strengths and weaknesses of current solution.

- Volume/type/frequency/nature of.

- Inputs

- Outputs

- Stored data

92
New cards

What is the name given to the process in which problems are continually broken down until each subproblem can be represented as a subroutine?

Problem Decomposition

93
New cards

State two purposes of problem decomposition

Two from:

- Identify sections which can make use of pre-coded modules or libraries.

- Save timecoding.

- Simplify project management.

- Simplify testing and maintenance.

- Faster project delivery.

- Develop sections in parallel.

94
New cards

Describe how the Divide and Conquer technique works

The problem size is halved with every iteration. Each individual subproblem is then solved recursively. The solutions to the subproblems are then recombined to form the final solution to the problem.

95
New cards

Give two applications of divide and conquer

Two from:

- Merge sort

- Binary search

- Quick sort

96
New cards

Which programming construct do many problems solved using Divide and Conquer use?

Recursion

97
New cards

What is representational abstraction?

A computational technique in which excessive details are removed to simplify a problem.

98
New cards

What type of abstraction is used to group together sections of the problem based on their functionality?

Abstraction by generalisation.

99
New cards

State two problem solving techniques

Two from:

- Backtracking

- Data mining

- Abstraction

- Divide and conquer

- Visualisation

- Performance modelling

- Pipelining

- Visualisation

100
New cards

Describe how backtracking works.

The backtracking algorithm works by methodically visiting each path and building a solution based on the paths found to be correct. If a path is found to be invalid at any point, it backtracks to the previous stage and visits an alternate path.