Week 1 Flashcards

1
Q

Define Time Complexity

A

It is a measure of the amount of time an algorithm takes to complete as a function of the length of the input.

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

Big O Notation

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

Define Space Complexity

A

It is the total amount of memory that an algorithm or operation needs to function relative to the size of the input data.

It can be expressed using Big O Notation

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

What do we intend the algorithm to do?

A

Be detailed and precise such as constraints, edge cases and handling errors

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

Define Pre-conditions

A

Conditions or rules that must be true before the execution of an algorithm or a function.

Such as an array must be sorted first

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

Define Post-Conditions

A

Conditions that must be true after the execution of an algorithm or a function.

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

Define Invariants

A

It is a condition that remains true throughout the execution of an algorithm.

It make sure the algorithm or data structure maintains its integrity and behaves as expected

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

What are the steps for algorithm design?

A
  1. Specification - what you want it to do and write it down
  2. Think, come up with an idea and write down your algorithm step by step
  3. Check if the algorithm does satisfy the specification (post-conditions and invariants)
  4. If necessary, check the Time and Space Complexity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the specification for a linear search?

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

How to perform an algorithm for linear search?

A
  1. Start from the beginning: begin at the first element of the list
  2. Compare each element: Compare the current element with the value you are searching for
  3. Match Found: If the current element matches the search value, return the index of the this element indication the position of the value within the list
  4. Move to the Next element: if the current element is not a match, move to the next element in the list
  5. Repeat the process: Continue steps 2-3 until either find a match or reach the end of the list
  6. End of List: If you reach the end of the list without finding a match, the search value is not in the list and returns -1 as the result.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s the pre-conditions to perform a linear search?

A
  • The list to be searched is accessible and not null
  • The value to be searched for is defined and comparable with the elements in the list
  • The list does not necessarily need to be sorted
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the invariant of performing a linear search?

A

The part of the list that has been searched does not contain the target value. This is maintained through the execution of the algorithm.

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

What’s the post-conditions of performing a linear search?

A
  • If the target value is in the list, the algorithm returns the index of the first occurrence of the value
  • If -1 is returned, then the target value is not in the list
  • The list remains unchanged after the execution of the algorithm
How well did you know this?
1
Not at all
2
3
4
5
Perfectly