Data Structure and Algorithm ASM2 Pass, Assignments of Data Structures and Algorithms

Data Structure and Algorithm ASM2 Pass

Typology: Assignments

2022/2023

Uploaded on 08/08/2023

dung-tan-2
dung-tan-2 🇭🇰

1 document

1 / 24

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Higher Nationals in Computing
Unit 19: Data Structures and Algorithms
ASSIGNMENT 2
Assessor name: PHAN MINH TAM
Learner’s name: Truong Tan Dung
ID: GCS210820
Class: GCS1004b
Subject code: 1649
Assignment due: Assignment submitted:
29/6/2023
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Data Structure and Algorithm ASM2 Pass and more Assignments Data Structures and Algorithms in PDF only on Docsity!

Higher Nationals in Computing

Unit 19: Data Structures and Algorithms

ASSIGNMENT 2

Assessor name: PHAN MINH TAM

Learner’s name: Truong Tan Dung

ID: GCS

Class: GCS1004b

Subject code: 1649

Assignment due: Assignment submitted:

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 19 : Data Structures and Algorithms

Submission date 29/6/20 23 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Truong Tan Dung Student ID GCS

Class GCS1004b Assessor name Phan Minh Tam

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 Dung

Grading grid

P4 P5 P6 P7 M4 M5 D3 D

ASSIGNMENT 2 BRIEF

Qualification BTEC Level 5 HND Diploma in Business

Unit number Unit 1 9 : Data Structures and Algorithms

Assignment title Implement and assess specific DSA

Academic Year 2022

Unit Tutor TamPM

Issue date 12 - Sep- 2022 Submission date

IV name and 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 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.

Table of Contents

  • Unit 19: Data Structures and Algorithms ASSIGNMENT Contents
  • problem. P4 Implement a complex ADT and algorithm in an executable programming language to solve a well defined
      1. Queue solution
      • 1.1. Node class
      • 1.2. Queue class
      • 1.3. Application class
      • 1.4. Screenshots
      1. Stack solution....................................................................................................................................................
  • P5. Implement error handling and report test results.
  • P6. 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.3. Common asymptotic Notations................................................................................................................
      • 1.4. How to find time complexity?
      1. Example:
  • an example. P7. Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with
      1. Two Main Measures for the Efficiency of an Algorithm................................................................................
      • 1.1. Time complexity
      • 1.2. Space complexity.
  • REFERENCES
  • Figure 1: Message class............................................................................................................................................. Table of Figure
  • Figure 2: Queue class (1)...........................................................................................................................................
  • Figure 3: Queue class (2)...........................................................................................................................................
  • Figure 4: Application class (1)
  • Figure 5: Application class (2)
  • Figure 6: Application class (3)
  • Figure 7: Interface Application
  • Figure 8: Option 1 (1)
  • Figure 9: Option 1 (2)
  • Figure 10: Option 1 (3)
  • Figure 11: Option
  • Figure 12: Option
  • Figure 13: Option
  • Figure 14: Stack class (1)
  • Figure 15: Stack class (2)
  • Figure 16: Common asymptotic Notations
  • Figure 17: Time Complexity

P a g e | 2

1. 2. Queue class

Figure 2 : Queue class (1)

P a g e | 3 Figure 3 : Queue class (2)

Then design the Queue, which is almost similar to the Stack but with certain changes such as adding

information to the Queue, or removing the message and displaying the Queue status.

1. 3. Application class

Finally, I develop a “Main” class for the system that does the following tasks.

P a g e | 5 Figure 5 : Application class ( 2 ) Figure 6 : Application class ( 3 )

Error handling is the process of responding to and recovering from incorrect circumstances in your

P a g e | 6

software. Java code execution may experience a range of failures, including input errors, unforeseen

conditions, and programmer-created programming defects.

Normally, when a slip happens, Java will stop and display an error message. In Java, this is known as

throwing an exception (throw an error). A rare occurrence, typically a math mistake, that needs special

processing is called an exception. Using a reference that hasn't been initialised, dividing by zero, using

an array that is longer than it should be, or the JVM's inability to allocate objects from the heap are

all examples of situations where an error could occur.

The try-catch block use the catch-and-throw method to deal with exceptions. Using the try statement,

you may designate a portion of code that will be error-checked as it runs. The catch statement allows

you to designate a section of code that will be executed if a try block error occurs.

The catch block in Java is used to handle the exception type when it is specified inside the argument.

The declared exception must belong to the parent class exception (i.e., Exception) or the newly formed

exception type. Nevertheless, it's a great idea to declare an exception in its produced form.

1. 4. Screenshots

  • The application interface: Figure 7 : Interface Application
  • Option 1: Figure 8 : Option 1 (1)

P a g e | 8 Figure 12 : Option 3

  • Option 4: Figure 13 : Option 4

P a g e | 9

2. Stack solution

Figure 14 : Stack class (1) Figure 15 : Stack class ( 2 )

I use stack to store integers. The Stacks class provides many other methods, such as find, contains and

P a g e | 11

their effectiveness, scalability, and applicability for various issue sizes is made possible

by the asymptotic analysis. It facilitates the process of selecting and optimising

algorithms in an educated manner.

➢ Worst Case: Space complexity is a metric that expresses an algorithm's memory or

storage requirements in relation to the size of the input. It calculates an algorithm's worst-

case rate of memory need growth.

1.2. Asymptotic notation

1.2.1. Big O notation (O)

Big O notation (O) in Java is a means to express how time-consuming an algorithm is. It

depicts the maximum or worst-case scenario of how quickly an algorithm's execution time

will grow as the size of the inputs increases.

These notations offer a clear approach to convey an algorithm's effectiveness and scalability.

We may choose the best algorithm and optimise our code for improved performance by

investigating and comprehending an algorithm's time complexity.

1.2.2. Omega notation (Ω)

The lowest bound or best-case scenario of the growth rate of an algorithm's running time as

the input size increases is expressed in Java using the omega notation (Ω).

The execution time of an algorithm can be lower-bound using omega notation. It indicates

an algorithm's best-case behaviour, which means that it will always take at least this little

while to run.

Because it frequently describes the best-case situation, which may not be as valuable for

algorithm analysis as the worst-case scenario, Omega notation is not as widely used as Big

O notation.

1.2.3. Theta notation (Θ)

In Java, the upper and lower bounds of an algorithm's running time are expressed using the

Theta notation (). By demonstrating that an algorithm's running time increases at the same

pace in both the best-case and worst-case scenarios, it sets a close bound on the growth rate

of an algorithm.

Theta notation defines a function f(n) as Θ(g(n)) if there exist positive constants c1, c2, and

n0 such that for all values of n greater than or equal to n0, c1 * g(n) <= f(n) <= c2 * g(n).

In plainer language, the Theta notation suggests that the algorithm's execution time is

constrained by some multiple of the same function from both above and below. It stands for

the tightest cap on the algorithm's rate of growth.

The exact growth rate of an algorithm, accounting for both the best-case and worst-case

scenarios, is expressed using theta notation. Comparatively to other notations like Big O and

Omega, it offers a more thorough study of an algorithm's effectiveness.

P a g e | 12

1.3. Common asymptotic Notations

Figure 16 : Common asymptotic Notations

Explanation:

  • Constant - O(1): Constant complexity in time. The input size has no impact on the algorithm's

execution time. Use the index to access an element in an array as an example.

  • Logarithmic - O(log n): Exponential time complexity. The input size affects the algorithm's

execution time in a logarithmic way. Binary search is an example.

  • Linear - O(n): Linear complexity of time. The input size has a linear effect on how long the

algorithm takes to run. An array's traversal is an example.

  • Linearithmic - O(n*log n): Temporal complexity that is logarithmic. The algorithm's

execution time increases proportionally to the input size multiplied by the input size's

logarithm. An illustration would be sorting formulas like merge sort and quicksort.

  • Quadratic - O(n^2): Complexity in quadratic time. The input size affects the algorithm's

execution time in a quadratic way. A nested loop iterating over an array is an example.

  • Cubic - O(n^3): When an algorithm in Java is described as having a time complexity of

O(n3), it signifies that its execution time increases proportionally to the cube of the input size

(n). The algorithm's running time is indicated by the term "O(n3)," which denotes that it is