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: 22 instructions.

  • Incrementing i and checking the loop condition (i < n): This occurs nn number of times, contributing nn instructions.

  • Calling DoSomething(i): This method is executed nn number of times, contributing nn instructions.

  • Writing the output (Console.WriteLine(c)): 11 instruction.

Total number of instructions =2+n+n+1=2n+3= 2 + n + n + 1 = 2n + 3. This can be generally expressed as an+can + c, where aa and cc are constants.

Nuance in Instruction Counting (Pt. 2)
  • It's important to question what a