



















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!




















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 P 4 P 5 P 6 P 7 M 4 M 5 D3 D
Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:
● 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.
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
I. Implement ADT & algorithms 1.1 Description of [your application] We are all aware that computers are unable to understand the letters or numbers that individuals type or perform. Instead, it is limited to 0s and 1s. For instance, a variety of apps or compilers help when we input a word or number into a computer to convert it to binary form (0s and 1s bit). in order for a computer to easily comprehend them. Based on that problem, I developed a function to solve it, converting Decimal Numbers to Binary Numbers using Stack ADT. I selected the Stack algorithm because it works well with the push and pop functionality of the Stack. 1.2 ADT (P4, P5) 1.2.1 Implement (P4) We first need to implement Stack ADT before we can utilize stack to address these problems: First, I develop an abstract Stack interface class to implement Stack functionality. Figure 1 Create an abstract Stack interface class
Thirdly, I create a class called Stack to carry out Stack algorithms. Figure 3 Create stack class (1)
Figure 4 Create stack class (2) Figure 5 Create stack class (3) Operations:
Figure 9 A function that returns true if size is 0 To start, we must first determine whether the stack is empty. Declares a variable called "value" and assigns it the value Top of stack in order to get the value we erased. We then declare a Node with the previous value Top called "temp". Set "temp" as the top of the stack and the previous value of Top to Null. Reduce the size by 1 and then return the removed value (the previously specified variable "value"). The Peek() method just returns the item at the top of the stack without deleting or changing it in any way. Figure 10 Implement peek() Traverse() - output each node's value Figure 11 Implement traverses()
Converting Decimal Numbers to Binary Numbers using Stack as a solution The convert() function implements this function, which converts decimal values to binary numbers, using the following lines of code: Figure 12 Convert function We first pile up all the binary digits in a stack and then convert a decimal number to binary. We first convert the entire number to binary before pulling out each digit one at a time and displaying it. The decimal number is consequently converted to its accurate binary representation. The decimals must first be converted to binary before being pushed to the Stack that we previously declared in order for this function to be executed on main. Next, we declare a number carrying a value that we want to convert to binary as an integer data type. I will test the accuracy of the algorithm using the integers 1080 and 2048. Figure 13 Main When I ran main with a 1080 starting point, I received the following outcome. Figure 14 Result
Figure 16 illustration (2) I then attempt 2048. Figure 17 Main Figure 18 Result
Error handling is the process used in software programs to respond to and recover from incorrect situations. In other terms, it is the process of foreseeing, spotting, and fixing software, coding, or communication problems. Error management helps ensure that software runs correctly. When evaluating error-handling options, many programs really run into serious design problems (techopedia, 2022) As an illustration, the ensureNonEmpty() function checks to see if a stack is empty. Figure 19 Try-catch block The terms "try" and "catch" denote the handling of exceptions brought on by data or code errors while a program is running. Exceptions happen in a try block, which is a portion of code. A catch block is used to catch and deal with exceptions from try blocks (techopedia, 2011) Computer languages including C (C++ and C#), Java, JavaScript, and Structured Query Language all make use of the try/catch expression (SQL) (techopedia, 2011) Advantages of Exception Handling Java provides a strong exception management architecture that enables you to recognize and address mistakes as they happen in your applications. The use of exception handling features provides a number of advantages. Let's examine these advantages in more detail (onlinetutorialspoint, 2015) Provision to Complete Program Execution: Permitting program execution to continue after an exception has been caught and dealt with is one of the main objectives of Java's exception management. A Java program's execution continues when an exception occurs. Program execution continues after the exception is handled until the end of the program. By using carefully planned try, catch, and finally blocks, you may create programs that fix errors and continue running as if nothing went wrong. If more than one exception is possible, you can handle each one separately by using different catch blocks (onlinetutorialspoint, 2015) Easy Identification of Program Code and Error-Handling Code: Try/catch blocks are used to segregate error-handling code from program code, which makes it easier to understand the logical flow of a program. The course of action to be done when an exception arises is not specified by the logic in the program code. The catch blocks may contain this information. Java, in contrast to many other traditional programming languages, enables you to produce well-organized code by sprinkling error reporting and error handling code throughout your application. Programs are easier to understand and maintain over time when error management and program logic are separated in this way (onlinetutorialspoint, 2015) Propagation of Errors: Error reports are propagated up the call stack via the manner that Java's exception handling framework is built. This is because whenever an exception arises, Java's runtime environment looks backwards through the call stack for methods that can catch the exception. Exception propagation up the call stack ensures that the right procedures catch exceptions when a program makes a lot of calls between methods (onlinetutorialspoint, 2015)
I use try-catch to fix the issue when the user enters inaccurate data: User enters incorrect information invalid system will display error message:
2. Analysis 2.1 Big O (P6) According to (tutorialspoint, 2022), An algorithm's asymptotic analysis involves determining the mathematical bounds or frames of its run-time performance. We may easily draw conclusions about an algorithm's best case, average case, and worst case scenarios using asymptotic analysis. An algorithm's time requirements often fall into one of three categories: Best Case − Minimum time required for program execution. Average Case − Average time required for program execution. Worst Case − Maximum time required for program execution. Following are the commonly used asymptotic notations to calculate the running time complexity of an algorithm. Ο Notation Ω Notation θ Notation
The notation O(n) is the formal way to express the upper bound of an algorithm's running time. It measures the worst case time complexity or the longest amount of time an algorithm can possibly take to complete (tutorialspoint, 2022) For example, for a function f(n): Ο(f(n)) = { g(n) : there exists c > 0 and n0 such that f(n) ≤ c.g(n) for all n > n0. } The notation Ω(n) is the formal way to express the lower bound of an algorithm's running time. It measures the best case time complexity or the best amount of time an algorithm can possibly take to complete (tutorialspoint, 2022) For example, for a function f(n) Ω(f(n)) ≥ { g(n) : there exists c > 0 and n0 such that g(n) ≤ c.f(n) for all n > n0. }