Docsity

Data structure & Algorithm, Assignments for Information Technology ASM2, Assignments of Data Structures and Algorithms

Partial preview of the text

Download Data structure & Algorithm, Assignments for Information Technology ASM2 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

Tran Nguyen Tan Sang

GREENWICH | GCS

Data Structure &

Algorithm

ASSIGNMENT 2

ASSIGNMENT 2 FRONT SHEET 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 Tran Nguyen Tan Sang Student ID GCS Class GCS0804_NX 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 TAN SANG Grading grid P4 P5 P6 P7 M4 M5 D3 D

ASSIGNMENT 2 BRIEF Qualification BTEC Level 5 HND Diploma in Business Unit number Unit 19 : Data Structures and Algorithms Assignment title Implement and assess specific DSA Academic Year 2021 Unit Tutor Issue date Submission date IV name and date Submission Format: Format: The submission is in the form of an individual written report. 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 Tutors. The form of submission will be a soft copy in PDF posted on corresponding course of http://cms.greenwich.edu.vn/ Project also needs to be submitted in zip format. Note: The Assignment must be your own work, and not copied by or from another student or from books etc. 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 know how to reference properly, and that understand the guidelines on plagiarism. If you do not, you definitely get fail Assignment Brief and Guidance: 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. Learning Outcomes and Assessment Criteria Pass Merit Distinction LO1 Implement complex data structures and algorithms D3 Critically evaluate the complexity of an implemented ADT/algorithm P4 Implement a complex ADT and algorithm in an executable programming language to solve a well defined problem. P5 Implement error handling and report test results. M4 Demonstrate how the implementation of an ADT/algorithm solves a well- defined problem LO4 Assess the effectiveness of data structures and algorithms D4 Evaluate three benefits of using implementation independent data structures P6 Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm P7 Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with an example. M5 Interpret what a trade-off is when specifying an ADT using an example to support your answer

  • LO3. Implement complex data structures and algorithms
    • problem. (Youtube: https://www.youtube.com/watch?v=eJRXOTMlKU4) P4. Implement a complex ADT and algorithm in an executable programming language to solve a well-defined
        1. Object Sender is used to store information of a sender:
        1. Object Receiver to store information of a receiver:
        1. Array implementation of Stack to store packets when Receiver receive packets from Queue.
        1. Array implementation of Queue to store packets when sender send packets to receiver.
        1. Object MyUtils to split a string with specified length for each packet to an array
      • because a Sender can send to many Receivers and a Receiver can receive from many Senders: 6) Object SenderReceiver is used to make a Many to many relationship between Sender and Receiver
        1. Main Class is used to execute this project:
    • P5. Implement error handling and report test results.
      • not found. 1) In main method, I read three messages from three files and I use try catch to catch exception when file
        1. Check messages that senders send to receiver must not be empty:
        1. Queue overflow:
        1. Stack overflow:
        1. Read message from file .txt:
        1. Stop sending when Sender send full of message:
        1. Stop receiving when receiver full of message
    • M4. Demonstrate how the implementation of an ADT/algorithm solves a well-defined problem
        1. SenderReceiver ADT:
        1. Sender ADT:
        1. Receiver ADT:
        1. Stack ADT:
        1. Queue ADT :....................................................................................................................................................
        1. MyUtils ADT:
    • D3. Critically evaluate the complexity of an implemented ADT/algorithm
  • LO4. Assess the effectiveness of data structures and algorithms
    • P6. Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm
        1. Asymptotic Analysis – Analysis of Algorithms:
        1. The execution Time of Algorithms
        1. General rules for estimation
    • with an example. P7. Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer
        1. Measurement of algorithm efficiency:
        1. Common Growth Rates:
    • M5. Interpret what a trade-off is when specifying an ADT using an example to support your answer
        1. Definition of trade-off:
        1. A trade-off is when I use Linked List:
    • D4. Evaluate three benefits of using implementation independent data structures
  • References:

LO3. Implement complex data structures and algorithms

P4. Implement a complex ADT and algorithm in an executable programming language to solve a well-

defined problem. (Youtube: https://www.youtube.com/watch?v=eJRXOTMlKU4)

1) Object Sender is used to store information of a sender: − Properties:

  • name (string)
  • isEnd (boolean) − Methods:
  • Constructor Sender(String name) to initialize Object Sender with ‘name’ parameter.
  • Set and get name
  • setIsEnd and isEnd − Implementation in Java: 2) Object Receiver to store information of a receiver: − Properties:
  • name (string) − Methods:
  • Constructor Receiver(String name) to initialize Object Receiver with name parameter.
  • getName − Implementation in Java:
  • isFull check if Queue is full, return true − Implementation in Java: 5) Object MyUtils to split a string with specified length for each packet to an array − Properties: No property − Methods:
  • Split with ‘message’, ‘numberOfChar’, ‘ch’ parameter − Implementation in Java: 6) Object SenderReceiver is used to make a Many to many relationship between Sender and Receiver because a Sender can send to many Receivers and a Receiver can receive from many Senders: − Properties:
  • sender (Sender)
  • receiver (Receiver)
  • queue (Queue)
  • stack (Stack)
  • messages (string array)
  • currIndexOfMessages (int)
  • currIndexOfPackets (int)
  • packets (string array)
  • isEnd (boolean) − Methods:
  • Constructor SenderReceiver to initialize SenderReceiver with sender, receiver, message parameters. This method has a task that it must split a length message to many short message with 250 characters and store them in an array:
  • send method is used to send each packet with 25 character to receiver by adding them in a queue
  • receive method is used for Receiver to receive packets from queue and add stack. When one message with 250 characters end, printing a short message in cosole.

Output of my program: P5. Implement error handling and report test results. 1) In main method, I read three messages from three files and I use try catch to catch exception when file not found.

− Therefore, I will add try catch into code when we do enqueue method: − This is the result when use try catch: 4) Stack overflow: − The program initializes the stack with a specified size: − So, if we insert packets exceed the size, the program will occur error like this: − To solve this problem I will check if stack is full, do not push new item − This is the result: 5) Read message from file .txt:

− Result: Successfully 6) Stop sending when Sender send full of message: − Result: Successfully 7) Stop receiving when receiver full of message

Step 3. Check if the index of array that store short messages equals to - 1. Program will increase currIndexOfMessages variable. Then split string of messages[currIndexOfMessages] and give it to array packets. Step 4. Check if current index of packets is larger than length of packets minus 1, we increase current index of array messages and give 0 value to current index of packets. Besides that, program will check if current index of array messages is larger than length of array messages, program will give true value to isEnd variable of Object Sender and then stop send method. But if currIndexOfMessages still smaller han length of array messages, we split string of messages[currIndexOfMessages] and give it to array packets. Step 5. Enqueue packets[currIndexOfPackets] into Queue. Step 6. Write on console the string that sender send to receiver. − Receive method of Object SenderReceiver: − Step 1. Check if the queue is empty and sender finish sending, stop the method Step 2. If not, check if queue is not empty, dequeue and give value to s variable. Step 3. If ‘s’ variable has value equal to “|” character (end of array packets), write all value stored in stack ion console Step 4. Else write ‘received packet on cosole’ 2) Sender ADT: − Sender is an ADT that I created to store information of a sender when start sending a message.

− Because properties name and isEnd of Object is private, I created public method to set and get them. − isEnd property is used to identify that sender have done. If isEnd is true, when random a value that this sender have to send, send method will not run all statement. − 3) Receiver ADT: − − This object is to store information of a receiver, because of private property, I create some public set and get method. 4) Stack ADT: