Tải bản đầy đủ (.pdf) (13 trang)

higher nationals in computing unit 19 data structure and algorithms

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.41 MB, 13 trang )

<span class="text_page_counter">Trang 1</span><div class="page_container" data-page="1">

<b>Higher Nationals in Computing </b>

<b>Unit 19: Data Structure and Algorithms No.2 </b>

<b>Assessor Name: Le Ngoc Thanh </b>

Class: GCS0903B ID: GCS200345

Assignment due: June 26 , 2022

<small>th</small>

Assignment submitted: June 26 , 2022

<small>th</small>

</div><span class="text_page_counter">Trang 2</span><div class="page_container" data-page="2">

2

<b> ASSIGNMENT 2 FRONT SHEET </b>

<b>Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 19: Data Structures and Algorithms </b>

<b>Submission date Date Received 1st submission</b>

<b>Student Name </b> Hong Thanh Hung <b>Student ID </b> GCS200345

</div><span class="text_page_counter">Trang 3</span><div class="page_container" data-page="3">

<b>Summative Feedback: Resubmission Feedback: </b>

<b>Internal Verifier’s Comments: </b>

<b>IV Signature: </b>

</div><span class="text_page_counter">Trang 4</span><div class="page_container" data-page="4">

<small> </small>

2

<b>Assignment Brief 2 (RQF) </b>

<b>Higher National Certificate/Diploma in Business </b>

<b>Student Name/ID Number: </b>

<b>Unit Number and Title: Unit 19: Data Structures and Algorithms Academic Year: 2021 </b>

<b>Unit Assessor: </b>

<b>Assignment Title: Implement and assess specific DSA Issue Date: </b>

<b>Submission Date: Internal Verifier Name: Date: </b>

<b>Submission Format: </b>

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.

</div><span class="text_page_counter">Trang 5</span><div class="page_container" data-page="5">

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

<b>Unit Learning Outcomes: </b>

<b>LO3 Implement complex data structures and algorithms LO4 Assess the effectiveness of data structures and algorithms Assignment Brief and Guidance: </b>

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

<b>development, including the complexity, the trade-off and the benefits. </b>

</div><span class="text_page_counter">Trang 6</span><div class="page_container" data-page="6">

<small> </small>

4

<b>Learning Outcomes and Assessment Criteria (Assignment 2) </b>

<b>LO3 Implement complex data structures and algorithms </b>

<b>D3 Critically evaluate the </b>

complexity of an implemented ADT/algorithm

<b>P4 Implement a complex ADT </b>

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

<b>P5 Implement error handling </b>

and report test results.

<b>M4 Demonstrate how the </b>

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

<b>LO4 Assess the effectiveness of data structures and algorithms </b>

<b>D4 Evaluate three benefits of </b>

using implementation independent data structures

<b>P6 Discuss how asymptotic </b>

analysis can be used to assess the effectiveness of an algorithm

<b>P7 Determine two ways in </b>

which the efficiency of an algorithm can be measured, illustrating your answer with an example.

<b>M5 Interpret what a trade-off is </b>

when specifying an ADT using an example to support your answer

Contents

Assignment Brief 2 (RQF) ... 2

<b>Higher National Certificate/Diploma in Business ... 2 P4 Implement a complex ADT and algorithm in an executable programming language to solve a well-defined problem. ... 5 P5 Implement error handling and report test results. ... 7 P6 Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm ... 9 P7 Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with an example. ... 10 References: ... 11 </b>

</div><span class="text_page_counter">Trang 7</span><div class="page_container" data-page="7">

<b>P4 Implement a complex ADT and algorithm in an executable programming language to solve a well-defined problem. </b>

To develop data structure and algorithms I have chosen ADT array and write in the Java language. Here is my code to implement an algorithm:

This is the App file which is take responsible to run the algorithm and give us back the result

<small> Stack myStack = new Stack(); Queue myQueue = new Queue(); for (int = 0; < i25;++){ String temp = "Hello "; Random rand = newRandom(); temp += rand.nextInt(100); myQueue.enqueue(temp); </small>

<small> System.out.println("Messages sent from user 1: " + temp); } </small>

<small> while (!myQueue.isEmpty()){ String temp = myQueue.dequeue(); myStack.push(temp); } </small>

<small> System.out.println(); while (!myStack.isEmpty()){ </small>

<small> System.out.println("Messages received from user 2: " + myStack.pop()); } </small>

<small> } } </small>

In this main function, I simulate a chatbox 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.

</div><span class="text_page_counter">Trang 8</span><div class="page_container" data-page="8">

<small> </small>

6

This is queue, the data structure which have enqueue and dequeue function to put in and take out the data.

<small> private inttotal = 0</small>

<small> private intrear; private intfront; </small>

<small> } </small>

<small> iftotal > 0){ total--; </small>

<small> String temp = queue[rear++]; (ifrear == queue.length){ rear = 0</small>

<small> front = -1</small>

<small> } </small>

</div><span class="text_page_counter">Trang 9</span><div class="page_container" data-page="9">

<small> return temp; } return ""; } </small>

<small> return total == ; 0</small>

<small> } </small>

<small> return total == queue.length; } </small>

<small>} </small>

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.

<small> private intindex; private inttotal = 0</small>

<small> } </small>

<small> ifindex >= 0){ total--; return stack[index--]; } </small>

<small> return ""; } </small>

<small> return total == ; 0</small>

<small> } </small>

</div><span class="text_page_counter">Trang 11</span><div class="page_container" data-page="11">

<b>P6 Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm </b>

An algorithm's effectiveness can be determined using Big O Notation. As the input increases, it measures the amount of time it takes to run your function. Alternatively, how well does the function scale?

Time complexity and spatial complexity are the two components that makeup efficiency measurement. The length of the function's computation-step execution time is known as its time complexity. The function's utilization of memory has an impact on space complexity. With the help of two search algorithms, this blog will demonstrate time complexity.

</div><span class="text_page_counter">Trang 12</span><div class="page_container" data-page="12">

<small> </small>

10

Stack illustration because it keeps items in order but only allows access to the top item, a stack is a linear data structure similar to a list. When you hit Command + Z and Command + Y on a Mac or Control + Z and Control + Y on a Microsoft device to undo and redo something, you will only be able to access the most recent modification you made in both circumstances. When using the browser, trying to move backward or forward is another example of a stack in action. Additionally, even though a stack is an abstract data type, it may be implemented using actual data structures like dynamic arrays and linked lists.

<b>P7 Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with an example. </b>

In computer science, there are typically multiple algorithms that can be used to address a given problem. Therefore, using a method to compare the answers and determine which is more ideal is absolutely necessary. The procedure must be:

• Independent of the computer being used to run the algorithm and its configuration. • Displays a straight-line relationship with the number of inputs.

• Can plainly and unambiguously discriminate between two algorithms. There are two such methods: time complexity and spatial complexity.

• Time Complexity: An algorithm's time complexity measures how long it takes to complete a task in relation to the size of the input. It should be noted that the time required to complete the procedure depends on the length of the input rather than the machine's real processing speed.

The total operations for an input length on N are calculated in order to determine the time complexity of an algorithm. It is assumed that each operation takes a fixed amount of time, c. To comprehend the computation process, consider the following example: Let's say that the task at hand is to determine whether a pair (X, Y) exists in an array (A) with N elements and a sum of Z. The easiest approach is to take into account each pair and determine whether or not it fits the requirement.

</div><span class="text_page_counter">Trang 13</span><div class="page_container" data-page="13">

• Space Complexity: The amount of space an algorithm uses to operate as a function of input length is measured by its space complexity. Here's an illustration: Imagine you are trying to determine the frequency of an array's elements.

In addition to spatial complexity, there is auxiliary space. The primary distinction is that although auxiliary space quantifies additional space utilized in the method beyond the input given, space complexity quantifies the total amount of space needed by the algorithm.

<b>OPERATION BEST AVERAGE WORST BEST AVERAGE WORST </b>

<b>isEmpty() </b> O(1) O(1) O(1) O(1) O(1) O(1)

<b>enqueue() </b> O(1) O(1) O(1) O(1) O(1) O(1)

<b>dequeue() </b> O(1) O(1) O(1) O(1) O(1) O(1)

<b>push() </b> O(1) O(1) O(1) O(1) O(1) O(1)

<b>pop() </b> O(1) O(1) O(1) O(1) O(1) O(1) Example for Time and Space Complexity of Queue using Array

<b>References: </b>

<small>Medium. 2022. Introduction to Big O Notation. [online] Available at: </small>

<small>< [Accessed 26 June 2022]. </small>

<small>2022. [online] Available at: < [Accessed 26 June 2022]. </small>

<small>Stack, A., 2022. Array Implementation of Stack | Java Stack Implementation using Array. [online] EDUCBA. Available at: < [Accessed 26 June 2022]. </small>

</div>

×