1649 Datastructure Assignment 2 Pass, Assignments of Computer Science

agawuhenvaionvnenaiaeivnaaeiaj

Typology: Assignments

2020/2021

Uploaded on 06/29/2023

nicolasdaocter
nicolasdaocter 🇻🇳

22 documents

1 / 31

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Unuversity of
Greenwich
Data Structure & Algorithms
NameNguyễn Minh Đạo
Student ID GCS210351
Subject ID: 1649
Class: GCS1003B
Submission date: 14/03/2023
Subject AdvisorLê Ngọc Thành
Assignment No: 2/2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f

Partial preview of the text

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.......................................................................................................
      1. Description of your application..............................................................................................
      1. 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
      1. 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
      1. Time complexity..................................................................................................................
      1. 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)