Algorithms Flashcards

1
Q

What is time complexity of an algorithm?

A

A measure of how long it takes an algorithm to run based on the size of the input.

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

What is Big-O notation for?

A

Showing the time complexity of an algorithm, used in the form O(f(n)) where n is the input size.

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

What are the search algorithms covered?

A

Linear search, binary search and binary tree search.

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

How does linear search work?

A

By going through an array in order to find the wanted element.

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

How does binary search work?

A

By starting in the middle of a sorted list and ignoring the half of the list that is all greater or less than the desired value.

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

What is the time complexity of a linear search?

A

O(n).

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

What is the time complexity of a binary search?

A

O(log n).

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

What is a binary tree search?

A

Same as a binary search but a tree is used instead of a list.

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

What are the sorting algorithms covered?

A

Bubble, insertion, merge and quick sort.

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

What is bubble sort?

A

A sorting algorithm where you run through the list of items comparing values and moving the larger one up the list so that after each run the largest value is at the top of the list.

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

What is insertion sort?

A

A sorting algorithm where items are moved from an unsorted array to a sorted array one item at a time.

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

How does merge sort work?

A

The list is split into lots of sub-lists starting at length 1 which are sorted as they are joined together.

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

What is the time complexity of bubble sort?

A

O(n^2).

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

What is the time complexity of insertion sort?

A

O(n^2).

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

What is the time complexity of merge sort?

A

O(n log(n)).

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

How does quick sort work?

A

Select a pivot value from the list and place all values bigger than it in one list and all values smaller than it in another and carry out the algorithm again on each sub list until data is sorted. The placing of values into sub-lists is done by having a left and right marker, switching the values at the marker if rightleft move right down one.

17
Q

What is the time complexity of quick sort?

A

O(n log(n)).

18
Q

Advantages and disadvantages of quick sort?

A

Very fast, does not need additional memory like merge sort, however if the split points are towards the ends of the list the time complexity goes to O(n^2).

19
Q

Does depth first traversal of a graph use a stack or queue?

A

Stack as it records the order nodes were visited.

20
Q

Does breadth first traversal of a graph use a stack or queue?

A

Queue as the nodes are added in the order they were found so they are checked first for surrounding nodes.

21
Q

How does depth first graph traversal work?

A

By following a path of nodes until it can no longer continue and backtracking until there are available nodes again.

22
Q

How does breadth first graph traversal work?

A

All nodes adjacent to the current node are visited before moving to the next node.

23
Q

An example of use for a depth first traversal?

A

Finding a way out of a maze.

24
Q

An example of use for a breadth first traversal?

A

Shortest path algorithms, web crawlers.