1. Trang chủ
  2. » Luận Văn - Báo Cáo

higher nationals in computing data structure algorithms assignment

19 0 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

The team needs to write a report of the implementation of the 2 data structures and how to measure the efficiency of related algorithms.. implementation of an ADT/algorithm solves a well

Trang 1

Higher Nationals in Computing

Data Structure & Algorithms ASSIGNMENT

No.2

Trang 2

Page | 2

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and

title Unit 19: Data Structures and Algorithms

Submission date 26/06/2022 Date Received 1st

Re-submission Date 30/06/2022 Date Received 2nd

Student Name Vo Bi Thanh Phuoc Student ID GCS200547

Class GSC0903B Assessor name Le Ngoc Thanh

Trang 3

1

Summative Feedback: Resubmission Feedback:

Internal Verifier’s Comments:

IV Signature:

Trang 4

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

Note:

● 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

Trang 5

3

● 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:

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 require a stack of messages

The team now has to develop these kinds 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

Trang 6

Learning Outcomes and Assessment Criteria (Assignment 2)

D3 Critically evaluate the complexity of an implemented ADT/algorithm

and algorithm in an executable programming language to solve a well-defined problem

and report test results

implementation of an ADT/algorithm solves a well-defined problem

D4 Evaluate three benefits of using implementation independent data structures

analysis can be used to assess the effectiveness of an algorithm

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

Trang 7

1 Implement ADT & algorithms 7

1.1 Description the application 7

Trang 8

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

Trang 9

7

1 Implement ADT & algorithms

1.1 Description the application

The system must be designed with ADT / algorithms for these two settings and run a trial version with a message of up to 250 characters The demo should show some important features of these structures Although this is a trial version, errors must be handled with exceptions, and some tests must be performed to demonstrate the accuracy of the algorithms / functions

privateintrear;

privateintfront;

publicQueue(){ queue = newString[ ]25;

publicStringdequeue(){ if (total > 0){ total ;

Stringtemp queue rear = [ ++];

(ifrear == queue.length){ rear = 0;

front = -1;

} returntemp;

} return"";

}

public booleanisEmpty(){ returntotal == 0;

Trang 10

}

public booleanisFull(){ returntotal == queue.length;

} }

out the data • Stack.java

publicclassStack{ privateString[] stack;

privateintindex;

privateinttotal = 0

publicStack(){ stack = newString[ ]25;

index = - 1;

}

public voidpush(Strings){ if (index < 24){ total++;

stack[++index] = s;

} }

publicStringpop(){ if (index >= 0){ total ;

returnstack index[ ];

} return"";

➢ This is the Stack, the data structure and its function have a mission that checks out the data and stops it when it reaches the limit

Trang 11

Stringtemp = "'I Love You To The Moon & Back!!!'";

Randomrand = newRandom();

temp += rand.nextInt(100);

q.Enqueue(temp)

System.out.println("[User 1]: " + temp) }

while (!q.isEmpty()){ Stringtemp = q.Dequeue();

myStack.push(temp) }

System.out.println();

//Print to screen from Stack

while (!myStack.isEmpty()){ //User 2 receive the message

System.out.println("[User 2]: " + myStack.pop());

} } }

➢ This is the App file which is take responsible to run the algorithm and give us back the result 1.3 Test & Result (P5)

➢ Here are some test cases I have during running this app:

Show result Input data The result is clean Have some errors with the font Fail

Show result Input data The result is clean Not show all the result Fail

Trang 12

Screen shoots of the application successfully running

 In this main function, I simulate a chat box of user 1 and user 2  Whenever user 1 sends a message, the message enqueue to the queue

 Then user 2 saw that the program will dequeue all of the messages in the stack to see the message

2 Analysis

2.1 Big O (P6)

 Big O Notation is a way to measure an algorithm’s efficiency It measures the time it takes to run your function as the input grows Or in other words, how well does the function scale

 In mathematical analysis, asymptotic analysis, also known as asymptotic, is a method of describing limiting behaviour (wikipedia, n.d.)

 Asymptotic Analysis is the big idea that handles above issues in analysing algorithms In

 Asymptotic Analysis, we evaluate the performance of an algorithm in terms of input size (we don’t measure the actual running time) We calculate, how does the time (or space) take by an algorithm increases with the input size

 For example: When consider the search problem searching a given item in a sorted array

One way to search is Linear Search (order of growth is linear) and other way is Binary Search (order of growth is logarithmic) To understand how Asymptotic Analysis solves the above-mentioned problems in analysing algorithms, let us say we run the Linear Search on a fast computer and Binary Search on a slow computer For small values of input array size n,

Trang 13

11

Search will definitely start taking less time compared to the Linear Search even though the Binary Search is being run on a slow machine The reason is the order of growth of Binary Search with respect to input size logarithmic while the order of growth of Linear Search is linear Thus, the machine dependent constants can always be ignored after certain values of input size (geeksforgeeks, n.d.)

 Usually, the time required by an algorithm falls under three types:

• Best Case: Minimum time required for program execution • Average Case: Average time required for program execution • Worst Case: Maximum time required for program execution

 The commonly used asymptotic notations to calculate the running time complexity of an algorithm:

• Ο Notation (Big Oh Notation, Ο): The notation Ο(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

• Ω Notation (Omega Notation, Ω): 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

• θ Notation (Theta Notation, θ): The notation θ(n) is the formal way to express both the

lower bound and the upper bound of an algorithm's running time (tutorialspoint, n.d.)

How different between each asymptotic notation

Trang 14

➢ In this program, we will use asymptotic analysis to assess the effectiveness of algorithm of the Transfer function:

while (n < source.Length && n < messageLimit) //O(n^2) {

while (myQueue.Count <= maxBuffer) {

if (n == messageLimit) { break;

}

myQueue.Enqueue(source[n]); n++; }

implement Asymptotic Analysis is not perfect, but that’s the best way available for analysing algorithms

2.2 Analyze performances (P7)

 Two method that can measured the effectiveness of an algorithm:

Time complexity

estimate of running time as a function of the size of input data The result is normally

processed

▪ Big O notation is a mathematical notation that describes the limiting behavior of a function

when the argument tends towards a particular value or infinity It is a member of a family of notations invented by Paul Bachmann, Edmund Landau, and others, collectively called Bachmann–Landau notation or asymptotic notation In computer science, big O notation is used to classify algorithms according to how their running time or space requirements grow as the input size grows In analytic number theory, big O notation is often used to express a bound on the difference between an arithmetical function and a better understood approximation; a famous example of such a difference is the remainder term in the prime number theorem (wikipedia, n.d.)

▪ Time complexity: In computer science, the time complexity is the computational

complexity that describes the amount of time it takes to run an algorithm Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm, supposing that each elementary operation takes a fixed amount of time to perform Thus, the amount of time taken, and the number of elementary operations performed by the algorithm are taken to differ by at most a constant factor

estimation that got embedded in many programming languages) to time the use of an algorithm Run-based profiling can be very sensitive to hardware configuration and the

Trang 15

13

possibility of other programs or tasks running at the same time in a multi-processing and multi-programming environment

var watch = System.Diagnostics.Stopwatch.StartNew(); watch.Start();

myTransfer.SendMessage(source); watch.Stop();

Result of using System Diagnostics

characters. So, the algorithm of this program could be considered as an effective algorithm

▪ Space complexity

▪ Space complexity: is a function describing the amount of memory (space) an algorithm

takes in terms of the amount of input to the algorithm We often speak of "extra" memory needed, not counting the memory needed to store the input itself Again, we use natural (but fixed length) units to measure this We can use bytes, but it's easier to use, say, number of integers used, number of fixed-sized structures, etc In the end, the function we come up with will be independent of the actual number of bytes needed to represent the unit Space complexity is sometimes ignored because the space used is minimal and/or obvious, but sometimes it becomes as important an issue as time

Trang 16

▪ In this program, When implement in C#, I have used GC.GetTotalMemory to calculate the

long available = GC.GetTotalMemory(false);

Console.WriteLine($"Memory usage (Buffer = {myTransfer.maxBuffer}): {available} bytes");

Memory usage with GC.GetTotalMemory

Trang 17

15

characters and this Function used 324712 bytes memory

Space complexity:

algorithm We often speak of "extra" memory needed, not counting the memory needed to store the input itself Again, we use natural (but fixed-length) units to measure this We can use bytes, but it's easier to use, say, number of integers used, number of fixed-sized structures, etc In the end, the function we come up with will be independent of the actual number of bytes needed to represent the unit Space complexity is sometimes ignored because the space used is minimal and/or obvious, but sometimes it becomes as important an issue as time

memory usage when Transfer Function executed: long available = GC.GetTotalMemory(false);

Console.WriteLine($"Memory usage (Buffer = {myTransfer.maxBuffer} {available}): bytes");

Memory usage with GC.GetTotalMemory

Trang 18

Memory using for each object in program

characters and this Function used 324712 bytes memory

CONCLUSION

Data Structures are structures programmed to store ordered data, so that various operations can be performed on it easily It represents the knowledge of data to be organized in memory It should be designed and implemented in such a way that it reduces the complexity and increases the efficiency

The implementation of a data structure usually requires writing a set of procedures that create and manipulate instances of that structure The efficiency of a data structure cannot be analyzed separately from those operations This observation motivates the theoretical concept of an abstract data type, a data structure that is defined indirectly by the operations that may be performed on it, and the mathematical properties of those operations (including their space and time cost)

After this subject, I have a lot of knowledge to know what ADT is and using ADT to implement a real program to solve a real problem in life In some case, I also have different prioritize about time or space to implement the system work well When measuring the program, I can make sure that system will work with right requirement

Trang 19

https://www.geeksforgeeks.org/analysis-of-algorithms-set-1-asymptotic-analysis/

at: http://www.purplechaiblogger.com/data-structure-importance-and-advantages/.

[online] Available at:

https://www.tutorialspoint.com/data_structures_algorithms/asymptotic_analysis.htm.[6] Wikipedia (2020) Asymptotic analysis [online] Available at:

https://en.wikipedia.org/wiki/Asymptotic_analysis.

Ngày đăng: 14/05/2024, 15:39

w