Docsity

Assignment 2 Data Structure and Algorithm - DISTINCTION, Assignments of Data Structures and Algorithms

Toggle sidebar
bg1
ASSIGNMENT 2 DATA STRUCTURE AND ALGORITHM
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 19: Data Structures and Algorithms
Submission date
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Phan Minh Tiến
Student ID
GCD201914
Class
GCD1001
Assessor name
Hồ Văn 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
Tiến
Grading grid
P5
P6
P7
M4
M5
D3
D4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31

Partial preview of the text

Download Assignment 2 Data Structure and Algorithm - DISTINCTION and more Assignments Data Structures and Algorithms in PDF only on Docsity!

ASSIGNMENT 2 DATA STRUCTURE AND ALGORITHM

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 19: Data Structures and Algorithms

Submission date Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Phan Minh Tiến Student ID GCD

Class GCD1001^ Assessor name Hồ^ Văn 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 Tiến

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:

  • LO3. Implement complex data structures and algorithms
    • problem (P4) I. Implement a complex ADT and algorithm in an executable programming language to solve a well-defined
        1. Description of my application
        1. Flowchart and explanations
      • 3 Implement Scenario (ADT)
    • II. Implement error handing and report test results (P5)
        1. Handle Errors By Exception
        1. Test Program
    • III. Demonstrate how the implementation of an ADT/algorithm solves a well-defined problem (M4)
        1. TransferMessage ADT:
        1. processMessages() ADT
        1. printMessages() ADT
        1. Stack ADT.....................................................................................................................................................
        1. Queue ADT
    • IV. Critically evaluate the complexity of an implemented ADT/algorithm (D3)
      • 1 Stack ADT:
        1. Queue ADT
        1. TransferMessage () method
        1. processMessage() method
        1. printMessage() method
  • LO4. Assess the effectiveness of data structures and algorithms
    • V. Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm (P6)
        1. Asymptotic Analysis – Analysis of Algorithms:
        1. The execution Time of Algorithms
        1. General rules for estimation
    • an example. (P7) VI. Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with
        1. Measurement of algorithm efficiency
        1. Common Growth Rates
        1. Analyze performances for my scenario
    • VII. Interpret what a trade-off is when specifying an ADT using an example to support your answer (M5)
        1. Definition of trade-off
      • 2 A trade-off is when I use Linked List
    • VIII. Evaluate three benefits of using implementation independent data structures (D4)
  • References
  • Figure 1: Flowchart of Main function, Read File message.txt function, and Transfer Message Function Table of Figures
  • Figure 2: Flowchart for processStack() function and printMessages() function
  • Figure 3: message.txt
  • Figure 4: Interface AbstractQueue
  • Figure 5: Interface AbstractStack
  • Figure 6: Class Stack and Constructor
  • Figure 7: Peek() and ensureNonEmpty() funtions
  • Figure 8: Enqueue() function in class Queue
  • Figure 9: Dequeuer() function in class Queue..........................................................................................................
  • Figure 10: toString() function in class Queue
  • Figure 11: Class Stack and Constructor
  • Figure 12: isEmpty(), peek(), size(), toString() function
  • Figure 13: Push function in class Stack....................................................................................................................
  • Figure 14: Pop function in class Stack
  • Figure 15: Main method
  • Figure 16: IndexOutOfBoundsException
  • Figure 17: NullArgumentException
  • Figure 18: FileNotFoundException
  • Figure 19: IOException
  • Figure 20: Actual Result 1........................................................................................................................................
  • Figure 21: Actual Result 2........................................................................................................................................
  • Figure 22: Actual Result 3........................................................................................................................................
  • Figure 23: Actual Result 4........................................................................................................................................
  • Figure 24: Actual Result 5........................................................................................................................................
  • Figure 25: transferMessages() function
  • Figure 26: processMessage() function
  • Figure 27: printMessages() function
  • Figure 28: Stack ADT
  • Figure 29: Queue ADT
  • Figure 30: Time execute short message
  • Figure 31: Time execute Long message
  • Figure 32: Time execute Messages with period
  • Figure 33: The chart of Time complexity
  • Figure 34: The chart of Space complexity
  • Figure 35: Test 1 with 50 elements
  • Figure 36: Test 2 with 30 element
  • Figure 37: Test 3 with 10 element

2. Flowchart and explanations

Figure 1: Flowchart of Main function, Read File message.txt function, and Transfer Message Function

Figure 2: Flowchart for processStack() function and printMessages() function Explanation of the system  Firstly, declare Queue and Stack based on the rebuilt Queue and Stack.  Secondly, create the file “message.txt” to enter your text.  Thirdly, Declare the variable startTime to start count the time of processing data.  Fourthly, The function that the system encounters is TransferMessage(). This function will do the job of making sure that the message inputted is totally fine. First up, the function will Read file “message.txt”. Then the function will call for a loop to split all the sentences in message to elements so it will be easier to handle. At this time there will be some situation to happen bellow:  The length of the message goes over 250 characters: a new exception will be thrown which is called Index_Out_Of_Bounds_Exception. The system will ask the user to type the message again.  There is nothing in the message: a new exception will be thrown and it is called IO_Exception. The system will also ask the user to type the message again.  The message that doesn’t meet any above mistakes: that message will be enqueued to the queue and the system will notify that the message has been successfully sent.  The last exception where we can’t cover: Illegal-State-Exception.

Figure 4: Interface AbstractQueue

Figure 5: Interface AbstractStack

 Next up, I personally built class Queue to implements interface AbstractQueue.. Below are declaration of some needed variables and the constructor.

Figure 6: Class Stack and Constructor

 These two functions in Queue class also take different tasks. For the peek function, it will return the element. Next up, we have ensureNonEmpty function, this one actually check on the non-emptiness of the queue.

Figure 7: Peek() and ensureNonEmpty() funtions

 enqueuer() function will allow the program to insert new message into the Queue and it runs onO(1).

 Next that, I continue create class Stack to implement interface Abstract Class:

Figure 11: Class Stack and Constructor

 These four functions take on different tasks. isEmpty() funtion would take the job of checking the emptiness of the stack. The peek function will make sure that the element adding in won’t overflow the stack. The size() method to set up the length for paragraph. Lastly, the toString will return the message in the stack into string so the system can easily handle.

Figure 12: isEmpty(), peek(), size(), toString() function

 For the Push function, this is the class that will insert the new message on top of the stack and also this functionality runs on O(1).

Figure 13: Push function in class Stack

 For the Pop function, this is the class where the program will remove the top or the most recent message out of the stack and it also runs on O(1).

Figure 14: Pop function in class Stack

 Main method: to run program

Figure 15: Main method

 Result:

II. Implement error handing and report test results (P5)

1. Handle Errors By Exception No program or segment may be regarded finished until the necessary error handing has been implemented. Unwanted program failures are a disaster – at most, they bring disappointment since program users must redo minutes or hours of effort, but in life-critical programs, even the most minor program fault has the potential to skill someone if not treated appropriately.  If a mistake is fatal in the sense that a program cannot reasonably continue, it must be able to “die gracefully”.

Figure 17: NullArgumentException

FileNotFoundException: The exception is thrown when trying to access a file that does not exist in the system

Figure 18: FileNotFoundException

IOException: The IOException is simply an exception that is thrown when an Input/Output error occurs. It is also the base class of such exceptions that occur while reading or accessing files, directories and streams.

Figure 19: IOException

2. Test Program Test Case (No)

Test Description Action test Expected Result Actual Result Status

1 Read file “message.txt” Create file “message.txt” with less than 250 characters. Next, use FileReader() function to declare the file I want read, then use BufferedReader() function to implement read that file.

After done sending message, we can read the message printed right after.

Figure 20 : Actual Result 1

Passed

2 Read file “message.txt” with over 250 characters

Create file “message.txt” with over 250 characters. Next, implement the same test case 1 and run program.

The system will display an notification “The message characters must be less than 250 character!!! Please retype” and exit program.

Figure 21 : Actual Result 2

Passed

3 Read file “message.txt” doesn’t contain anything

Create file “message.txt” with doesn’t contain anything. Then run program

The system will display an notification “You haven’t typed anything yet! Please retype must not be null”

Figure 22 : Actual Result 3

Passed

4 Read file “message.txt” separate with period

Create file “message.txt” separated with period. Then run program

The system will display message with the different line by period

Figure 23 : Actual Result 4

Passed

5 Try read file “message.txt” from the unknow path.

Declare a path of file “message.txt” don’t have system. Then run program

The system will display an notification “Find Not Find”

Figure 24 : Actual Result 5

Passed