2.3 Algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

A* algorithm

A

Approximately finds shortest path between two nodes

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

Big O notation

A

A way or classifying algorithms based on their complexity

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

Breadth first traversal

A

A method of traversing a graph by using a queue to visit all the neighbours of the current node before doing the same to each of the neighbours until the entire graph has been explored

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

Depth first traversal

A

A method of traversing a graph by using a stack to travel as far along one route as possible and then backtracking and doing the same for the remaining routes until the entire graph has been explored

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

What does Dijkstra’s algorithm use

A

A priority queue

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

Space complexity

A

A measure of the amount of memory space needed by an algorithms to solve a particular problem of a given input size

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

Time complexity

A

A measure of the amount of time needed by an algorithm to solve a particular problem of a given input size

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

Constant time complexity O(1)

A

Time taken is independent from number of elements inputted

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

Exponential O(2^n)

A

Double with every item added

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

Polynomial time complexity O(n^n)

A

Proportional to elements inputted to the power of n

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

Processing power and memory

A

More processing power means time complexity is less important whereas lots of memory means space complexity is less important

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

What do you do to reduce the space complexity

A

Perform all of the changes on the original pieces of data

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

What do you do to reduce time complexity

A

Reduce number of embedded loops

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

Best case time complexity for linear search

A

O(1)

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

Best case time complexity for BINARY search

A

O(1)

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

Best case time complexity for BUBBLE sort

A

O(n)

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

How many pointers do stacks use

A

1 for the top of the stack

18
Q

What is the top pointer of a stack initialised as

A

-1

19
Q

Why is the top pointer of a stack initialised as -1

A

When empty, value of 0 would suggest there is an element in the stack

20
Q

Check size of a stack

A

size()

21
Q

check if a stack is empty

A

isEmpty()

22
Q

Return top element of stack but do not remove

A

peek()

23
Q

Add to stack

A

push(element)

24
Q

Remove top element of stack and return removed element

A

pop()

25
Q

Check size of queue

A

size()

26
Q

Check if queue is empty

A

isEmpty()

27
Q

return front element of queue but do not remove

A

peek()

28
Q

remove front element from queue and return removed element

A

dequeue()

29
Q

How can next node be accessed in a linked list

A

N.next

30
Q

First item of linked list

A

Head

31
Q

Last item of linked list

A

tail

32
Q

Best case time complexity for insertion sort

A

O(n)

33
Q

Worst case for every space complexity

A

0(1)

34
Q

Average and worst time case for linear search

A

O(n)

35
Q

Average and worst time case for binary search

A

0(log(n))

36
Q

Average and worst time case for bubble sort

A

O(n^2)

37
Q

Average and worst time case for insertion sort

A

O(n^2)

38
Q

How is dijkstras algorithm implemented

A

Priority queue

39
Q

Example of when dijstras algorithm can be used

A

determine the optimal route to
use when forwarding packets through a network.

40
Q
A