Professional Documents
Culture Documents
COMT Group09 2 PDF
COMT Group09 2 PDF
CT111-2-3-COMT
COMPUTING THEORY
UC2F2008CS-CS(DA)-CS(DF)-SE
WEIGHTAGE: 20%
This study source was downloaded by 100000841823167 from CourseHero.com on 08-30-2022 04:12:58 GMT -05:00
https://www.coursehero.com/file/73479137/COMT-Group09-2docx/
TABLE OF CONTENTS
References 6
1
This study source was downloaded by 100000841823167 from CourseHero.com on 08-30-2022 04:12:58 GMT -05:00
https://www.coursehero.com/file/73479137/COMT-Group09-2docx/
1.0 Code Snippet and Time Complexity
1.1 Time Complexity
The time complexity of an algorithm, which expressed as T(n), represents the
asymptotic behavior of the run time and it is most generally estimated by calculating the
number of elementary operations required to complete the execution. (Studytonight, 2020)
Commonly, the time complexity is expressed using the Big O notation. In this assignment, we
will also use Big O notation to demonstrate the time complexity of for loop.
2
This study source was downloaded by 100000841823167 from CourseHero.com on 08-30-2022 04:12:58 GMT -05:00
https://www.coursehero.com/file/73479137/COMT-Group09-2docx/
1.3 Code Snippet of For Loop
Figure 1.3.1 Code Snippet of Nested For Loop by using the C Programming Language
int i = 0 1
i<N 1
int x = 0 0
x<N 0
printf(“%d”,x); 0
x++ 0
printf(“%d”,i); 0
i++ 0
Table 1.4.1 Number of execution in the code snippet when N is a negative number
According to (Cormen, T., et. al., 2009), the running time of an algorithm on a
particular input is the number of “steps” executed. From Table 1.4.1, we can see that the total
3
This study source was downloaded by 100000841823167 from CourseHero.com on 08-30-2022 04:12:58 GMT -05:00
https://www.coursehero.com/file/73479137/COMT-Group09-2docx/
number of execution is 2 when N is 0 or a negative number. The number of execution will
still remain 2 as long as N is 0 or a negative number. As the number of execution is a
constant, the running time when N is 0 or a negative number is also a constant, we can say
that the time complexity is O(1).
In short, the best-case time complexity is O(1).
4
This study source was downloaded by 100000841823167 from CourseHero.com on 08-30-2022 04:12:58 GMT -05:00
https://www.coursehero.com/file/73479137/COMT-Group09-2docx/
1.5 Worst Case
The worst-case scenario is where N is a positive number. In this case, the outer loop
runs N times. Meanwhile, each time the outer loop runs, the inner loop runs N times.
int i = 0 1
i<N N+1
int x = 0 N
x<N N*(N+1) = N2 + N
printf(“%d”,x); N*N = N2
x++ N*N = N2
printf(“%d”,i); N
i++ N
Table 1.5.1 Number of execution in the code snippet when N is a positive number
From Table 1.5.1, we can see that the total number of execution is (3N 2 + 5N + 2). To
figure out the time complexity, we have to find the fastest growing term and take out the
coefficient. In this case, the fastest growing term is 3N 2. After taking out the coefficient, the
time complexity is O(N2).
In short, the worst-case time complexity is O(N2).
5
This study source was downloaded by 100000841823167 from CourseHero.com on 08-30-2022 04:12:58 GMT -05:00
https://www.coursehero.com/file/73479137/COMT-Group09-2docx/
2.0 Computability
2.1 Computability
If a problem can be worked out in principle using a computing device, the problem is
said to be computable which can also be said as “decidable” or “solvable” (Immerman, 2004)
and the code snippet of the nested loop shown above is computable as it can be determined
by a finite procedure from state to state, and the algorithms are simple as well. If the problem
is computable, it is decidable if the problem has an algorithm that decides it and meets the
criteria of any of these 3 characteristics: complete, mechanistic and deterministic otherwise,
the problem is undecidable.
If a clean code can be executed without any interruptions, the code is complete and
the code snippet above is complete as upon execution, the code will be checked sequentially
to ensure that the conditions are true and based on that, an output is displayed without faults.
The code is not deterministic as output during best-case, we will get same output if we
have same input.
6
This study source was downloaded by 100000841823167 from CourseHero.com on 08-30-2022 04:12:58 GMT -05:00
https://www.coursehero.com/file/73479137/COMT-Group09-2docx/
After experimenting for multiple case, we found that the code shown in Figure2.1.1 is
deterministic. We will prove this by giving several examples. To prove the code snippet is
deterministic, we need to prove the same input always bring the same output. To test this, we
added an infinite loop to execute the code snippet in Figure 2.1.1 for multiple times. Also, we
made the console to print "End of code snippet" every time the code snippet done execution
so that we know when the code snippet done execution.
In the first case, we considered the N as -1000. As mentioned in previous part, when
N is a negative number, the test expression i<N will return false and the code snippet in
Figure 2.1.1 will be ended. Hence, the console shows “End of code snippet". When we input
N as -1000 again, the console still show "End of code snippet". This means that when we
input N as -1000, the output is always the same.
In the second case, we considered N as 0 for three times. The console shows the same
output when N is 0.
In the third case, we considered N as 2. As we can see from Figure2.1.1, when we
input N as 2, the console shows "000111End of code snippet". When we input N as 2 again,
the console still shows the same output "000111End of code snippet".
From these three cases above, we can see that the same input always lead to the same output.
Hence, we can say that the code is deterministic.
Furthermore, another characteristic of computation is mechanistic. It means that the
code need to reach the requirement of finite sequences and each can be run without
ambiguity. (Chowdhary, 2015)The steps and answer of the code should be precise when we
proceed it. The error and unclear condition should not appear to meet the requirement of
mechanistic. To related to our case, we have to make sure the input of code snippet should be
clear and correct and we will get a clear and right answer without any error.
An effective procedure can be called if it met three properties above, complete, mechanistic
and deterministic.
7
This study source was downloaded by 100000841823167 from CourseHero.com on 08-30-2022 04:12:58 GMT -05:00
https://www.coursehero.com/file/73479137/COMT-Group09-2docx/
References
Chowdhary, K., 2015. Lecture 19: Decidability, and Church-Turing Thesis. [ebook] pp.19-1.
Available at: http://www.krchowdhary.com/toc/19-decide-lect.pdf [Accessed 12 November
2010].
Cormen, T., et. al., 2009. Introduction To Algorithms. 3rd ed. Cambridge, Mass.: MIT Press,
p.25.
Educative, 2019. Big O Notation: A primer for beginning devs. [Online] Available at:
https://www.educative.io/blog/a-big-o-primer-for-beginning-devs [Accessed on 1 November
2020]
Immerman, N., (2004), “Computability and Complexity”, [online]. Available from:
https://plato.stanford.edu/entries/computability/ [Accessed: 10 Nov 2020]
Studytonight, 2020. Time Complexity of Algorithms. [Online] Available at:
https://www.studytonight.com/data-structures/time-complexity-of-algorithms [Accessed on 1
November 2020]
8
This study source was downloaded by 100000841823167 from CourseHero.com on 08-30-2022 04:12:58 GMT -05:00
https://www.coursehero.com/file/73479137/COMT-Group09-2docx/
Powered by TCPDF (www.tcpdf.org)