Docsity

Assignment 2 Data Structure and Algorithms, Essays (university) of Software Development

Partial preview of the text

Download Assignment 2 Data Structure and Algorithms and more Essays (university) Software Development in PDF only on Docsity!

Data Structures and Algorithms

ASSIGNMENT 2

No.

Learner’s name : Nguyen Tri Tai Assessor name : Le Ngoc Thanh Class : GCS0903A Learner’s ID : GCS Subject’s ID : 1649 Assignment submitted : 26/06/

ASSIGNMENT 2 FRONT SHEET

Grading grid P 4 P 5 P 6 P 7 M 4 M 5 D3 D 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 Nguyen Tri Tai Student ID GCS Class GCS0903A Assessor name Le Ngoc Thanh 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

Assignment Brief 2 (RQF) Higher National Certificate/Diploma in Business Student Name/ID Number: Unit Number and Title: Unit 19: Data Structures and Algorithms Academic Year: 2021 Unit Assessor: Assignment Title: Implement and assess specific DSA Issue Date: Submission Date: Internal Verifier Name: Date: Submission Format: Format: ● The submission is in the form of an individual written report and a presentation. This should be written in a concise, formal business style using single spacing and font size 12. You are required to make use of headings, paragraphs and subsections as appropriate, and all work must be supported with research and referenced using the Harvard referencing system. Please also provide a bibliography using the Harvard referencing system. Submission ● Students are compulsory to submit the assignment in due date and in a way requested by the Tutor. ● The form of submission will be a soft copy posted on http://cms.greenwich.edu.vn/. ● Remember to convert the word file into PDF file before the submission on CMS. Note: ● The individual Assignment must be your own work, and not copied by or from another student.

● If you use ideas, quotes or data (such as diagrams) from books, journals or other sources, you must reference your sources, using the Harvard style. ● Make sure that you understand and follow the guidelines to avoid plagiarism. Failure to comply this requirement will result in a failed assignment. Unit Learning Outcomes: LO3 Implement complex data structures and algorithms LO4 Assess the effectiveness of data structures and algorithms Assignment Brief and Guidance: Assignment scenario Continued from Assignment 1. Tasks For the middleware that is currently developing, one part of the provision interface is how message can be transferred and processed through layers. For transport, normally a buffer of queue messages is implemented and for processing, the systems requires a stack of messages. The team now has to develop these kind of collections for the system. They should design ADT / algorithms for these 2 structures and implement a demo version with message is a string of maximum 250 characters. The demo should demonstrate some important operations of these structures. Even it’s a demo, errors should be handled carefully by exceptions and some tests should be executed to prove the correctness of algorithms / operations. The team needs to write a report of the implementation of the 2 data structures and how to measure the efficiency of related algorithms. The report should also evaluate the use of ADT in design and development, including the complexity, the trade-off and the benefits.

Contents

    1. Requirement of program
    1. Implement program in java
    1. Error handling and report test results
    • Error handling
    • Test results
    • Test case:........................................................................................................................
    1. How the implementation of an ADT/algorithm solves a well-defined problem
    • Flow Chart below:
    • Using Queue ADT
    • Using Stack ADT
    1. Evaluation the complexity of an implemented ADT/Algorithm

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

1. Requirement of program Message transfer program: The system should be created with ADTs and algorithms for these two structures, and a demo version with a message of no more than 250 characters should be implemented. The demonstration should show some of these structures' most significant operations. Even though it is a demo, failures should be handled properly using exceptions, and certain tests should be run to demonstrate the validity of algorithms / actions. This programming include: Using a buffer (ADT STACK / Queue) during data transmission and reception Handling errors: Use the Exception catcher - the "try... catch" block - to capture and manage errors that occur during program execution. Program testing and reporting test results (Test case, test log) 2. Implement program in java To solve this problem, I have designed Stack and Queue ADT for handing the requirements as below: First, I have designed a “Message” object to store the messages in the system.

  • Class Node : used to declare variables

Class MyStack: Then, I will design the stack ADT for the system

Class main Finally, I will create a "Main" class for the system with the following functions

3. Error handling and report test results Error handling No program or segment may be regarded finished until the necessary error handling has been implemented. Unwanted program failures are a disaster - at most, they create disappointment since program users must redo their work for minutes or hours, but in life-critical programs, even the most minor program fault, if not managed appropriately, has the ability to kill someone. If a mistake is fatal in the sense that the program cannot reasonably continue, it must be able to "die gracefully." This implies that it must be

  • tells its user(s) why it died and
  • Remember to save as many program states as possible. The process of responding to and recovering from erroneous circumstances in your software is known as error handling. When running Java code, several mistakes might occur, including coding errors produced by the programmer, faults caused by incorrect input, and other unexpected factors. When an error occurs, Java will generally stop and display an error message. This is referred to as throwing an exception in Java (throw an error). An Exception is a rare event, generally a mistake, that necessitates specific handling. Using an uninitialized reference, dividing by zero, exceeding the length of an array, or the JVM not being able to allocate objects on the heap can all result in an exception. The try-catch block is used to implement the catch and throw exception handling pattern. The try statement lets you to design a block of code that will be checked for errors while it runs. If an error occurs in the try block, the catch statement allows you to define a block of code that will be executed. In Java, the catch block is used to manage Exceptions by defining the exception type in the argument. The stated exception must be either an exception of the parent class (i.e., Exception) or a produced exception type. However, it is preferable to indicate the created kind of exception. The catch block should only be used after the try block. With a single try block, you may utilize numerous catch blocks. The terms try and catch appear in pairs:

We will face several faults and exceptions when building the system, such as NullPointerException (thrown when the program tries to refer to an object but it has no location in memory, i.e. has a null value), IndexOutOfBoundsException, and so on: For example: As a result, when I implemented the system, I utilized try-catch to catch errors. Example:

Check the feature of receiving messages Check the feature of displaying all messages

Test case: A test case describes an input, action, or event, as well as the intended response. The purpose of the test case is to determine whether or not each feature of the software program is functioning properly

4. How the implementation of an ADT/algorithm solves a well-defined problem To get data to Destination Message, the system uses Queue as a buffer and Stack. A Transfer Function will do this. I'll demonstrate how the system works with the algorithm to help you visualize it. Test case ID Description Expected result Actual results Result 1 Enter a message here. The message is a maximum of 250 characters long. If it has more than 250 characters, an error warning is displayed. Enter your message here. If it is more than 250 characters, an error notice will show prompting you to input the message again String has a length restriction of 250 characters. Please try again. Fail 2 Check to see if a new function has been sent a message Enter a message here. This message has been added to the system. The message has been added to the system. Pass 3 Examine the message receiving feature The message will be received by the system. The message was received by the system. Pass 4 Examine the option to see all messages. Show all messages in the system. The system has shown all messages. Pass

Using Queue ADT In this system, I utilized three Queue functions to create a Buffer, including: Enum(), Enqueue() and Dequeue():

  • Enum() function: Check the number of elements in the Queue (Buffer). As a result, we may specify a maximum character in Buffer.
  • Enqueue() function: This method inserts the character into the Queue (Buffer) and is only executed when the value from Enum() is greater than 0. Enqueue() only works when the Queue (Buffer) is not full.
  • Dequeue() function: This method returns the Queue's first character (Buffer). This method is only called when the value returned by Enum() differs from 0 and the Queue (Buffer) is full. When the Queue (Buffer) is empty, Dequeue() will terminate. Using Stack ADT In this system, I utilized two Stack functions to create a Destination Message: Push() and Pop() :
  • Push() function: Place the character at the top of the stack. In this application, I'm using Push() in Queue with the value: Dequeue() (Buffer). As a result, the Stack can obtain a character from the Queue (Buffer). When the Queue (Buffer) is empty, the Push() method will terminate.
  • Pop() function: This method returns the top character in the Stack and terminates when the Stack is empty. After that, I use the following equation to join each character into a string (Destination Message): Pop() + Destination = Destination

5. Evaluation the complexity of an implemented ADT/Algorithm To build an efficient Queue implementation in which Queue and Stack operations have the same time complexity O (1). However, the difficulty of the method in the Transfer function is O(n^2), thus when we execute this program, the complexity is likewise O(n^2). As a result, we can see that algorithm time increases in lockstep with algorithm complexity.: