Fundamentals of algorithms Flashcards

1
Q

describe breadth-first

A

shortest path for an unweighted graph

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

describe depth-first

A

Navigating a maze

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

describe pre order

A

copies a tree

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

describe in order

A

outputs the contents of a binary search tree in ascending order

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

describe post order

A

emptying a tree

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

why RPN is used

A

Easier for computer to analyse

Do need brackets so don’t have to keep track of parentheses

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

where RPN is used

A

Used in interpreters based on a stack for example Postscript and bytecode.

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

binary search

A

continually divides a list by two, eliminating the part of the list that cannot have your item in it

O(log n)

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

linear search

A

checks each element to see if it matches the target

O(n)

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

bubble sort

A

swaps the largest with the smallest until list is in order

O(n^2)

{example of a particularly inefficient sorting algorithm, time-wise.}

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

merge sort

A

splits the input into two lists of similar sizes, sorts them recursively and merges them back together into one sorted lists

O(nlog n)

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

applications of shortest path algorithm.

A

navigation system to find most efficient routes between locations

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

recursion vs iteration

A

iterative solutions often start small and build up

recursion solutions often start big and break the problem down

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

pros and cons of iteration and recursion

A

iterative solutions often start small and build up

recursion solutions often start big and break the problem down

pros:

recursive solutions can be more concise and readable

iterative solutions often execute faster

cons:

recursion can run infinitely when the the general case doesn’t move towards the stopping case / can take up more memory

iteration can run infinitely if an indefinite loop is used and the condition never changes

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

recursion

A

Subroutine that calls itself

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

call stack

A

keeps track of subroutines that have started but havent finished