Section 12 - Algorithms Flashcards

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

Bubble Sort and Insertion Sort

Use a bubble sort to sort the following list:
[9, 5, 4, 15, 3, 8, 11]

A

Check online textbook for answer
Search 350 in page number

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

Bubble Sort and Insertion Sort

Use an insertion sort to sort the following list:
[9, 5, 4, 15, 3, 8, 11]

A

Check online textbook for answer
Search 352 in page number

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

Merge Sort and Quick Sort

Use a merge sort to sort the following list:
[5, 3, 2, 7, 9, 1, 3, 8]

A

Check online textbook for answer
Search 354 in page number

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

Merge Sort and Quick Sort

Use a quick sort to sort the following list:
[9, 5, 4, 15, 3, 8, 11]

A

heck online textbook for answer
Search 356-357 in page number

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

Bubble Sort and Insertion Sort

What is the definition of a bubble sort?

A

A sorting algorithm that repeatedly steps through the input list, element by element, comparing the current element with the one after it, and swapping their values if needed

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

Bubble Sort and Insertion Sort

What is the definition of an insertion sort?

A

A sorting algorithm that builds the final sorted array one item at a time via comparisons

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

Merge Sort and Quick Sort

What is the definition of a merge sort?

A

A comparison-based sorting algorithm that uses divide and conquer to break down the input list into smaller parts before merging them together

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

Merge Sort and Quick Sort

What is the definition of a quick sort?

A

A sorting algorithm that picks an element as a pivot and partitions the input array around the selected pivot by placing the pivot in its correct position in the sorted array

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

Searching Algorithms

When should a linear search be used?

A

When data is not in a particular sequence / order

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

Searching Algorithms

What is the time complexity of a linear search?

A

O(n)
Linear

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

Searching Algorithms

What is the definition of a binary search?

A

A search algorithm that repeatedly divides the data list in half, discarding the half that cannot contain the requested data, until there is only one item in the list

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

Searching Algorithms

What is the definition of a linear search?

A

A search algorithm where data items have to be searched one by one until the required one is found / the end of the list is reached

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

Graph-Traversal Algorithms

What is the difference between depth-first and breadth-first travsersal?

A
  • A depth-first traversal uses a stack
  • A breadth-first traversal uses a queue
    ////
  • In depth-first traversal, we go as far down one route as we can before backtracking and taking the next route
  • In breadth-first travseral, we first visit all the nodes adjacent to A before moving to B and repeating the process for each node at this ‘level’, before moving to the next level
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Optimisation Algorithms

What is Dijksrta’s algorithm?

A

Dijkstra’s algorithm is designed to find the shortest path between one particular start node and all other nodes in a weighted graph

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

Optimisation Algorithms

What is the A* algorithm?

A

The A* algorithm focuses only on reaching the goal node

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

Optimisation Algorithms

Give an example of how Dijkstra’s algorithm and the A* algorithm can be used

A

Dijkstra: GPS navigation
A*: Game character navigation

17
Q

Complexity (not in specific section)

What is constant complexity in O notation?

A

O(1)

18
Q

Complexity (not in specific section)

What is linear complexity in O notation?

A

O(n)

19
Q

Complexity (not in specific section)

What is logorithmic complexity in O notation?

A

O(logn)

20
Q

Complexity (not in specific section)

What is factorial complexity in O notation?

A

O(n!)

21
Q

Complexity (not in specific section)

What is exponential complexity in O notation?

A

O(2^n)

22
Q

Complexity (not in specific section)

What is polynomial complexity in O notation?

A

O(n^2)

23
Q

What is the worst-case time complexity of a binary search?

A

O(logn)

24
Q

What is the worst-case time complexity of a quick sort?

A

O(n^2)

25
Q

What is the worst-case time complexity of a merge sort?

A

O(nlogn)

26
Q

What is the worst-case time complexity of a bubble sort?

A

O(n^2)

27
Q

What is the worst-case time complexity of an insertion sort?

A

O(n^2)