Algorithms AQA

0.0(0)
studied byStudied by 4 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/33

Last updated 1:56 PM on 7/26/24
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

34 Terms

1
New cards

What is recursion?

When a function calls itself

2
New cards

What are the 3 rules of a recursive function?

1) Base case (stopping condition)
2) It can reach the base case
3) The subroutine must call itself

3
New cards

What is Big-O notation?

A measure of the time complexity of an algorithm

4
New cards

What is time complexity?

The amount of time needed to solve a problem

5
New cards

What is space complexity?

The amount of resources needed to solve a problem (e.g. memory)

6
New cards

How does a linear search work?

Iterate through a list of items. Stop if you find what you are searching for. Otherwise keep going to the end

7
New cards

What is the time complexity of a linear search?

O(n)

8
New cards

How does a binary search work?

Check the middle value of the list. Compare your value to this value and if it is higher discard the bottom half of the list or vice versa. Keeps halving the list until you find your item or until there are no items left

9
New cards

What is required for a binary search to be able to take place on a list?

The list needs to be sorted

10
New cards

What is the time complexity of a binary search?

O(logn)

11
New cards

How does a bubble sort algorithm work?

Compare the first two elements and swap them if they aren't in the correct order. Keep going through the list comparing pairs of values and swapping if necessary. Repeat this process the number of times as the length of the list

12
New cards

What is the time complexity of a bubble sort?

O(n²)

13
New cards

How does a merge sort algorithm work?

Divide the unsorted list into sublists of each containing one element. Repeatedly merge two sublists at a time to produce new sorted sublists until there is only one sublist remaining

14
New cards

What is the time complexity of a merge sort?

O(nlogn)

15
New cards

What are the two types of graph-traversal algorithms?

Depth-first and breadth-first

16
New cards

How does a depth-first graph traversal algorithm work?

Go as far as you can down a path before backtracking and searching other paths

17
New cards

What data structure does a depth-first algorithm use?

A stack

18
New cards

How does a breadth-first graph traversal algorithm work?

Explore all neighbours of the current vertex, then the neighbours of each of those vertices and so on

19
New cards

What are possible applications of depth-first traversal?

Navigating a maze, Job scheduling where some jobs have to be completed before others begin

20
New cards

What are possible applications of breadth-first traversal?

Finding the shortest path between two points, A web crawler that analyses sites by following links randomly

21
New cards

What is the time complexity of depth-first and breadth-first searches?

In a sparse graph O(n) but if every vertex has the maximum number of edges it is O(n²) as every vertex must be searched and n number of edges from each vertex

22
New cards

What are the 3 different tree traversal algorithms?

Pre-order, in-order, post-order

23
New cards

Which order do you traverse a tree using the 3 (binary) tree traversal algorithms?

Pre-order) Root, Left, Right
In-order) Left, Root, Right
Post-order) Left, Right, Root

24
New cards

What is a use of pre-order?

Copying a tree

25
New cards

What is a use of in-order?

Outputting contents of a binary tree in ascending order

26
New cards

What is a use of post-order?

Emptying a tree

27
New cards

What algorithm can be used to find the shortest path between nodes on a graph?

Dijkstra's shortest path algorithm

28
New cards

What must be true about a graph for Dijkstra's algorithm to work?

It must be weighted

29
New cards

What supporting data structure does Dikjstra's algorithm use?

A priority queue

30
New cards

How does Dijkstra's algorithm work?

1) Set distance to starting node to 0 and all other nodes to infinity
2) Search all connected nodes to starting node and note their value down in priority queue
3) Remove starting node from queue and search all adjacent nodes to the next node in the queue
4) Update any values in the queue if there is a shorter path
5) Dequeue item
6) Repeat until no nodes left in queue

31
New cards

When is a problem defined as being computable?

If there is an algorithm that can solve every instance of it in a finite number of steps

32
New cards

What is a tractable problem?

A problem with a polynomial-time solution (or less)

33
New cards

What is an intractable problem?

A problem that does not have a polynomial-time solution e.g. time complexity O(2^n) and O(n!)

34
New cards

How do we attempt to solve intractable problems with computers?

Come up with heuristic approaches (an imperfect solution but does a good enough job)

Explore top flashcards