Implement a complex ADT and algorithm in an executable programming language to solve a wel, Thesis of Data Mining

Implement a complex ADT and algorithm in an executable programming language to solve a well defined problem.

Typology: Thesis

2019/2020

Uploaded on 11/06/2021

hai-nguyen-14
hai-nguyen-14 🇻🇳

4.4

(7)

5 documents

1 / 23

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 2 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 14: Data Structures and Algorithms
Submission date
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Le Thanh Phuong
Student ID
GCD191157
Class
GCD0803
Assessor name
Mr. Phi
Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.
Student’s signature
Phuong
Grading grid
P4
P5
P6
P7
M4
M5
D3
D4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download Implement a complex ADT and algorithm in an executable programming language to solve a wel and more Thesis Data Mining in PDF only on Docsity!

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 14 : Data Structures and Algorithms

Submission date Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Le Thanh Phuong Student ID GCD

Class GCD0803 Assessor name Mr. Phi

Student declaration

I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that

making a false declaration is a form of malpractice.

Student’s signature Phuong

Grading grid

P 4 P 5 P 6 P 7 M 4 M 5 D3 D

Summative Feedback:Resubmission Feedback:

Grade: Assessor Signature: Date:

Internal Verifier’s Comments:

IV Signature:

Table of Contents

  • Acknowledgement
  • Introduction
  • problem......................................................................................................................................................................... P4. Implement a complex ADT and algorithm in an executable programming language to solve a welldefined
      1. Algorithm simulation (Books, n.d.)
      1. Natural language for algorithms
      1. Flowchart of program
      1. Codes and breakdown
      • a. Head
      • b. isEmpty()
      • c. getNumOfEl()
      • d. isFull()
      • e. enqueue()....................................................................................................................................................
      • f. dequeue()....................................................................................................................................................
      • g. Main
      • h. Output of program
  • P5. Implement error handling and report test results.
      1. Error handling
      1. Result of Test
    • a. Case of Test
      • b. Test log
  • P6. Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm (Thi, n.d.)
  • example....................................................................................................................................................................... P7. Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with an
    • a. Definition
    • b. Implement into example.................................................................................................................................
  • References
  • Figure 1 Introduction
  • Figure 2 Algorithm simulation
  • Figure 3 Flowchart of program
  • Figure 4 Head
  • Figure 5 isEmpty()
  • Figure 6 getNumOfEl()
  • Figure 7 isFull()
  • Figure 8 enqueue()......................................................................................................................................................
  • Figure 9 dequeue()......................................................................................................................................................
  • Figure 10 head of main().............................................................................................................................................
  • Figure 11 if statement for the length of string =
  • Figure 12 If statement for the length of string <=250
  • Figure 13 else statement for the length of string is over
  • Figure 14 Output when the user input the right number of characters.....................................................................
  • Figure 15 Output when the user don't input anything
  • Figure 16 Output when the user input over 250 characters
  • Figure 17 trystatement
  • Figure 18 catchstatement
  • Figure 19 Graph of problem
  • Figure 20 startstatement
  • Figure 21 Finish and print statement..........................................................................................................................
  • Figure 22Output when the queue's size is 30.............................................................................................................
  • Figure 2322Output when the queue's size is 70.........................................................................................................

P4. Implement a complex ADT and algorithm in an executable programming language to solve a welldefined problem.

  1. Algorithm simulation (Books, n.d.) Our team has to design an algorithm according to the scenario, create a program to relay messages from source to destination with a sequence of 250 characters. This makes S1 the input and S2 the output, so you need to run the program according to the First In – First Out algorithm so you have to use the Queue algorithm to process and move it. S1 captures the string entered by the user and transfers it to the queue, which is re-read by another queue, passes it to S2, and shows S2. The following will be a photo illustrating how a contact program works: Figure 2 Algorithm simulation
  2. Natural language for algorithms The program input is provided S1, f = r = 0 , Creating Queue Q keep it up char characters. Step:
  • 1 - Each letter from S1 is read by the program: Q[r]=x
  • 2 - If-else statements to decide whether or not the queue is complete, use step 4 if the queue is complete, and step 3 if the queue is not full.
  • 3 - Transfer x into Queue , x= S1.charAt(i), Q.enqueue(x), i++ then go back to step 1
  • 4 - Although Queue is not empty, read x in Queue (x = Q.dequeue()) then transfer to S2 (S2=S2+x).
  • 5 - If i < length of string (i<S1.length()) then doing step 4 again if not do step 1.
  1. Flowchart of program The image below shows the flow chart of the program that transforms a string from S1 to S2 with 250 characters and prints S2 output on the computer. The S1 and queue inputs are defined according to the structure and data flow, as shown below and the startup program, like the algorithms mentioned above. Figure 3 Flowchart of program

c. getNumOfEl()

Figure 6 getNumOfEl() (MAX – f + r)% MAX return string number by using the function getNumOfEl().

d. isFull()

Figure 7 isFull() isFull() is the feature to verify whether or not the queue is complete with the return getNumOfEl() == (MAX - 1), the data type of this function must be boolean.

e. enqueue()

Figure 8 enqueue() enqueue() can read the first letter of the queue with Q[r]=x then r = (r+1)%MAX to change the location of index in queue for latter and also this function must be in the if statement check the Queue is not full.

f. dequeue()

Figure 9 dequeue() dequeue() can show the character x function in Q and change the location of f in queue for latter.

g. Main

Create Queue Q = new Queue() so in class Queue, we can call other function, add a variable size so We can quickly adjust queue sizes and count buffer assistance. Figure 10 head of main() S1 and S2 string can collect surrounded characters, count is for counting the buffer or how many of queues the program needs to use and i = 0 is for calculate. Using Scanner sc = new Scanner(System.in) and S1=sc.nextLine() to collect the string entered by the customer. Figure 11 if statement for the length of string = 0

h. Output of program

Figure 14 Output when the user input the right number of characters Figure 15 Output when the user don't input anything Figure 16 Output when the user input over 250 characters

P5. Implement error handling and report test results.

  1. Error handling We ourselves use the code and do not wish the program to crash, even if the code is erroneous, there are only certain occasions in which the coding software indicates only faults but does not indicate which fault. To overcome this situation, we should use the exception catcher " try ... catch " statement to catch and handle errors if there is a problem during program execution. Figure 17 trystatement Figure 18 catchstatement We must print out the error by system.out.println(“ ” + e.toString()) to collect the error and bring it into e.
  2. Result of Test a. Case of Test Test What is being tested How Test data used Expected result 1 Length A string entry includes 0 character. Null On the computer display: " The inputted string is empty." 2 Length Inputs more than 250 characters in a string. Input over 250 characters View on the screen:" The characters’ inputted by you is over 25 0 ”. 3 Length Inputs a string of 1 to 250 characters. Input 1 50 characters Show the string length, the S output, and the number of buffers used. 4 Length Input special characters only Input characters: !@#$%^&* Show the string length, S output and the number of buffers used. 5 Error Warning Modify the queue size to - 1 size = - 1 Screen display: "Error Warning" and error cause.

5 Error Warni ng Modify the queue size to - 1 size =

  • 1 Screen display: "Error Warning" and error cause.

Erro r reco rde d

P6. Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm (Thi, n.d.) The runtime efficiency of an algorithm can be estimated by asymptotic algorithm analysis within a basic word. We draw the correct conclusions with asymptotic regression on the best, worst and worst case scenario of an algorithm (Data Structures - Asymptotic Analysis, n.d.)

  • The best case: The minimum period of time required to conduct the plan.
  • The average case: The average time needed for the execution of the software.
  • The worst case: The maximum time taken for the software to be enforced. Asymptotic analysis means asymptotic feedback, i.e. if the algorithm has no input, the algorithm operates for a certain amount of time and is a constant. Other variables are assumed to be constant in addition to the input function. The following Asymptotic Notations are commonly used in estimating the run-time complexity of an algorithm:
  • Ο Notation
  • Ω Notation
  • θ Notation But we only discuss O Notation in this article, so what is O Notation? O n) is a means of displaying an algorithm's higher asymptote runtime. It predicts the most complicated time case or is the longest time an algorithm takes (running from start to finish). Therefore, because the usual calculation of running potential algorithms and calculating the run-times of thosealgorithms is not always possible, we need to use this asymptote. We can use a realistic evaluation for evaluating the time of each algorithm in the most conditional setting, however, there is also another method of estimating that requires using the theory evaluation asymptotically. In order to begin evaluating and estimating the algorithm, we must first determine how many transactions are done in a solution and then indicate their success with the growth function. In fact, basic algorithms such as reading or writing are known as a time unit. For example:
  • Case 1: c1: count = count + 1 c2: sum = sum + count Total cost of time: c1 + c
  • Case 2: simple if-else statement If (n<0) Cost : c 1 , Time: 1

Total cost of time: c1 + c2 + (n+1)c3 + nc4 + n(n+1)c5+nnc6+nnc7+nc* The time required for this algorithm is n^ The proportional time necessity of O Notation is however, called growth rate. For eg, a calculation's runtime will be evaluated as f(n) and for another g (n2). This results in a linear growth in the runtime of the initial operation with a rise in n and an exponential increase in the run time for the second operation with n. Similarly, if n is relatively small it is roughly the same operating time for the two operations. For more specifically, we can give a graph present a problem, for example the problem here having:

  • Algorithm A requires 5*n^2 time units to solve a problem of size n
  • Algorithm B requires 7*n time units to solve a problem of size n. Figure 19 Graph of problem We can see that the two algorithms have different time units. But where there is a too large amount of n, the informative constants would look too small to be comparable and so on.

P7. Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with an example a. Definition For the efficiency of an algorithm, it is common that people use two time and space calculation variables if the fast algorithm demands more space and, vice versa, if space is decreased, it takes longer.

  • Time is a function which defines how long an algorithm takes as far as the amount of input to the algorithm is concerned, or otherwise the time taken to process an algorithm from the output input.
  • Space is a function that defines how much memory an algorithm requires (space) as the input to the algorithm. It shows how many rams, megabytes... It is also divided into 3 cases of interval ranking, along with the asymptote: best, average, and worst cases.
    • Best case: O(1) It is a constant time requirement, regardless of the scale of the problem and just take 1 second.
    • Average case: O(n + 1) Linear algorithm time specifications are improved by 1 (Mostly case used)
    • Worst case: O(n) Directly increases with the size time requirement for a linear algorithm. The average case is the most commonly used example for deciding if the algorithm can be solved. We could use extra space (RAM) for operations because of the conflict between time and space if we use time. The efficiency of the algorithm is very poor and inefficient if you are not investing in space. Therefore, people also do not waste too much money and still have a steady output using average cases to match time and space. b. Implement into example Applying a few critical considerations to the P4 programme, in order to find the optimal means of calculating the success of the algorithm:
  • Add the variables start, finish and duration in double data type.
  • Add the command line start = system.currentTimeMillis ();
  • Add the command line finish = system.currentTimeMillis ();
  • Print the variable duration screen to see the results. Figure 20 startstatement