Courses / HEC NSCT – National Skill Competency Test: Complete Preparation for Computing Graduates

1.6 Debugging, Error Analysis and Complexity Awareness

Area 1 – Problem Solving & Analytical Skills (20%) · 40 min read · 15 MCQs to check yourself

Three kinds of errors

Error When it appears Example
Syntax Before running (compiler/interpreter rejects) Missing bracket or colon
Runtime While running – program crashes Division by zero, index out of range, null reference
Logical Program runs but answer is wrong Using > instead of >=, off-by-one loop

Debugging steps

Reproduce the bug → isolate (print/log or breakpoint) → find the root cause → fix → retest (and add a test so it never returns).

Off-by-one errors

A loop for i = 0; i <= n; i++ runs n + 1 times; for i = 0; i < n; i++ runs n times. Arrays of size n have indices 0 … n − 1.

Complexity awareness

Code shape Growth
One loop over n items O(n)
Loop inside loop O(n²)
Halving each step (binary search) O(log n)
Sort then scan O(n log n)
Prefer the lower growth when n is large – 1,000,000 items × O(n²) is far too slow.

Best debugging tips for beginners (Web Dev Simplified)

This lesson ends with a quiz of 15 MCQs. Open the lesson on PrepOasis to take it and save your progress.

Previous: 1.5 Data Interpretation and Critical Thinking · Next: Area 1 Review, Checklist and Area Test

All lessons in HEC NSCT – National Skill Competency Test: Complete Preparation for Computing Graduates