Algorithms AQA

studied byStudied by 2 people
0.0(0)
Get a hint
Hint

What is recursion?

1 / 33

flashcard set

Earn XP

34 Terms

1

What is recursion?

When a function calls itself

New cards
2

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

New cards
3

What is Big-O notation?

A measure of the time complexity of an algorithm

New cards
4

What is time complexity?

The amount of time needed to solve a problem

New cards
5

What is space complexity?

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

New cards
6

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

New cards
7

What is the time complexity of a linear search?

O(n)

New cards
8

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

New cards
9

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

The list needs to be sorted

New cards
10

What is the time complexity of a binary search?

O(logn)

New cards
11

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

New cards
12

What is the time complexity of a bubble sort?

O(n²)

New cards
13

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

New cards
14

What is the time complexity of a merge sort?

O(nlogn)

New cards
15

What are the two types of graph-traversal algorithms?

Depth-first and breadth-first

New cards
16

How does a depth-first graph traversal algorithm work?

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

New cards
17

What data structure does a depth-first algorithm use?

A stack

New cards
18

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

New cards
19

What are possible applications of depth-first traversal?

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

New cards
20

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

New cards
21

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

New cards
22

What are the 3 different tree traversal algorithms?

Pre-order, in-order, post-order

New cards
23

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

New cards
24

What is a use of pre-order?

Copying a tree

New cards
25

What is a use of in-order?

Outputting contents of a binary tree in ascending order

New cards
26

What is a use of post-order?

Emptying a tree

New cards
27

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

Dijkstra's shortest path algorithm

New cards
28

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

It must be weighted

New cards
29

What supporting data structure does Dikjstra's algorithm use?

A priority queue

New cards
30

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

New cards
31

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

New cards
32

What is a tractable problem?

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

New cards
33

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!)

New cards
34

How do we attempt to solve intractable problems with computers?

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

New cards

Explore top notes

note Note
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 11 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 11 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 57 people
Updated ... ago
5.0 Stars(3)
note Note
studied byStudied by 18 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 9 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 1418 people
Updated ... ago
4.8 Stars(25)

Explore top flashcards

flashcards Flashcard29 terms
studied byStudied by 297 people
Updated ... ago
4.5 Stars(10)
flashcards Flashcard50 terms
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard80 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard21 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard144 terms
studied byStudied by 12 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard47 terms
studied byStudied by 9 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard49 terms
studied byStudied by 82 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard146 terms
studied byStudied by 10 people
Updated ... ago
5.0 Stars(1)