









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:
Student Name/ID Number: Liu Chi Khanh/ GCS 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.
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
Because I want to use Scanner to acquire input value, I type "java.util.Scanner." The value returned by "nextLine()" while reading a message (String) is the first character of the string. Then, I make the desired changes using "if" expressions. If User 1 didn't enter a message to send, for instance, the system would immediately crash if "if (question.isEmpty())" was used to check that. Alternatively, "if (sentence.length()> 111)" can be used to set a character restriction. If the limit is reached, the user will be prompted to enter more characters by seeing the message "Limited characters please re- enter." A block of code that might cause an exception to be thrown is run using the keyword "try," which is followed by other blocks to handle special cases and, optionally, another block to be executed under all conditions. The tools to construct structured exception handling, and "Catch"bug. The guarded code that might result in the exception is included in a try block. Explain how you handle error by exception (P5) What is exception handling? Responding to undesirable or unexpected events that occur while a computer program is running is known as exception handling. Without this process, exceptions would interfere with a program's regular functioning and cause it to crash. Exception handling deals with these events to prevent this from happening. Exceptions can happen for a variety of reasons, such as incorrect user input, erroneous code, hardware failure, a lost network connection, a lack of memory to run an application, a memory conflict with another program, a program trying to divide by zero, or a user trying to open files that aren't accessible. Specialized programming language structures, hardware interrupt mechanisms, or operating system interprocess communication features manage exceptions as they happen. In contrast to error handling, which deals with serious issues that an application might want to avoid, exception handling deals with conditions that a program might capture. On the other hand, error management supports the continuity of software program execution. How is exception handling used? When an exception occurs in a program that contains many statements midway through execution, the statements that follow the exception are not executed, and the program crashes. When an exception arises, exception handling aids in preventing this from happening. Exceptions can be caught and thrown via exception handling. An exception is dispatched to a function that can handle the exception if a detecting function in a block of code is unable to handle an abnormality. A catch statement is a collection of sentences that deals with the particular thrown exception. The kind of exception that is thrown is determined by the catch parameters. When dealing with exceptions that cannot be handled locally, exception handling is helpful. The exception handler moves control to where the error can be handled rather than displaying an error status in the program. A function has the option of handling exceptions or throwing them. Try blocks, which are blocks of code contained in curly braces or brackets and capable of raising an exception, can also be used to divide error handling code from regular code. Programmers can organize exception objects using try blocks.
Figure 2 -Exception handling works when I enter the length of characters, there will be an error message pop up to remind the user. 2.3/ Test plan(P5) Result: II/ Analysis 1/ Big O (P6) What is Big O notation and how does it work? Simply put, Big O notation indicates how many operations an algorithm will perform. The literal "Big O" before the projected number of operations gives it its moniker. Big O notation does not indicate the algorithm's speed in terms of seconds. The number of variables that affect how long an algorithm takes to run is way too large. Instead, you'll compare various algorithms using Big O notation to see how many operations each one does. Big O establishes a worst-case run time? Assume you are a teacher and your pupil is Jane. You utilize a straightforward search strategy to browse the database of your school district in an effort to locate her information. You are aware that a straightforward search will execute O(n) times. This implies that, in the worst scenario, finding Jane's will need you to look through every single record (represented by n).
Figure 4 -Big O notation Here are some common algorithms and their run times in Big O notation: Figure 5 -Example
With your current level of knowledge, Big O notation is risky. Start comparing algorithms right away. Example: O(1) Example Look at findFirstIndex, which is provided below. When accessing the 0 index, passing either a smallCollection or a giganticCollection will result in an O(1) run-time. FirstIndex's return value is also a constant-time operation. Both of these actions will take a consistent amount of time regardless of the size of n. Figure 6 -O(1) Example O(n) example Check out the printAllValues function we have provided below. The amount of n directly affects how many operations are required to loop across it. A loop is typically (but not always) a sign that the particular section of code you're looking at has an O run time (n). Figure 7 -O(n) example P7/ Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with an example. Counting the operations Counting the number of operations an algorithm requires to find the solution across various input sizes is one technique to gauge its efficiency.
Figure 9 -Example empirical measurements
References