ASM 2: DATA STRUCTURE (BTEC), Assignments of Programming Languages

You work as in-house software developer for Softnet Development Ltd, a software body-shop providing network provisioning solutions. Your company is part of a collaborative service provisioning development project and your company has won the contract to design and develop a middleware solution that will interface at the front- end to multiple computer provisioning interfaces including SOAP, HTTP, JML and CLI, and the back-end telecom provisioning network via CLI .

Typology: Assignments

2021/2022

Uploaded on 08/09/2022

KhoaLd
KhoaLd 🇻🇳

4.9

(53)

13 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Higher Nationals in Computing
Unit 19: Data Structure and Algorithms
ASSIGNMENT 2
Assessor name: LE NGOC THANH
Learner’s name: LE DONG KHOA
ID: GCS200218
Class: GCS0904A
Subject code: 1649
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download ASM 2: DATA STRUCTURE (BTEC) and more Assignments Programming Languages in PDF only on Docsity!

Higher Nationals in Computing

Unit 1 9: Data Structure and Algorithms

ASSIGNMENT 2

Assessor name: LE NGOC THANH

Learner’s name: LE DONG KHOA

ID: GCS

Class: GCS0904A

Subject code: 1649

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 Le Dong Khoa Student ID GCS Class GCS0904A 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 Grading grid P4 P5 P6 P7 M4 M5 D3 D

Assignment Brief 2 (RQF)

Higher National Certificate/Diploma in Business

Student Name/ID Number: 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. ● 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

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

Content

  • defined problem. P4 Implement a complex ADT and algorithm in an executable programming language to solve a well
      1. Requirement of program
      1. Implement code
      • 2.1 Stack.java
      • 2.2 Queue.java
      • 2.3 Main.java
  • P5 Implement error handling and report test results.
    • 1 Error handling
      1. Test case with screen shoots
      • 2.1 Test case:
      • 2.2 Screen shoots:
  • P6 Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm
      1. The execution time of algorithm
    • 2 Asymptotic analysis
      • 2.1 Big-O notation
      • 2.2 Omega-Ω notation
        1. 3 Theta-Θ Notation
    • 3 General Rules for Estimation
  • answer with an example. P7 Determine two ways in which the efficiency of an algorithm can be measured, illustrating your
    • 1 Time complexity
    • 2 Space Complexity
    • 3 Evaluate
      • 3.1 Source code that I used
      • 3.2 Time Test
  • Reference

2 2.1 Stack.java First I create a constructor Stack to initialize Object Stack with size parameter. Push function use to insert the character into the top position of stack. In this program, I’m using push with value: deQueue in queue. So the Stack can get character from Queue. Push function will stop when the Queue is empty. Pop function will return the top character in Stack and stop when the Stack is empty. After that I connect each character into string. IsEmpty is used to check stack does not store any item. isFull is used to check stack is full, if insert more, stack will be overflow In this program we use “Try – Catch” to handle the error and this “Try – Catch” exception handling has been used to the pop and push function to handle the user inputted string, avoiding the inputted string message consists of an amount of values such as this error: “Index was outside the bounds of the array”.

3 2.2 Queue.java Firstly, I create constructor Queue to initialize Object Queue with size parameter. Base on standard of Queue, I created eQqueue, deQueue, isEmpty, isFull methods. isEmpty prevent performing operations on an empty stack, the programmer is required to internally maintain the size of the stack which will be updated during push and pop operations accordingly. isEmpty conventionally returns a boolean value: True if size is 0, else False. As I use single dimension array to implement queue, we just check for the rear pointer to reach at size to determine that the queue is full. Enqueue function allow to insert the character into Queue and this function is only execute when the size is bigger than 0. It means enQueue just work when the Queue is not Full. Next, deQueue function is only execute when the size is different with 0 and after the Queue is full. Through, deQueue will stop when the Queue is empty. This deQueue function return the first character of the messageContent.

5 P5 Implement error handling and report test results.

1 Error handling

No program or segment can be considered complete until the appropriate error handling has been added. Unwanted program errors are a catastrophe - at the best, they cause disappointment because program users have to repeat for minutes or hours of work, but in life-critical applications, even the most trivial program error, if not processed correctly, has the potential to kill someone. If an error is fatal, in the sense that a program cannot reasonably continue, the program must be able to " die gracefully ". This means that it must informs its user (s) why it died and save as many program states as possible. Error handling is the process of responding to and recovering from error conditions in your program’s. When executing Java code, different errors can occur: coding errors made by the programmer, errors due to wrong input, or other unforeseeable things. When an error occurs, normally Java will stop and generate an error message. The technical term for this is: Java will throw an exception (throw an error). An Exception is an unusual event, often an error, that requires special processing. Exceptions can be caused by using a reference that is not yet initialized, dividing by zero, going beyond the length of an array, or even JVM not being able to assign objects on the heap.  Try: A try block identifies a block of code for which particular exceptions is activated. It is followed by one or more catch blocks.  Catch: A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.  Throw: A program throws an exception when a problem shows up. This is done using a throw keyword. The catch block in Java is used to handle the Exception by declaring the exception type in the parameter. The declared exception must be an exception of the parent class exception (i.e, Exception) or the generated exception type. However, the good approach is to declare the generated type of exception. The catch block must be used after the try block only. You can use multiple catch blocks with a single try block. The try and catch keywords come in pairs:

6 When implementing the system, we will encounter some errors like this: So, when implementing the system, I used try-catch to catch the error. After using “Try – Catch” we could know where is bug in our program then fixed it to make the system work well. And here is the result:

  1. Run a single message
  2. Random

8 size

  1. Testing to send a random message to the array Import the class java.util.Random.Random rand = new Random(). int r = rand.nextInt(20) and String s= “hi”
  • r The program will automatically display hi with random number [ hi7 hi9 hi0 hi hi3]
PASS

2.2 Screen shoots:

  1. Test case 1:
  2. Test case 2:

9

  1. Test case 3:
  2. Test case 4:
  3. Test case 5: Here is my source code link: https://github.com/DKHOA111/ADT-ASM/tree/master/asm

11

1. The execution time of algorithm

The running time of an algorithm for a specific input depends on the number of operations executed. Therefore, each operation takes a certain amount of time. The greater the number of operations, the longer the running time of an algorithm. For example: The running time of a statement assigning the first value of an integer array to a variable is simply the time it takes to copy the value of the first array value. We can assume this assignment takes a constant amount of time regardless of the value. Let us call c1 the amount of time it takes to copy an integer. No matter how large an array on a typical computer is (given the reasonable terms of memory and array size), the time it takes to copy a value from the first position of the array is always c1. Hence, the equation for this algorithm is simply T (n) = c1; indicating that the size of the input n has no effect on run time. This is called a constant running time. Now, consider the following code: The basic operation in this example is the cumulative operation for the sum of the variables. We can assume that increment takes a constant time; call this time c2. (We can ignore the time required to initialize sum, and to increment the loop counters i and j. In practice, these costs can safely be bundled into time c2). The total number of increment operations is n2. We say that the runtime is T (n) = c2n2. The growth rate for an algorithm is the rate at which the cost of the algorithm grows as the size of its input grows. Here is a list of commonly used growth rates: Now, consider the following figure:

12 The figure above shows a graph for six equations, each of which describes the running time for a particular program or algorithm. A variety of representative growth rates for the typical algorithms shown. The two equations labeled 10n and 20n are graphed by straight lines. The growth rate cn (with any positive constant c) is often referred to as the linear growth rate or run time. This means that as the value of n is growing, the running time of the algorithm also increases proportionally. Doubling the value of n will double the running time. An algorithm whose running-time equation has a highest-order term containing a factor of n2 is said to have a quadratic growth rate. In the Figure above, the line labeled 2n represents quadratic growth rate. The line labeled 2n represents exponential growth rate. This name comes from the fact that n appears in the exponent. Line labeled n! is also increasing exponentially. As can be seen from Figure above, the difference between an algorithm whose running time has cost T (n) = 10n and another with cost T (n) = 2n2 becomes large as n increases. For n> 5, the algorithm with running time T (n) = 2n2 was much slower. This is despite the fact that 10n has a constant coefficient greater than 2n2. Comparing the two curves marked 20n and 2n2 shows that changing the constant coefficient for one of the equations only shifts the point where the two curves cross.