Paper 2 Module 3 Flashcards

1
Q

What is the definition of time complexity?

A

The time complexity of an algorithm is how much time it requires to solve a particular problem.

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

What are properties of O(1) Big O notation time complexity?

A

Constant Time Complexity

The amount of time taken to complete an algorithm is independent from the number of elements inputted.

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

What are properties of O(n) Big O notation time complexity?

A

Linear time complexity

The amount of time taken to complete an algorithm is directly proportional to the number of elements inputted.

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

What are properties of O(n^2) Big O notation time complexity?

A

Polynomial time complexity

The amount of time taken to complete an algorithm is directly proportional to the square of the elements inputted.

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

What are properties of O(n^n) Big O notation time complexity?

A

Polynomial Time

The amount of time taken to complete an algorithm is directly proportional to the elements inputted to the power of n.

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

What are properties of O(2^n) Big O notation time complexity?

A

Exponential time complexity

The amount of time taken to complete an algorithm will double with every additional item.

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

What are properties of O(log n) Big O notation time complexity?

A

Logarithmic time complexity

The time taken to complete an algorithm will increase at a smaller rate as the number of elements inputted.

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

What is the order of time complexities in big(O) notation? Worst to best

A

O(2^n) and O(n^2)
O(n log(n))
O(n)
O(log(n))
O(1)

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

What is the definition space complexity?

A

The space complexity of an algorithm is the amount of storage the algorithm takes.

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

What is the time complexity for a linear search? and why?

A

O(n). This is because linear seach algorithm is an algorithm which traverses through every item one at a time until it finds the item it’s searching for.

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

What is the time complexity of a binary search algorithm?

A

O(log(n)), a binary search algorithm is a divide and concoer algorithm, this means it splits the list into smaller lists until it finds the item it’s searching for, since the size of the list is halved everytime, its O(log(n)).

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

what is the time complexity of a bubble sort algorithm?

A

O(n^2), The bubble sort algorithm passes through the list evaluating pairs of items and ensuring the larger value is above the smaller value. It has a polynomial Big-O notation.

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

What is a stack?

A

It is a data structure that is first in, last out. They are often implemented as an array and use a single pointer (top pointer) to manage the data. The top point is initialised at -1 because the first value to enter is at position 0.

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

What are the operations that you can perform on a stack? and their name?

A

1.Check size = size()
2. check if empty = isEmpty()
3. Return top element (but don’t
remove ) = peek()
4. Add to the stack = push(element)
5. Remove top element from the stack and return removed element = pop()

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

what is a queue?

A

Queues are a type of first in first out data structure. A queue has two pointers the front and the back.

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

what operations can you do on a queue? and what’s their name?

A
  1. Check size = size()
  2. check if empty = isEmpty()
  3. Return front element = peek()
    4 Add to the queue =
    enqueue(element)
    5.Remove front element from the
    queue and return removed element
    = dequeue()
17
Q

What is a linked list?

A

A linked list is composed of nodes, each of which has a pointer to the next item in the list. Searching a list is performed using a linear search, carried out by sequential next operations until the desired element is found.

18
Q

What are trees?

A

Trees are formed from nodes and edges, which cannot contain cycles and aren’t directed. Trees are useful as a data structure because they can be traversed. You can use depth first and breadth first searches for this.

19
Q

How do you do a depth first search?

A

Depth first search goes as far down into the tree as possible before back tracking. The algorithm uses a stack and goes to the left child node of the current node when it can. If there is no left child then the algorithm goes to the right child. If there are no child nodes, the algorithm visits the current node, outputting the value of the node before backtracking to the next node on the stack and moving right.

20
Q

How do you do a breadth first search?

A

Starting from the left, breadth-first visits all children of the start node. The algorithm then visits all nodes directly connected to each of those nodes in turn, continuing until every node has been visited. Unlike depth first, breadth first uses a queue.

21
Q

What is a bubble sort?

A

It is a sorting algorithm that makes comparisons and swaps between pairs of elements. It starts on the first item and compares it to the second.

22
Q

What is insertion sort?

A

It is similar to bubble sort, but it starts on the second item, and comepares it to the item on the left (the first item), a swap stakes place if the second item is larger, if not the program selects the third item. if that is smaller a swap happens and then another comparison is made with the previous values (first value).

23
Q

what is merge sort?

A

It is a sorting algorithm that uses divide and conquour technique. The array is split in half until only 2 items remain groups. The items in the groups are compared and reaasembled with an ordered array.

24
Q

divide and conquer means?

A

It means taking two or more identical, smaller sub-problems from a larger problem, solving the sub-problems individually and combining their solutions to solve the original, larger problem.

25
Steps for a quick sort algorithm.
1. Set a pointer to the first and last in the list. 2. While the first pointer is not equal to the second pointer: a. if the items at the pointers are in the wrong order, swap the items and the pointers. b. Move the first pointer one item towards the second pointer. 3. Repeat from step 1 on the list of items to the left of a pointer. 4. Repeat from step 1 on the list of items to the right of a pointer.
26
What is the dijkstra's algorithm?
it is a pathfinding algorithm that finds the shortest path between two nodes in a weighted graph. It does not used a huristic to find the path.
27
28
what is the A* algorithm?
The A* algorithm is a general path-finding algorith which is an improvement of dijkstra's algorithm and has two cost functions:- 1. The first cost function is the actual cost between two nodes. 2. The second cost function is an approximate cost from the starting node to the end node. This is called a heuristic.