2.3 Algorithms Flashcards

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

What is the Big O Notation?

A

A measure of the complexity of an algorithm.

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

State all the Big O Notations from worst to best in terms of efficiency.

A

O(n!) - Factorial
O(2^n) – Exponential
O(n^2) – Polynomial
O(n) – Linear
O(log n ) – Logarithmic
O(1) – Constant

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

Which Big O Notation has the smallest complexity?

A

O(1) – Constant

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

Which Big O Notation has the largest complexity?

A

O(n!) - Factorial

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

What is the definition of Dijkstra’s Shortest Path?

A

An algorithm for finding the shortest path between nodes in a graph.

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

What are some key facts of Dijkstra’s Shortest Path? ( 3 points)

A
  • Originally depth first (Finds quickest route to one node
  • Then it finds the distances to all nodes
  • It is iterative
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the steps of Dijkstra’s Algorithm? (6 points !)

A
  1. Set distance to first node to 0. Set all others to infinity.
  2. Record the distance from first node to all connected nodes. Mark first node as visited.
  3. Repeat this until done:
    1. Pick next unvisited node with smallest distance.
    2. Record the distance from this node to all connected nodes.
    3. Mark as visited, record the last node we visited.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the definition of the A* Algorithm?

A

A graph traversal algorithm that finds the shortest path between two nodes using heuristics

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

A* vs Dijkstra’s, Advantages and Disadvantages comparing them:

A

A*

+ Only finds route to chosen mode.

+ More efficient if good heuristic chosen.

  • Heuristic must be calculated.

Dijkstra’s

+ Finds distance to all nodes.

  • Slower/ less efficient.

+ Guaranteed to find the best solution.

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

What is a Linear search and what is its complexity?

A

A searching algorithm that checks all items in order.
Time Complexity: O(n)
Space complexity is constant O(1)

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

Why should you use Linear search?

A

List doesn’t need to be sorted.

Can be very quick (if you’re lucky)

Doesn’t require additional memory.

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

How does a linear search work? ( 3 points)

A

Iterate through all items.

When sough item found, record index.

Return index.

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

What is a Binary Search and what is its complexity?

A

A divide and conquer algorithm that splits data until it finds the sought item.
Complexity: O(log n)

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

What are some key facts of the Binary Search?

A

List must be sorted.

Scales very well with large data sets

Doesn’t require extra memory

Runs on a loop ( not recursion)

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

What is the Quick Sort Algorithm and what is its complexity in both the normal and worst case?

A

A recursive, divide and conquer algorithm that sorts a list
Time Complexity: O(n log n)
Time Worse Case: O(n^2)
Space is O(log n)

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

What is a pivot?

A

A chosen point in a list. We aim to have all larger numbers to the right and all smaller numbers to the left.

17
Q

What are some key facts of Quick Sort Algorithm? ( 3 points)

A
  • Recursively splits the list until the length is 1
  • Requires a little extra memory space ( not as much as merge sort)
  • It’s Very quick
18
Q

What is the Bubble sort and what is it’s time and space complexity?

A

A sorting algorithm that swaps pairs of data until a list is in order.

Time complexity – polynomial O(n^2)
Space complexity – Constant O(1)

19
Q

How does the bubble sort work? ( 3 points)

A
  • Looks at every number in the array
  • Swaps the numbers
  • Checks if one of the numbers is greater than another
20
Q

What is an insertion sort and what is it’s time and space complexity?

A

A sorting algorithm that sorts data by placing items into a new list in the correct order

Time complexity – polynomial O(n^2)
Space complexity – Constant O(1)

21
Q

What is the Merge Sort what is it’s time and space complexity?

A

A recursive, divide and conquer algorithm that sorts a list

Time – Logarithmic O(n * log n)
Space – Linear O(n)

22
Q

How does the Merge Sort work?

A
  • Divides lists into two sub-lists until the length is 1
  • Combines sub-lists together in order
23
Q

Merge sort vs Bubble sort, Advantages and Disadvantages comparing them:

A

Merge Sort

  • Scales Well
  • Good for large data set
  • Uses sub-lists so requires more memory space

Bubble Sort

  • Easy to Code
  • Uses a temporary variable when swapping
  • Fast on small data sets
24
Q

What is a Stack?

A

A last in first out( LIFO)
A data structure usually used to store instructions

TIP:
[Think of water going through a pipe and coming out the other side]

25
Q

What is the call stack?

A

A structure to hold the active subroutines and their data

26
Q

What is abstract data structure?

A

A data structure made by the programmer

27
Q

What is a Queue?

A

A static, first in first out structure for ordering data.

TIP:
[Think of a store, first come first served]

28
Q

What does enQueue(item) do?

A

Adds an item to the rear of the list

29
Q

What does deQueue() do?

A

Removes the item from the front of the list

30
Q

What does isEmpty()/ isFull() do?

A

Checks if the list is empty/full