0% found this document useful (0 votes)
10 views

DebuggingTemplate

Uploaded by

amitvaghamshi9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

DebuggingTemplate

Uploaded by

amitvaghamshi9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

BEGIN HERE

You have written some logical


code snippet and now stuck at a
point, where you need to resolve
some error/s
Start Click on the 'RUN' button

Some common examples of this


error

Is your code
Steps to missing semicolon , missing
colo
'Compilation/ Syntax Error'
compiling No
has occured Fix Errors typo in reserved/keywor
incorrect braces closing or
successfully? indentation error
- Link mismatch/ absence in function
return type and return
statemen
How to identify:
incorrect impor
Compilation failed because of undeclared variable
‘Wrong Syntax’ and an error End of File error
message appears which helps
identify the error.
Yes

Some common examples of

this error

Steps to
Division by zer
Accessing array out of its limi
Null pointer exceptio
Is your program
crashing? Yes 'Runtime Error' has occurred Fix Errors Memory/stack overflow/
segmentation faul

- Link
Variable casting error
Index Out Of Bound Exception -
check edge cases and data
type overflow and sizes (if
How to Identify:
code is in C++ or Java)
The indicator of runtime error
is - No/ Invalid Output with an
error message

No

Are the sample/


custom test No
cases passing?

Yes

Click on the 'SUBMIT' button

Is the output
matching your
expected output/ Yes Good to Go. No more Errors!
all your test cases
are passing?

No

Is the program
Iscrashing/
the program
Steps to
Yes crashing/ throwing an
throwing an
exception?
No 'Logical Error' has occurred What type of test cases are failing Fix Errors
exception?
How to Identify:

- Link
We see a difference in expected vs
actual output. Invalid/ Incorrect
Output
Note:

Please explore the possibility


PS- Unlike syntax or runtime
of runtime error as well at this
errors, logical errors do not cause point.
the program to crash or throw
exceptions, making them harder to
detect.

Perf (Performance) Test


Base/Sample Test Cases Edge Test Cases
Cases

Examples of errors associated with You might need to rethink your


Review your base logic. You might different data types/ data structures
problem solving approach
be missing out on a section of - Array: empty array, array with 1 What is the Space Complexity
possible input types.
element
of your solution
Eg. only thinking logic for odd size - Matrix: rectangular, square, column What is the Time Complexity of
of a palindrome string and not matrix, row matrix
your solution
even size strings Review logic associated with :
- Integer: positive/negative, 0, large Can you think of other data
- Constraints on input (boundary overflowing cases
structures/ patterns/
conditions , size of input etc.)
- Linked List: null head, one node list, algorithms to improve your
- data structure/s being used. odd/even list
solution's Time Complexity (eg.
- Trees: one node tree, skewed tree, in case of TLE [Time Limit
perfect binary tree
Exceeded] ) and space
- String: empty string, large string, all complexity.
unique, all vowel, special character,
alphanumeric string

- Stack: underflow, overflow


Steps to fix Compilation/ Syntax Errors

What are Syntax/ Compilation


Errors:

1. These errors occur when we


violate the rules present in a How to fix:

syntax (of the coding language) . With a clear understanding of the


2. This error indicates something error message on the screen and
needs to be fixed before location/s of the error, one can fix
compiling the code.
the compilation errors.
3. We call them compile time
errors because the compiler can
easily detect these errors.

STEPS TO FIX

COMPILATION/ SYNTAX

ERRORS

Read the error message. The error message would ideally clearly call out the error along with the line number in most of the cases.

Google the error message (if needed)

Identify the problem causing section/line in the code.

Try the fix in this section and run your code again

Go to ‘Is your code


compiling successfully?’
Decision Box - Link
Steps to fix Runtime Errors

What are Runtime Errors:

1. An error that is encountered


when a program is being executed How to fix:

after a successful compilation of With a clear understanding


the code​.​ I.e. once all the of the error message on the
compilation errors are resolved.
screen and location/s of the
2. The program encounters an error, one can fix the
unexpected situation or condition runtime errors.
that prevents it from continuing
normally.

STEPS TO FIX

RUNTIME ERRORS

Understand the Error Message: The programming language usually provides an error message or exception stack trace giving
information about the error's type and location. Read and understand the error message to identify the cause of the error. Google the
error message if needed.

Some common examples of this


error
Division by zer
Locate the Error: Identify the line of code where the runtime error occurs. The error message will usually indicate the specific line Accessing array out of its limi
Null pointer exceptio
number or method where the error has triggered from. See more examples here Memory/stack overflow/
segmentation faul
Variable casting error
Index Out Of Bound Exception -
check edge cases and data
type overflow and sizes (if code
Review the Code: Examine the code around the error location and look for potential issues. Check for divisions by zero, array index is in C++ or Java)

calculations, null references, or recursive functions that may be causing the error.

Examples of errors associated


with different data types/ data
structure
Check Input and Data Structures: Ensure that the input values and data structures being used in the code are correctly initialised Array: empty array, array with 1
and have valid values. Eg. verify that arrays have the correct size, objects are instantiated, and variables are assigned appropriate elemen
Integer: positive/negative, 0,
values. large overflowing case
Linked List: null head, one node
list, odd/even lis
Trees: one node tree, skewed
tree, perfect binary tre
String: empty string, large
Use Debugging Tools: Utilize debugging tools provided by the programming environment or IDE to string, all unique, all vowel,
Set breakpoints - step through the code, and inspect variable values. This can help you pinpoint the exact cause of the runtime special character, alphanumeric
strin
error
Add Print Statement
Print statements can be added in the sections of the code where a decision is being made. (PS- If the logical bits are
segregated into functions, it becomes easier to debug if a function is working as expected and giving the correct result
One can print expected outputs in a print statement or some indicative values to check if the code is reaching till a particular
section/line numbe
Comment out sections of the code which you think might be causing an error to identify the code section which is working
correctly incase adding Print statements are not helpful independently
Dry Run the cod
In case of absence of a compiler usage to test above 2 steps, one can consider an input test case (along with the expected
output) and manually check the code flow for actual output one is getting through a code walkthrough vs. expected output.
(Video can be created to demonstrate this in all languages)

Fix the Error: Once the cause of the error is identified, make the necessary modifications to fix the issue. It could involve adding
conditional checks, handling exceptions, validating input, or adjusting algorithmic logic.

Run your code again

Go to ‘Is your code


compiling successfully?’
Decision Box - Link
Steps to fix Logical Errors

How to fix:

A good way to debug is to

1. Add print/log statements and


What are Logical Errors:

identify the code snippet where


1. Occurs when the code runs
the bug is.

without any error messages or


Start with testing if a function is
exceptions, but it does not
correct by printing the value
produce the expected or desired
returned/calculated from it (if
output.

applicable).

2. These errors are often the


If not, go deep, add print
result of incorrect program logic
statements inside it.

or flawed algorithms
2. For the Time limit exceeded -

watch out for loops, while loops

conditions.

STEPS TO FIX

LOGICAL

ERRORS

Review the Code: Carefully examine the code and algorithm to understand the expected behavior and the logic implemented. Look for any

discrepancies between the intended logic and the actual code. Eg. Are you missing out on a possible set of scenarios

Use Debugging Techniques: Utilize debugging techniques, such as adding print statements or using a debugger, to track the flow of execution,

inspect variable values, and identify potential issues

Add Print Statement

Print statements can be added in the sections of the code where a decision is being made. (PS- If the logical bits are segregated into

functions, it becomes easier to debug if a function is working as expected and giving the correct result

One can print expected outputs in a print statement or some indicative values to check if the code is reaching till a particular section/line

numbe

Comment out sections of the code: which you think might be causing an error to identify the code section which is working correctly if adding

Print statements are not helpful independently

Dry Run the cod

In case of absence of a compiler usage to test above 2 steps, one can consider an input test case (along with the expected output) and

manually check the code flow for actual output one is getting through a code walkthrough vs. expected output. (Video can be created to

demonstrate this in all languages

Analyze more Input and Outpu

Check the input values and the corresponding output to identify any patterns or inconsistencies that may reveal logical errors. Consider

edge cases and ensure the algorithm handles all scenarios correctly. Use Custom runs to get 'actual output' from your code vs 'expected

output'

Modify the Logic: Once identified, make the necessary adjustments to the code or algorithm to fix the issue. Update the program logic to

accurately reflect the desired behavior.

Test and Rerun the code with various inputs to ensure the the logical error is resolved and the program produces the correct output.

Go to ‘Is your code

compiling successfully?’

Decision Box - Link

You might also like