Algorithmic Complexity
Algorithmic Complexity
What is an Algorithm?
A finite collection of sequential, detailed, and unambiguous instructions.
Essentially, a procedure designed to help solve a specific problem.
Counting Instructions
Linear Growth Example (Pt. 0 & 1)
Consider a simple loop:
for(int i = 0; i < n; i++) {
DoSomething(i);
}
Console.WriteLine(c);
To count instructions:
Declaring and initializing the variable
i: instructions.Incrementing
iand checking the loop condition (i < n): This occurs number of times, contributing instructions.Calling
DoSomething(i): This method is executed number of times, contributing instructions.Writing the output (
Console.WriteLine(c)): instruction.
Total number of instructions . This can be generally expressed as , where and are constants.
Nuance in Instruction Counting (Pt. 2)
It's important to question what a