Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 19: Data Structures and Algorithms

Submission date August 31st 2019 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Huynh Tan Phat Student ID GCS18016

Class GCS0605 Assessor name Dr. Le Minh Nhut Trieu

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
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:

IV Signature:

Page 2
ASSIGNMENT 2 BRIEF
Qualification BTEC Level 5 HND Diploma in Business

Unit number Unit 19: Data Structures and Algorithms

Assignment title Implement and assess specific DSA

Academic Year 2019 - 2020

Unit Tutor Dr. Le Minh Nhut Trieu

Issue date August 31st 2019 Submission date August 31st 2019

IV name and date

Submission Format:
Format: The submission is in the form of an individual written report. 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 Tutors. The form of submission will be a soft copy in PDF posted on corresponding course
of http://cms.greenwich.edu.vn/ Project also needs to be submitted in zip format.
Note: The Assignment must be your own work, and not copied by or from another student or from
books etc. 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 know how to reference
properly, and that understand the guidelines on plagiarism. If you do not, you definitely get fail
Assignment Brief and Guidance:
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 system requires 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.

Page 3
Learning Outcomes and Assessment Criteria

Pass Merit Distinction

LO1 Implement complex data structures and algorithms

P4 Implement a complex ADT M4 Demonstrate how the


D3 Critically evaluate the
and algorithm in an executable implementation of an
complexity of an implemented
programming language to solve ADT/algorithm solves a well-
ADT/algorithm
a well-defined problem. defined problem

P5 Implement error handling


and report test results.

LO4 Assess the effectiveness of data structures and algorithms

P6 Discuss how asymptotic M5 Interpret what a trade-off is


analysis can be used to when specifying an ADT using D4 Evaluate three benefits of
assess the effectiveness of an an example to support your using implementation
algorithm answer independent data structures

P7 Determine two ways in


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

Page 4
Contents
P4 Implement a complex ADT and algorithm in an executable programming language to solve a well-defined problem.
......................................................................................................................................................................................... 1
ADT interface...............................................................................................................................................................1
Stack ADT implementation..........................................................................................................................................1
P5 Implement error handling and report test results......................................................................................................3
Stack ADT error handling.............................................................................................................................................3
Stack ADT catching exceptions testing.........................................................................................................................4
M4 Demonstrate how the implementation of an ADT/algorithm solves a well-defined problem...................................5
Stack ADT operations testing.......................................................................................................................................5
Abstract data type testing............................................................................................................................................6
D3. Critically evaluate the complexity of an implemented ADT/algorithm......................................................................7
P6 Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm........................................8
Two ways to convert decimal to binary........................................................................................................................8
P7. Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with an
example......................................................................................................................................................................... 10
Time complexity.........................................................................................................................................................10
Space complexity.......................................................................................................................................................11
M5. Interpret what a trade-off is when specifying an ADT using an example to support your answer..........................12
D4 Evaluate three benefits of using implementation independent data structures......................................................13
Reference....................................................................................................................................................................... 14

Page 5
Page 6
P4 Implement a complex ADT and algorithm in an executable programming
language to solve a well-defined problem.
In order to transfer the messages and process it through layers, the developed team is required to create a
middleware which includes the implementation of Stack and a demo version with message is a string of 250
characters. In addition, the errors of the Stack implemented are needed to be handled by exceptions and
demonstrated the accuracy of the operations by some executed cases.

ADT interface

Figure 1: Interface of Abstract Data Type

First of all, an interface of the abstract data type “E” is created in order to implement in the StackADT class.
The interface Stack<E> includes the method of the StackADT implementation consisted of isEmpty(),
isFull(), top(), push(), pop() with the “E” ADT.

Stack ADT implementation.

The following is the code sample of Array-Stack operations with explanations in order to help the readers to
understand the source code easily. First of all, the declaration of variables and creation of Array Stack will
be introduced.

Figure 2: Creating a StackADT.

It is noticeable that the Figure 2 is represented for the creation of the Stack using an Array. Firstly, an Array
named “S” is created with the data type “E” (code line 3) which is an abstract data type and the “max”,
“head” variables is declared as integer (code line 4). Three of them are “private” which means only the
public methods can be used these variables and to increases the security of them. In addition, “max”
represents for the length of the array and “head” stands for the last elements in the array. After declaring
the necessary variables, a Stack named StackADT is created with the input is “int max” (code line 6) and the
length of the Array-Stack will depend on the input of the Stack ADT (code line 7). Moreover, the code line 8

Page 1
is created an array with the length is the input of the max and with “head = -1” (code line 9) which means
there is no element in the Array right now.

Figure 3: IsEmpty() Method

After creating an Array-Stack, the first operation will be introduced is the IsEmpty(). According to Figure 3,
the method is created with Boolean data type (code line 11) which is needed to return something such as
true or false at the end of the method. In order to implement the isEmpty() method, the “head” is declared
as “-1” which means there is no element in the array (code line 12).

Figure 4: isFull() Method

The next operation of Stack is the isFull() which help to check whether the Stack is overflow or not. As well
as isEmpty() the data type of isFull() is Boolean (code line 14) and if the length of the elements is equaled to
the length of the array then the Stack is full (code line 15).

Figure 5: push(n) Method

After discovering the two checking operations of the Stack, the first functional method is the push(n). The
push(n) method is declared as “public void” which means no return at the end of the method and
contained an input is “E n” (code line 17). When the “n” is inputted into the method, it will be added to the
“head” of the array “S” (code line 21).

Figure 6: pop() Method

Another functional method is pop() which will print out the last element of the array and delete it. As can
be seen in the Figure 6, pop() is declared as “public E” with no parameter (code line 24). The pop() will take
out the front value in the array (code line 26) and delete it after taking (code line 27) then print it (code line
28).

Page 2
Figure 7: top() Method

As well as pop(), the top() operation also prints out the top element but without removing the value.
“Public E” is the way declaring the method top() and it also does not have any parameter (code line 35). At
code line 37, the top element of the Stack will be returned.

Figure 8: clear() Method

The last operation is clear() which will delete the entire element in the array. Similar to the other methods,
clear() is declared as “public void” and have no parameter (code line 43). The Array-Stack will be cleared by
giving the “head = -1” (code line 44).

P5 Implement error handling and report test results.


Stack ADT error handling

In order to catch the exception of the Stack implementation, some source code is added to the functional
operation consists of push(), pop() and top(). The first operation to be fixed is the push() method.

Figure 9: push(n) Method with error handling

As can be seen in the Figure 9, the if() function with “isFull()” condition (code line 19) is added to the push()
method in order to catch the exception if the stack is full, the element will not be inserted in the Stack. If
the condition is true, the push() will return “Stack is overflow” announcement otherwise the element will
be added to the Stack as usual. Moreover, the maximum of the characters which push into the Stack is 250
strings. If the length gets over 250 strings, the element will not be pushed into the Stack and return the
error announcement (code line 22).

Page 3
Figure 10: pop() Method with error handling

It is noticeable that the “try-catch” is added to the pop() operation in order to handle the case that the
exception of the method (code line 25 to 32). If the “try” runs without exceptions (code line 27 to 31), the
pop() will print “x” to the user as usual. On the other hand, the pop() method will run the “catch” in order
to print out the “Stack is empty” announcement. Moreover, the ADT “Object” obligates to return
something to get out of the method so that the “null” is chose in order to reduce the affection to the code
(code line 33).

Figure 11: top() Method with error handling

Similar to pop() operation, the top() method is also added the “try-catch” to the operation in order to catch
the stack underflow error. If the “try” does not contain any problem (code line 36), the “head” element of
array “S” will be return (code line 37) otherwise the “catch” will execute and return “Stack is empty” to the
user (code line 39). As well as pop(), the code line 41 is obligated because of the Object ADT.

Stack ADT catching exceptions testing

After figuring out the operation principle of the added source code, the code will be tested for
demonstrating the new source code is worked.

Page 4
Figure 12: Catching exceptions testing

As can be seen in the Figure 12, the Stack named “s1” which can contain 3 elements is created firstly in
order to using the operation of Stack (code line 64). The first three element is inserted into the Stack (code
line 65, 66, 67) consists of “Monday”, “Tuesday” and “2019”. When pushing the fourth element into the
Stack (code line 68), instead of inserting the object into the Stack, the system will return “Stack is overflow”
(Output line 1) because the length of the “s2” is only 3 elements. In order to check the error handling of
pop() and top() (code line 70 and 71), the clear() is called (code line 69) in order to clear the Stack for the
pop() and top() to catch the exceptions. It is noticeable that the system returns “Stack is empty” (Output
line 2, 3) instead of printing out the element. From code line 72 to 76, the element which is pushed into
Stack is over 250 strings in order to check the 250 strings overload (Output line 4).

M4 Demonstrate how the implementation of an ADT/algorithm solves a well-


defined problem
Stack ADT operations testing

When the implementation of Stack is done, it will be tested in order to demonstrate the operation is
working. The following is the testing of Stack operation without error handling.

Page 5
Figure 13: Stack's operation testing

First of all, a Stack named “s1” is created in order to using the method of the StackADT (code line 47) with
the length is 3 elements. To check the ADT works or not, the first two elements with different kinds of data
type is pushed into the “s1” included s1 “Phat” stands for string (code line 48) and “500” represents for
integer (code line 49). Continue to push another object is “Duy” (code line 50) in order to check if the
isFull() method (code line 51) is running (Output line 1). After that, the pop() is called (code line 52) to print
the last element out and delete it (Output line 2). When the element “Duy” is remove out of the Stack, the
top() method is executed (code line 53) to check whether the “Duy” is delete or not and also returned the
top element after deleting (Output line 3). Finally, the clear() function is called (code line 54) in order to
clear the elements in the Stack and check the stack is empty or not (Output line 4) after clearing by
isEmpty() (code line 55). In conclusion, the Stack operations work effectively.

Abstract data type testing

Figure 14: Stack ADT with Integer

The Figure 14 is noticeable that the Stack named “s2” which has the length = 3 is created with the Integer
data type (code line 50). In order to test the Stack is worked or not, two integer elements are pushed into
the Stack (code line 51, 52) then popped out the value at the top (code line 53) and return to the user
(Output line 1). After that, the top() operation is executed (code line 54) in order to print the topmost
element (Output line 2).

Page 6
Figure 15: Stack ADT with String

As can be seen in the Figure 14, a Stack named “s3” which has the length = 3 is created with the String data
type (code line 50). In order to test the Stack is worked or not, two integer elements are pushed into the
Stack (code line 51, 52) then popped the topmost element (code line 53) and return to the user (Output
line 1). After that, the top() operation is called (code line 54) in order to print the element at the top
(Output line 2).

D3. Critically evaluate the complexity of an implemented ADT/algorithm


The implementation of Stack using array consisted of push(), pop(), top(), clear(), isEmpty() and isFull()
operation. In order to evaluate the complexity of implemented Array-Stack these operations are divided
into two kinds of method includes checked operation represented for clear(), isEmpty() and isFull() and
functional operations stand for pop(), push() and top().

Checking operations

Operation name Time complexity Space complexity


isEmpty() O(1) O(n)
isFull() O(1) O(n)
Clear() O(1) O(n)
Figure 16: Checking operation complexity

According to the Figure 13 table, the time complexity of the three checking operations is O(1) due to the
fact that these operations only contain a constant code line. The O(1) which is stand for the time complexity
has provided that the isEmpty(), isFull() and Clear() method run quite fast which means the execution time
of these algorithm remain the same although the size of the problem increases largely. For example, the
time to run the Clear() method is 1 second, it does not matter how many element the Stack contains such
as 500 elements or 5 elements in it but the run time of Clear() method still is 1 second. In conclusion, the
running time of these operations are very quick and it is independent on the size of the dataset while
running.

The Figure 13 table is witnessed that the Space complexity of the checking operations is all O(n) because of
the memory space will be allocated to the methods basing on the numbers of the methods call from the
users. Therefore, the usage storage for these operations can be small or huge due to the amount of time
the developer use it. For example, the isEmpty(), isFull() and Clear() require 4 bytes for each method called,
if the developer use each method one time so that the memory space needed for the methods called is 12
Page 7
bytes. As can be seen in the example, although 4 bytes are not the large amount of memory space, the O(n)
will not good for algorithm to work efficiently if the values of n is big. To sum up, the space complexity of
these operations do not required much memory space but it will take significantly an amount of memory if
it is used too much.

Functional operations

Operation name Time complexity Space complexity


Push() O(1)* O(n)
Pop() O(1)* O(n)
Top() O(1) O(n)
Figure 17: Functional operation complexity

As can be seen in the Figure 14 table, the time complexity for push() and pop() operation is O(1)* (* means
average) when using appendix to adding an element which means the item is inserted at the next to the
last index. Suppose having a 4-bytes array with 1-bytes for each block, in order to insert or remove an
element at the fifth position, the array will create or delete 4 bytes block which is taking time to create /
delete. Therefore, the push() and pop() has the time complexity differed to the other functions whose
having O(1) running time. In addition, the time execution of push and pop is still dramatically fast although
it has to remove or add new 4-bytes block. As well as the checking operation, the time running of pop()
operation in this case is O(1) which means it is evaluated as very significantly fast and the time running is
not changing by the affection of the input size. In conclusion, the time execution of the functional
operations is similar to the checking operations but the push() and pop() method is slightly different from
the others.

It is noticeable in the Figure 14 table that the space complexity of the checking operations and the
functional operations is equaled to each other which mean they are both O(n). Therefore, the larger the
use of push(), pop() and top(), the more memory space is required for allocating to the algorithm which
means the number of “x” bytes are allocated for the “n” input elements. To sum up, the space complexity
of the functional operations is evaluated that they do not require too much space for the operations in
condition they are not called many times.

P6 Discuss how asymptotic analysis can be used to assess the effectiveness of an


algorithm.
In order to analyze the effectiveness of Stack when implementing an algorithm, the mathematic of
converting from decimal to binary will be created in two ways consists of converting using stack and not
using stack.
Two ways to convert decimal to binary

Decimal to binary not using Stack operations

Before figuring out the effectiveness of algorithm using Stack, the normal implementation of converting
decimal to binary will be performed in order to compare with the algorithm using Stack. The following is
the code sample of converting decimal to binary using custom logic.

Page 8
Figure 18: Decimal to binary without Stack

As can be seen in the Figure 13, the code sample is represented for the algorithm converting decimal to
binary in a normal way. The method DtoBin() with “int dec” parameter is declared as “public static void”
(code line 4). The variables which are declared in the methods consist of an array named bin with 40 integer
element (code line 5) and a variable “int index = 0” (code line 6). After declaring the variables, the loop
“while (dec > 0)” is created (code line 7) in order to divide by 2 the inserted decimal and add the residual to
the array “bin[]” (code line 8) and it continue to divide by 2 one more time (code line 9). The process will be
repeated until the input “dec” is smaller than 0. When the while() loop is over, the loop at code line 11 and
12 is used to print out the elements from the array bin from left to right in sequence.
Decimal to binary using Stack operations
After figuring out the Dec to Bin method using logic, the operation transferring from decimal to binary using
Stack will be discovered.

Figure 19: Decimal to binary using Stack

It is noticeable in the Figure 14 that the StackADT has been applied to the algorithm. First of all, the Stack
named “s3” is created with 40 elements in order to using the operations of the Stack. After creating the
Stack, the while() loop is declared with the condition is parameter “dec != 0” (code line 60) which means it
was not until that the decimal is equaled to 0, the while() loop is over. Code line 61 shown us that the
variable “int x” will be assigned the residual of the result of “dec % 2” and then the “x” will be pushed into
the “s3” stack (code line 62) and continue to divide the dec by 2 one more time. The process will be
continued until the while() is over. Applying the operations Stack to the dectoBin(dec) function, the printing
process will be altered by using the loop while() with the condition is checking the isEmpty() method until

Page 9
the Stack is empty (code line 67). If the condition is satisfied, the “s3” will pop and print out the element
(code line 68) until the Stack contains no element.

Compare two implemented ways of decimal to binary problem

After figuring out the operation principle of two ways to implement the decimal to binary problem, they
will be compared to show which one is better and why the better algorithm should be in used.

As can be seen in the analysis of the decimal to binary problem which is implemented in two different ways,
the method with the support of Stack operations (Figure 14) is more effective than the one that creates
using logic (Figure 13). First of all, at the second loop of each source code, the Figure 14 will help the
developer to use the logic lesser than the Figure 13 due to the support of Stack operations which means
the Figure 13 is required the developer to think about the complex conditions of the loop for() such as
What the element “i” should equal to; the “i” have to bigger or smaller than how much or it should
increase or decrease a value after the loop. On the other hand, the Figure 14 only need to know if the Stack
is not empty then pops out the topmost element from the Stack by using the isEmpty() and pop() method
of Stack.

According to the view of the code readers, they will prefer the source code of Figure 14 to the Figure 13
because it is easier to understand. It is not necessary to think much about the condition for printing the
result, the reader is only required a bit about the simple features of the Stack’s operations in order to figure
out the meaning of the source code. In addition, it also helps the reader to explain it to the other people
who are not IT professionals. For instance, these people will not understand anything about when reading
the code but with the support of the readers and their acknowledges about the Stack, the Figure 14 source
code will be easily to transferred from the readers to the people who are not IT professionals.

In conclusion, the Figure 14 is better than the Figure 13 due to the simple source code of the Figure 14 by
using Stack operations and it does not require many logic concept in the code which helps developers to
write the code smoothly. Moreover, the Figure 14 is easier to understand for people who have experience
about code and also those who are not IT professional because the operation principle of Stack is very clear.

P7. Determine two ways in which the efficiency of an algorithm can be measured,
illustrating your answer with an example.
Complexity of algorithms is a concept which is used for measuring the efficiency of an algorithm. For
instance, there are many styles to create an algorithm but which style is better so that the concept will help
to define which is better. In order to analyze which ways to implement algorithm is good, it is usually
calculated the time that the algorithm running on the system and the space that it containing in the
memory. These two concepts are known as the time complexity and space complexity of an algorithm and
they are the two features of the algorithm complexity in general.

Time complexity
The time complexity performs the needed time for an algorithm to run from the beginning and the end of
it. The time required is executed by a T(n) function in which the T(n) is defined as the numbers of step in
the algorithm. For example, the summarize of two integers will have “n” step which means the total of

Page 10
calculated time will be T(n) = c*n with “c” is represented for the necessary time to sum two integers. The
T(n) will have a linear increment if the size of the input is increased. For instance, the time to solve the
summarize of two integers will higher when the inputs are “n1 = 239” and “n2 = 429” otherwise it will
faster with the inputs are “n1 = 1” and “n2 = 8”. In order to make the Time Complexity clearer, the decimal
to binary algorithm using Stack will be analyzed.

Figure 20: Time complexity of DecToBin using Stack

T(n) = c1 + (n+1)*c2 + n*c3 + n*c4 + n*c5 + c6 + (n+1)*c7 + n*c8 + c9.

T(n) = (c1 + c2 + c6 + c7 + c9) + n(c2 + c3 + c4 + c5 + c7 + c8)

T(n) = a + n*b

 Time complexity of Figure 15 is proportional to O(n).

As can be seen in the Figure 15, the command section at the right of the source code is stand for the time
to execute of each operation in the function such as “1”, “n” or “n + 1” and the “c” is represented for the
cost of each operation in an algorithm. Moreover, the operations which are outside of the loop such as
code line 6, 7 or 17 will take “1” time to run. The while() function will take “n + 1” time because it will
execute until the condition is satisfied and the variables which are contained in the while() loop will take
“n” time according to the amount of the loop running time. To sum up, the Total Cost of the algorithm will
be “T(n) = c1 + (n+1)*c2 + n*c3 + n*c4 + n*c5 + c6 + (n+1)*c7 + n*c8 + c9”. Applying the dropping constant
rule, the necessary time for the Figure 15 algorithm is proportional to “n” which means it is a linear growth
rate and it quite fast due to the feature of linear growth rate.
Space complexity

The space complexity calculates the amount of required space which is needed for an algorithm in order to
execute during the course. The memory space which an algorithm needed to use (S(P)) is performed by the
summarize of “c” stand for fixed part which is the space to store the simple constant such as “10”, “π” and
“Sp” represented for the variable part which is needed storage of variables where the size of the storage
depending on the size of problem such as allocating recursive memory, stack memory, etc. Therefore, the
general formula for space complexity is “S(P) = c + Sp”. Suppose to have a command line “x = y + z + 25”, the
space complexity will be calculated by “S(P) = c + Sp  S(P) = 4 + 0  S(P) = 4” with three variables are “x”,
“y”, “z” and “25”.

Page 11
Figure 21: Space complexity of DecToBin using Stack

S(P) = c + Sp

 S(P) = 1 + n + n  S(P) = 2n + 1

 With each unit of space equal to 4 bytes, the S(P) = 8bytes * n + 4bytes

 Space complexity of the Figure 16 is equaled to O(n).

Retrospect to the converting from decimal to binary algorithm, the space complexity of the algorithm will
be measured by the formula which is given above. The Figure 16 provides that the yellow stressed which
appears at code line 5, 6 and 8 are the determined storage of variables. The first variable “int dec” is
equaled to “1” (code line 5) due to the needed space for algorithm. A Stack is created at code line number 6
which will take a “n” space of the memory because it contains an array in. In addition, the variable “int x”
(code line 8) is also equaled to “n” because the while() loop will repeat, the “x” will be created each
iterations. Therefore, the “c” for the Figure 16 will be “c = 1” and the “Sp” will be “Sp = n + n  Sp = 2n”
because there is no constant in the algorithm. Moreover, the space complexity of Figure 16 is calculated as
“S(P) = c + Sp  S(P) = 2n + 1” so that the space complexity will equal to 2n + 1. Applying the dropping
constant rule, the required space for the Figure 16 algorithm is proportional to “n”.

M5. Interpret what a trade-off is when specifying an ADT using an example to


support your answer
The tradeoff when specifying an ADT is the trade-off between space using and time running of an
algorithm. A space-time tradeoff can be known as which way the developer choose to solve a problem
which means an algorithm will reduce the time executed by increasing the memory space otherwise the
algorithm can spend more time to decreasing the usage of memory. In these modern days, most of the
computers are upgraded with the huge amount of memory space so that the young developers usually do
not care about the required memory space while coding but it is noticeable that the space of the memory is
not infinite. On the other hand, the people who have the low quality computers are pleased to wait for
executing a big calculation but not in a long duration which means it only can take no longer than 30
minutes to run a huge algorithm. Therefore, the concept of space-time tradeoff is introduced in order to
solve these situation which means the developers are allowed to used more memory space to execute the

Page 12
program more quickly otherwise if the memory space is limited the developers will have to take more time
to solve the problem.

For example, the worst, average and best case of merge sort in time complexity is O(nlogn) but it needs an
auxiliary array in order to use the merge sort which means more memory space is required although it is
quite fast due to the time complexity. By contrast, the time complexity of quick sort is O(nlogn) for the best
and average case and O(n2) for worst case which means the time to execute is slower than merge sort but it
does not require allocating the memory for auxiliary array. Therefore, depending on the necessity of the
developers, they will choose which sorting algorithm is the best for them to use.

D4 Evaluate three benefits of using implementation independent data structures


In order to evaluate the benefits of using implementation independent data structures, the three
advantages of them are determined as the representation independence, modularity and interchangeability
of the data structure’s implementation.

The first benefit of using implementation independent data structures is the representation independence
feature which means the abstract type will not relate to the actual data structure. Therefore, if the
representation made some changes, it would not affect to the code of the abstract type. This benefit allow
the developer to implement the data structures in their own way but still keep the basic operation of the
data structure. For example, Stack can be implemented by using the array or the linked list.

Modularity is the second advantage of using independent data structure implementation. This helps the
implementation of the independent data structure to separate from the other program and they can be
implemented in the other program in the most effective way. In addition, it will help to hide the details of
the implemented source code to the user which means they only need to call the method by some code
line in order to use it and do not need to know the inside.

Another benefit of using implementation of independent data structure is interchangeability. In this some
implementation of the data structure might suite for one software and might for software another
alternative implementation needed. So this implementation can be changed based on the program or
software need. For example, the user can use a Queue with String, Integer or Record data type with only
one implementation for the Queue which means the developers do not to create the implementation of
the Queue many times in order to use different data type.

In conclusion, implementation of any algorithm or the data structure is very important in terms of the
program performance in terms of the time complexity and space complexity so one data structure might
need the separate implementation based on the availability of the memory or the processing power.
Therefore, when memory optimization is more important than may be time complexity can be high but
space complexity needs to be within the control and vice-versa. So these implementation independent data
structure give the free hand to the developer use their own wisdom and implement it.

Page 13
Reference
1. Clinger, W. (2019). Advantages of Abstract Data Types. [online] Course.ccs.neu.edu. Available at:
https://course.ccs.neu.edu/cs5010f17/InterfacesClasses2/advantagesADT1.html? [Accessed 31
Aug. 2019].
2. Giải thuật là gì ?. (2019). Giải thuật là gì ?. [online] Available at: https://hoclaptrinh.vn/tutorial/cau-
truc-du-lieu-amp-giai-thuat-55-bai/giai-thuat-la-gi?
fbclid=IwAR3_fhTmEIm9x79SR1ycYEXo1HhYYWWHiFjCMh1Geuxg2oSX4sB7FZIqcvc [Accessed 31
Aug. 2019].
3. Medium. (2019). Stack Implementation and complexity. [online] Available at:
https://medium.com/@kaichimomose/stack-implementation-and-complexity-c176924e6a6b [Accessed
31 Aug. 2019].
4. YouTube. (2019). Time Complexity, Space Complexity, and Big O. [online] Available at:
https://www.youtube.com/watch?v=8mBxpDWEKNw&t=519s [Accessed 31 Aug. 2019].
5. YouTube. (2019). Space complexity with examples. [online] Available at:
https://www.youtube.com/watch?v=nmoQ6ZKId3k&t=304s [Accessed 31 Aug. 2019].
6. Wikipedia. (2019). Space-time tradeoff. [online] Available at:
https://simple.wikipedia.org/wiki/Space-time_tradeoff [Accessed 31 Aug. 2019].
7. Quora.com. (2019). [online] Available at: https://www.quora.com/What-is-the-time-space-trade-off-
in-data-structures [Accessed 31 Aug. 2019].

Page 14

You might also like