Docsity

Advance Programming Assignment2, Assignments of Advanced Computer Programming

Toggle sidebar
bg1
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 NGUYEN TIEN LOC Student ID BHAF200116
Class PBIT17102 Assessor name NGUYEN THAI CUONG
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 D4
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download Advance Programming Assignment2 and more Assignments Advanced Computer Programming in PDF only on Docsity!

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 NGUYEN TIEN LOC Student ID BHAF Class PBIT17102 Assessor name NGUYEN THAI CUONG 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

Summative Feedback:Resubmission Feedback: Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:

I. Introduction

Data Structures are the programmatic way of storing data so that data can be used efficiently. Almost every enterprise application uses various types of data structures in one or the other way. This tutorial will give you a great understanding on Data Structures needed to understand the complexity of enterprise level applications and need of algorithms, and data structures. Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output. Algorithms are generally created independent of underlying languages, i.e. an algorithm can be implemented in more than one programming language. After present ADT from last report assignment 1. In this report assignment 2, I have reused ADT such as Queue and Stack to make a Send Message program with specific requirement, and analysis the performance the program

II. Implement a complex ADT and algorithm in an executable

programming language to solve a well-defined problem (P4).

1. What is the Message Queue?

A message queue is a software engineering component used for communication between processes or between threads within the same process. Message queues provide an asynchronous communication protocol in which the sender and receiver of messages don't need to interact at the same time - messages are held in queue until the recipient retrieves them. Message queues are used within operating systems or applications as a way for programs to communicate with one another. They may also be used to pass messages between computer systems.

2. Executable Code

This programming include:  Using ADT Queue as a buffer during data transmission and reception.  Error handling: use the Exception catcher - the "try ... catch" block to catch and handle errors if any arise during program execution.  Test program and report test results (Test case, test log). To solve this problem, I have designed Queue ADT for handing the requirements as below:  Class Message:

 Next, I will instantiate Queue class and here need to initialize constructor, variables and functions or methods for given problem like Enqueue , Delete and Showmessage and Exit.

 Output:

 The above that I use the function to add message to the Queue and now I will try to display it on the screen. I just need to enter Sender and Message to display on screen.

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:

 This is the result of the program after applying Try Catch

2. Test Case

No Test case Input data Expected output Actual output^ Result 1 Test add new message  Enter Sender: Tien Loc  Enter the text of the Message: Welcome to Ninh Binh Display message “Enqueue Successfully!” Display message “Enqueue Successfully!”

PASS

2 Test show list message Enter number 2 to the command at the main menu. Display the lists of all message Display the lists of all message

PASS

3 Test Delete a Enter number 3 to the Display message Display message PASS

Big-O Notation (O-notation):  Big-O notation represents the upper bound of the running time of an algorithm. Thus, it gives the worst-case complexity of an algorithm. Omega Notation (Ω-notation)

 Omega notation represents the lower bound of the running time of an algorithm. Thus, it provides the best case complexity of an algorithm. Theta Notation (Θ-notation):  Theta notation encloses the function from above and below. Since it represents the upper and the lower bound of the running time of an algorithm, it is used for analyzing the average-case complexity of an algorithm.

There are two main measures for the efficiency of an algorithm. The complexity of an algorithm is divided into two types:  Time complexity  Space complexity

1. Time Complexity

The total time needed to complete the execution of an algorithm is called time complexity. The time complexity depends on all factors that the space complexity depends on. Time requirements can be defined as the numerical function T(num), where T(num) can be measured as the number of steps, provided each step consumes the constant time. Example:  Time Complexity: In the above code “Welcome to Viet Nam” is printed only once on the screen. So, the time complexity is constant: O(1) i.e. every time a constant amount of time is required to execute code, no matter which operating system or which machine configurations you are using.

 Time Complexity: In the above code “Welcome to Viet nam” is printed only n times on the screen, as the value of n can change. So, the time complexity is linear: O(n) i.e. every time, a linear amount of time is required to execute code. The space complexity of an algorithm quantifies the amount of space taken by an algorithm to run as a function of the length of the input.

2. Space Complexity