Download 1649 Datastructure Assignment 2 Pass and more Assignments Computer Science in PDF only on Docsity!
Unuversity of
Greenwich
Data Structure & Algorithms
NameïŒNguyá»
n Minh ÄáșĄo
Student IDïŒ GCS
Subject ID: 1649
Class: GCS1003B
Submission date: 14/03/
Subject AdvisorïŒLĂȘ Ngá»c ThĂ nh
Assignment No: 2/
Assignment Brief 2 (RQF)
Higher National Certificate/Diploma in Business
Student Name/ID Number: Nguyen Minh Dao/ GCS Unit Number and Title: Unit 19: Data Structures and Algorithms Academic Year: 2021 Unit Assessor: Le Ngoc Thanh 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.
Learning Outcomes and Assessment Criteria (Assignment 2) Pass Merit Distinction LO3 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
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 Student ID Class Assessor name 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 Grading grid P4 P5 P6 P7 M4 M5 D3 D
Table of Content
- Assignment Brief 2 (RQF)..................................................................................................................
- Higher National Certificate/Diploma in Business...........................................................................
- I. Implement ADT & algorithms.......................................................................................................
- Description of your application..............................................................................................
- ADT (P4, P5).........................................................................................................................
- 2.1. Implement (P4)............................................................................................................
- 2.1.1. Node.java...........................................................................................................
- 2.1.2. Queue.java.......................................................................................................
- 2.1.3. Stack.java.........................................................................................................
- 2.1.4. Application.java................................................................................................
- 2.1.5. Screenshot of result.........................................................................................
- 2.2. Test case (P5)...........................................................................................................
- 2.3. Implement error-handling for the app........................................................................
- (P6)................................................................................................................................................ II. Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm
- Asymptotic analysis.............................................................................................................
- 1.1. Definition....................................................................................................................
- 1.2. Asymptotic notation...................................................................................................
- 1.2.1. Big O notation (O)............................................................................................
- 1.2.2. Omega notation (Ω)..........................................................................................
- 1.2.3. Theta notation (É”).............................................................................................
- 1.3. Common asymptotic notations..................................................................................
- 1.4. How to find time complexity?.....................................................................................
- answer with an example (P7)........................................................................................................ III. Determine two ways in which the efficiency of an algorithm can be measured, illustrating your
- Time complexity..................................................................................................................
- Space complexity................................................................................................................
- References....................................................................................................................................
- Figure 1: Projectâs Structure............................................................................................................... Table of Figures
- Figure 2: Node class...........................................................................................................................
- Figure 3: getter & setter method.......................................................................................................
- Figure 4: Queue class......................................................................................................................
- Figure 5: enqueue method...............................................................................................................
- Figure 6: dequeue method...............................................................................................................
- Figure 7: print method......................................................................................................................
- Figure 8: Stack class........................................................................................................................
- Figure 9: Stack constructor..............................................................................................................
- Figure 10: Push method...................................................................................................................
- Figure 11: print method....................................................................................................................
- Figure 12: Application class.............................................................................................................
- Figure13: do-while loop menu with switch case...............................................................................
- Figure 14: menu...............................................................................................................................
- Figure 15: enter option 1..................................................................................................................
- Figure 16: option 2 case 1................................................................................................................
- Figure 17: option 2 case 2................................................................................................................
- Figure 18: option 3 case 1................................................................................................................
- Figure 19: option 3 case 2................................................................................................................
- Figure 20: option 4 case 1................................................................................................................
- Figure 21: option 4 case 2................................................................................................................
- Figure 22: option 5............................................................................................................................
- Figure 23: type a string selection when there is no error handling code.........................................
- Figure 24: Error handling code.........................................................................................................
- Figure 25: Result after add an error handling code.........................................................................
2.1.1. Node.java.
Figure 2: Node class The class has two instance variables: âdataâ and ânextâ. âdataâ is a string variable that stores the data value of the node. ânextâ is a reference to the next node in the linked list.
Figure 3: getter & setter method For the setter and getter methods in the Node class. I wrote âgetDataâ to get the data from a particular message. Then âsetDataâ to set the data for a specific declared variables. The 'setNext' method takes a 'Node' argument and sets the value of 'next' to the provided 'Node'. The âgetNextâ method returns the reference to the next âNodeâ.
2.1.2. Queue.java.
- enqueue(String element): a method that adds a new node containing the given string âelementâ to the end of the queue. If the queue is empty, both âfrontâ and ârearâ are set to the new node. Otherwise, ârearâ is set to the new node, and the new node is added to the end of the queue. The method also increments ânodesCountâ. Figure 6: dequeue method
- dequeue(): a method that removes and returns the first node from the queue. If the queue is empty, the method returns ânullâ. Otherwise, the method removes the first node and updates âfrontâ to point to the next node. If the queue becomes empty as a result of the removal, ârearâ is also set to ânullâ. The method also decrements ânodesCountâ. Figure 7: print method
- print(): a method that prints out the contents of the queue. If the queue is empty, the method prints out "Empty". Otherwise, the method iterates over each node in the queue and prints out its string value, along with a number that represents its position in the queue.
2.1.3. Stack.java.
Figure 8: Stack class The Stack class has two private member variables: âtopâ and ânodesCountâ. âtopâ is a reference to the top node in the stack, and ânodesCountâ keeps track of the number of nodes in the stack. Figure 9: Stack constructor This stack constructor initializes âtopâ to ânullâ and ânodesCountâ to â0â, which means itâs an empty stack at beginning. Figure 10: Push method Iâm using the âpush()â method to add a new element to the stack's top. It will generate a new âNodeâ object, assign the new element to its âdataâ field, assign the current âtopâ node to its ânextâ field, and assign the new node to its âtopâ. Lastly, it increases ânodesCountâ to reflect the new node's inclusion.
Figure 12: Application class The main method begins by creating a new Scanner object to read user input, and then initializes a Queue object and a Stack object to store messages.
Figure13: do-while loop menu with switch case The program then enters a do-while loop that repeatedly displays a menu of options and prompts the user for input. There are several options for us to choose from â1â to â5â. If you enter any of them, itâll be read using the Scanner object and then processed using a switch case statement to determine which case to take based on the selected option.
Figure 16: option 2 case 1 This is the result of option 2 when the queue is empty. Thereâs no message in the queue so the receiver canât get any from it. Figure 17: option 2 case 2 This is the result of option 2 when the queue have message. The receiver get the message from the queue then put it into the stack storage. There are 2 case when you choose option 3:
Figure 18: option 3 case 1 This is the result of option 3 when the queue is empty. Thereâs no message in the queue so system prints âEmptyâ Figure 19: option 3 case 2 This is the result of option 3 when the queue have message. The system prints the message in order LILO (last in last out)