Sei sulla pagina 1di 10

‘’

Individual Assignment
Module Code: CT111-3-2-COMT
Module Name: Computing Theory

Intake Code: UC2F1902SE


Lecturer Name: DR BOOMA POOLAN MARIKANNAN

Submission Date: 13 May 2019


Student Name: Alvin Jeffrey A/L Anthony
TP Number: TP028642
Part A: Automata

1) Design a Non-deterministic Finite Automata (NFA)

This is a for loop using the programming language Java.

public class MyAssignment {

public static void main(String[] args) {

for (int i=0; i<5; i++) {

System.out.println(i) ;

}
The diagram below is a Non-deterministic Finite Automata (NFA) based on the Java sample
code above.
2) Provide the corresponding quintuple and state transition table for the NFA

Below is the quintuple for the NFA

M = {Q, Σ, S, F, δ}

Q - Set of states = {q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15,

q16, q17, q18, q19, q20, q21, q22, q23, q24, q25, q26, q27}

Σ - Alphabet of input symbols = {f, o, r, (, i, n, t, =, 0, ;, <, 5, +, ), {, } }

S - Initial state = {q0}

F - Set of final state = {q27}

δ - Set of transitions = {see transition table}


Below is the transition table for the NFA

Transition Table
∞ . f o r ( i n t = 0 ; < 5 + ) { }
q0 q1
q1 q1 q2
q2 q3
q3 q4
q4 q5
q5 q6
q6 q7
q7 q8
q8 q9
q9 q10
q10 q11
q11 q12
q12 q13
q13 q14
q14 q15
q15 q16
q16 q17
q17 q18
q18 q19
q19 q20
q20 q21
q21 q22
q22 q23
q23 q24
q24 q25
q25 q26
q26 q27
q27
Part B: Complexity and Decidability

1) Specify a short snippet of a program code that employs the construct from Part A,
indicating the complexity for each line of the code snippet

The complexity for the first line from the snippet above is O(6)

The complexity for the second line from the snippet above is O(1)

2) Using the snippet, demonstrate the complexities for the Best Case and Worst Case
scenarios

Best Case

This line from the snippet is the best case because it only executes the code once.

Worst Case

This line from the snippet is the worst case because it executes the code repeatedly until it
satisfies the condition in the line.

3) Modify the code snippet so that its complexity would significantly increased
The condition in the code snippet above is increased to 10. Hence, the complexity would
significantly increase to O(11).
4) Discuss the Computability of the snippet

Computability is the time taken for the overall program to be executed successfully. To
be specific, computability is the sum of all the complexities that are present in the
snippet. So, based on this explanation, the computability for the snippet above would be
O(12). This is because the complexity for the first line is O(11) and the complexity for
the second line is O(1).

Whereas the computability for this snippet above is O(7). This is because the complexity
for the first line is O(6) and the complexity for the second line is O(1).
5) Explain how the Decidability of the code snippet can be determined

Computability = 7

Output

Computability = 12

Output

Decidability is defined as the determining factor of which particular snippet will take the
least time to execute. This can be done by comparing the computability of both the
snippets as shown above. So, based on that, the first snippet will be executed the fastest if
compared to the second snippet.
REFERENCES

a) GeeksforGeeks. (2019). Analysis of Algorithms | Set 4 (Analysis of Loops) -


GeeksforGeeks. [online] Available at: https://www.geeksforgeeks.org/analysis-of-
algorithms-set-4-analysis-of-loops/ [Accessed 4 May 2019].

b) YouTube. (2019). Minimization of DFA - Examples (Part 1). [online] Available at:
https://www.youtube.com/watch?v=0XaGAkY09Wc [Accessed 1 May 2019].

c) W3schools.com. (2019). Java For Loop. [online] Available at:


https://www.w3schools.com/java/java_for_loop.asp [Accessed 3 May 2019].

Potrebbero piacerti anche