Professional Documents
Culture Documents
Pathway
LO3 Discuss the importance and dynamics of working within a team and the impact of team working in
different environments
Pass, Merit & Distinction P4 P5 M4 D3
Descripts
LO4 Examine the need for Continuing Professional Development (CPD) and its role within the workplace
and for higher level learning
Pass, Merit & Distinction P6 P7 M5 D4
Descripts
Resubmission Feedback:
1
Data Structures and Algorithms Unit 19 S.M. Sahan Sudharaka Wickramasinghe
* Please note that grade decisions are provisional. They are only confirmed once internal and external moderation has taken place
and grades decisions have been agreed at the assessment board.
Assignment Feedback
Formative Feedback: Assessor to Student
Action Plan
Summative feedback
Assessor Date
signature
Student Date
signature
Pearson Higher Nationals in
Computing
Unit 19: Data Structures &
Algorithms Assignment 01
General Guidelines
1. A Cover page or title page – You should always attach a title page to your assignment. Use
previous page as your cover sheet and make sure all the details are accurately filled.
2. Attach this brief as the first section of your assignment.
3. All the assignments should be prepared using a word processing software.
4. All the assignments should be printed on A4 sized papers. Use single side printing.
5. Allow 1” for top, bottom, right margins and 1.25” for the left margin of each page.
1. The font size should be 12 point, and should be in the style of Time New Roman.
2. Use 1.5 line spacing. Left justify all paragraphs.
3. Ensure that all the headings are consistent in terms of the font size and font style.
4. Use footer function in the word processor to insert Your Name, Subject, Assignment No, and
Page Number on each page. This is useful if individual sheets become detached for any
reason.
5. Use word processing application spell check and grammar check function to help editing
your assignment.
Important Points:
1. It is strictly prohibited to use textboxes to add texts in the assignments, except for the
compulsory information. eg: Figures, tables of comparison etc. Adding text boxes in the body
except for the before mentioned compulsory information will result in rejection of your work.
2. Carefully check the hand in date and the instructions given in the assignment. Late submissions
will not be accepted.
3. Ensure that you give yourself enough time to complete the assignment by the due date.
4. Excuses of any nature will not be accepted for failure to hand in the work on time.
5. You must take responsibility for managing your own time effectively.
6. If you are unable to hand in your assignment on time and have valid reasons such as illness,
you may apply (in writing) for an extension.
7. Failure to achieve at least PASS criteria will result in a REFERRAL grade .
8. Non-submission of work without valid reasons will lead to an automatic RE FERRAL. You will
then be asked to complete an alternative assignment.
9. If you use other people’s work or ideas in your assignment, reference them properly using
HARVARD referencing system to avoid plagiarism. You have to provide both in-text citation and
a reference list.
10. If you are proven to be guilty of plagiarism or any academic misconduct, your grade could
be reduced to A REFERRAL or at worst you could be expelled from the course
Student Declaration
I hereby, declare that I know what plagiarism entails, namely to use another’s work and to present it as
my own without attributing the sources in the correct form. I further understand what it means to
copy another’s work.
Submission format
The submission should be in the form of a report, which contains code snippets (which must be
described well), text based descriptions, and diagrams where appropriate. References to external
sources of knowledge must be cited (reference list supported by in-text citations) using the
Harvard Referencing style.
LO1. Examine abstract data types, concrete data structures and algorithms.
LO2. Specify abstract data types and algorithms in a formal notation.
LO3. Implement complex data structures and algorithms.
LO4. Assess the effectiveness of data structures and algorithms.
6
Data Structures and Algorithms Unit 19 S.M. Sahan Sudharaka Wickramasinghe
Assignment Brief and Guidance:
Scenario
‘XYZ’ hotel chain has 100 banquet halls island wide. Any hotel has minimum one banquet hall to
maximum 5 halls. It provides online hotel banquet hall reservation facilities to their customers.
The reservation system uses a waiting list of the selected banquet halls.
Each banquet hall has unique id, name, location, maximum number guests, reservation date
and the three menu prices. Customer can search a banquet hall with the location, reservation
date and the number of guests. According to the hotel chain rules and regulations, when a
possible match between reservation and the banquet hall is found the customer is contacted
via email or SMS and informed. If customer is not responding within a day, he or she is placed
back in the waiting list and must wait again for another hall.
7
Data Structures and Algorithms Unit 19 S.M. Sahan Sudharaka Wickramasinghe
Task 1: Examine and create data structure by simulating the above scenario and explain the
valid operations that can be carried out on this data structure.
Task 2: Implement the above scenario using the selected data structure and its valid operations
for the design specification given in task 1 by using java programming. Use suitable error
handling and Test the application using suitable test cases and illustrate the system. Provide
evidence of the test cases and the test results.
Task 3: Determine the operations of a memory stack and critically review how it is used to
implement function calls related to the above scenario.
Task 4: Sort the banquets halls with two different sorting algorithms and critically review the
performances of those two algorithms by comparing them.
Task 5: There are 8 hotels available in the Southern district in Sri Lanka. A customer plans to
visit all of these eight hotels through the shortest path within a day.
Analyse the above operation by using illustrations, of two shortest path algorithms, specify how
it operates using a sample graph diagram.
Task 6: Banquet hall details are stored from oldest to newest hall. The customer should be able
to find from the newest to the oldest banquet hall added to the hotel chain.
Using an imperative definition, specify the abstract data type for the above scenario.
Examine the advantages of encapsulation and information hiding when using an ADT selected
for the above scenario.
Object orientation is a paradigm where a computer program functions by objects calling the
methods of other objects, which ultimately produces program behaviour. It makes programming
simple, readable, and makes programs maintainable. Imperative ADTs are basis for object
orientation. Do you agree? Discuss your answer.
Task 7: Implement the above scenario using the selected complex ADT by using java.
Demonstrate how the implementation of an ADT/algorithm solves the above problem.
Critically evaluate the complexity of an implemented ADT/algorithm.
Explain the different ways in which the efficiency of an algorithm can be measured, illustrating
your answer the algorithm which you have developed.
Task 8: Asymptotic analysis can be used to assess the effectiveness of an algorithm. Discuss
Asymptotic analysis for the scenario given in task 7.
Critically review the sort of trade-offs exists when you use an ADT for implementing programs
Describe the benefits of using independent data structures for implementing programs.
Grading Rubric
10
Data Structures and Algorithms Unit 19 S.M. Sahan Sudharaka Wickramasinghe
LO2. Specify abstract data types and algorithms in a
formal notation.
Author recommend queue data structure for this system. because “XYZ” hotel chain required
a waiting list program list program.
Must be included in the waiting list program:
-If customer is not responding with in a day, he/she is placed back into the waiting list
-If the customer requests any change or refuses to reserve, delete the reservation and enter the
back of the queue
The above requirements based on FIFO methodology.it are referred to first in the first exit
procedure. This is the main reason why I recommend the queue data structure to be more
suitable for this system.This is exactly how the queuing system works in the real world. If
you go to a reservation to book a dining room and are first in line, you will be the first to
make a reservation. The queue status is the same as when the data was first entered, the
queue would exit first, The process to add a clement into queue is called enqueue and the
process of removal of an element from queue is called dequeue,
Author The following is the function of the queue data structure
Queue operation
Operation Description
Dequeue () This function define the operation for
removing an element from queue
Enqueue () This function defines the operation for adding
an element into queue
Search Searching is an operation or a technique that
helps find place of a given element or value in
the list.
Init ()/ (is full,is empty ) This function is used for initializing the queue
Front Front is used to get the front data item from a
queue
Rear Rear is used to get the last item from a queue
1. Enqueue
A queue is the maintenance of two data indicators, the front and back steps must be taken to
reserve a queue
Example:
Rear Front
Waiting list reservation
Reservation 4 Reservation 2
Reservation 3 Reservation 1
After confirmation, the specific reservation should be removed from the waiting list. Add a
confirmed reservation
After the responding:
Rear Front
Reservation 4
Conform reservation
2. The client made a temporary reservation but did not respond within a day
No change will occur if the customer does not respond that the reservation should wait
Front
Rear
Reservation 2
Reservation 4 Reservation 3 Reservation 1
3. After confirmation, the customer does not change the requirements such as location,
number of guests.
Conform reservation
It will then be removed from the confirmed reservation and added to the waiting list
Rear Front
Conform reservation
Re move
Reservation 3 Reservation 2 Reservation 1
Reservation 4
Rear Front
The customer then confirms the reservation and takes steps to remove it from the waiting list.
In addition, food is removed from the list of available foods.
Re move
Reservation 3 Reservation 2 Reservation 1
Reservation 4
Rear Rear
Conform reservation
Rear Front
Conform reservation
Rear Front
Remov e
Banquet hall Banquet hall Banquet hall
3 2 1
Banquet hall 4
2. Dequeue
Separation from queues is a two-pronged process. Enter the front-rear reservation and remove
the reservation after access.
Rear Front
Conform reservation
After the checking reservation is not responding with in day. Then it should be removed and
give a chance to following reservation 2.
Rear Front
Conform reservation
Reservation 1
3. Init ()
Is empty
Cheeks whether the queue is empty. (if is empty is true, then the additiona of an item is
possible. If this is false, then acknowledge with the message “queue is empty)
Is full
Cheeks whether the queue is full. (if is full is true, then the removal of an item is possible, if
this is false, then acknowledge with the message “Queue is full”)
4. Search
Searching ai an operation or a technique that helps find the place of a given element or value
in the list. Some of the standard searching technique that is being followed in the data
structure is listed below:
1. linear search or sequential search
2. binary search
The reservation search feature allows you to show reservations by selecting from a larger
search option. This feature provides access to create new reservations and modify exit
reservation information. Access to guest profiles, cancel reservations, cancel large
reservations, check guests and cancel checks
2.Implement the above scenario using the selected data structure and its
valid operations for the design specification given in task 1 by using java
programming.
Class queue
Figure 7 Result
Source: Author developed
Result
Figure 8 Result.
Source: Author developed
2.1 Tase case
TEST PLAN
Table 1 test plan
XYZ Hotels Reservation System
Test plan ID 01
Brief introduction This system is named as XYZ Hotels Reservation System, and
about the system it is a software which manages information about the
Customers and the recipients.
Brief introduction This document defines the plan for testing the Hotel
about the testing Reservation System, and this document supports the following
objectives objectives:
1. Testing the features of the system
2. List the recommended test requirements
3. Describing the recommended test strategies
4. List the deliverables elements of the test activities
Features to be tested Customer ID, Inserting Member Details, Inserting Member ID,
Inserting, Accepting the Customer, Rejecting the Customer,
Continuing the process, Ending the program
Test environment Esoft metro cumpus
Test Case
Test Case
Test unit: Inserting Member Details Test designed by: shan sudharaka
Test case ID: 02 Test designed date: 2nd April 2020
Test Case
Test Case
Test unit: Inserting Customer Details Test designed by: shan sudaraka
Test case ID: 04 Test designed date: 2nd April 2021
Test Case
Test unit: Accepting the Customer Test designed by: shan sudaraka
Test Case
Test unit: Rejecting the Customer Test designed by: shan sudaraka
Test Case
Test unit: Continue the process Test designed by: shan sudaraka
Test Case
-If you want to access any other customer reservation, you would first need to remov
-first and can only be removed at the last after all reservations on top of it have been
Figure 9 Stack
Source: (Khoja.S, n.d.)
Figure 10 push,peek,pop
Source: (Khoja.S, n.d.)
PUSH Operation
The pushing process is the incorporation of an element into the stock. Since there is only one
place where the new element can be inserted - at the top of the stock, the new element is
inserted at the top of the stock.
POP Operation
The pop operation is the removal of an element. Again, we only have access to the element at
the top of the stock, so we can only remove one element. We remove the top part of the
stock. Note: We can choose to return the value of the popped element, this is the
programmer's choice for full implementation.
PEEK Operation
The maximum function allows the user to view the element at the top of the stock. The stock
does not change in any way during this operation.
In order to prevent operations on a blank stock, the programmer needs to maintain the size of
the push internally and thus update during push and pop operations. isEmpty () Traditionally
gives a boolean value: magnitude 0 is true or false.
Stacks in Computer Memory
Memory stocks are linear data structures (locations) used to store data in a computer's
memory. They are also known as queues. The data in a stock must always be of the same
type.
Advantages
Disadvantages
1. the size of the program increases
2. Stack based CPU organization user zero address instruction.
Task 4
Sort the banquets halls with two different sorting algorithms and critically review the
performances of those two algorithms by comparing them.
The author selected in two sorting algorithms
1. Bubble Sort algorithms
2. Selection sort algorithms
1.Bubble sort algorithm
Bubble sorting is a simple sorting algorithm. This sorting algorithm is an element in
which each adjacent element pair is compared and they are switched if the element is not
in order. This algorithm is not suitable for large datasets. Its average and worst
complexity is complexity (n2) and n is the number of items.
(Tutorialspoint.com, 2019)
java code
2.Selection sort
The author suggests that the selection sort algorithm is appropriate because the
selection sort algorithm is faster than the bubble sort.
Also, bubble sorting means using item swapping and item selection. The bubble
sorting algorithm is considered to be the simplest and most efficient algorithm, but
the selection sorting algorithm is relatively efficient compared to the bubble sorting.
Bubble sorting consumes extra space to store the temporary variable and requires
more exchange space.
(Tech Differences, 2017)
Task 5.
There are 8 hotels available in the Southern district in Sri Lanka. A customer plans to
visit all of these eight hotels through the shortest path within a day.Analyse the above
operation by using illustrations, of two shortest path algorithms, specify how it
operates using a sample graph diagram.
Searching method
Search is an operation or technique that helps to find the place of a given element or
value in a list. Any search is said to be successful or unsuccessful depending on
whether the search feature is found or not. Some of the standard search methods
used in a database are element tables, files, simple data elements in arrays, tree
nodes, vertical and edge elements, or charts in other search locations.
(Tech Differences, 2017)
There are 8 hotels in the Southern District of Sri Lanka. A customer plans to visit all
eight of these hotels within a day on the shortest route. Analyze the operation using
examples from two shortcut algorithms.Implementation using a sample graph.
The above scenario gives us an example of using the shortest route algorithm.
Therefore, as mentioned here, there are 8 hotels in the Southern Province. Here we
have to find the shortest route to each of these hotels. So, these hotels are shown in
the chart below, including Route 8. The route is the distance from one hotel to
another. Here are three separate districts in the Southern Province for hotels. A1, A2
are hotels in the HIKKADUWA in Galle District of the Southern Province, and B1,
B2, B3 are hotels in the MIRISSA in Matara District of the Southern Province. C1,
C2, C3 are hotels in the AMBALANTHOTA in Hambanthota District of the
Southern Province.
The author illustrates the graph with,
1. A1, A2 - Hikkaduwa
2. B1, B2, B3 -Mirissa
3. C1, C2, C3 - Ambalanthota
1. Assign a distance value to all verticals in the input group
2. Start all distance values as infinity
3.Assign distance values to infinity
Assign the distance value to 0 for the origin header, then it will be selected first
All we have to do is find the shortest way to get to these 8 hotels using the chart below.
To do this, Author use two separate sorting algorithms.
-Dijkstra’s algorithm
The Dijkstra’s algorithm allows you to calculate the shortest path between one selected
node and each other node in a graph.
Step 01
I will choose A1 as the starting point here. Then, we want to find next node to be traversed.
So, according to the above algorithm we want to find least distance to traversed. Therefore,
B1 is located in long distance as 53KM but A2 is located in a shortest distance as 15Km. So,
first we traversed to A2.
Step 02
In this step we can traverse one node, It is node B2 with 21KM distance. So, at this step we
have traversed 3 Hotels such as A1, A2, B2.
Step 3
We are in this step at B2 Hotel. So, we have 4 hotels to traverse from B2. Namely, B1, B3,
C2, C 3. So, we should traverse a hotel with the shortest distance. So, the shortest distance
has to B3 Hotel, distance is 7KM. So, let's traverse to it.
Figure 18 Dijkstra’s algorithm 3
Source: Author developed
STEP 4
A1 starting point
Step 5
Now we are in C3 there is only one path. From C3. That is C2 witch the distance.
Step 6
There are two hotel that we can go from C2 57km distance. from C2 57 km distance
from C2 to B1 and 11km distance. From C2 to B1 and 11 km distance from C2 to C1.we can
selected the next as C1.
Step 7
Only one hotel we have to go now, witch the distance 50km from H1, the hotel is B1
Relaxation algorithm
Our shortcut execution area is based on an operation called mitigation. We start with disto [s]
to 0 for all other verticals and disto [v] to infinity. Loosening an edge means testing to see if
the best way from s to w is to move from s to v, then move the edge from v to w, then we
need to update our data structures
Vertical relaxation. All our activations actually loosen all the edges that point from a given
header.
Banquet hall details are stored from oldest to newest hall. The customer should be able
to find from the newest to the oldest banquet hall added to the hotel chain.
Using an imperative definition, specify the abstract data type for the above scenario.
Examine the advantages of encapsulation and information hiding when using an ADT
selected for the above scenario. Object orientation is a paradigm where a computer
program functions by objects calling the methods of other objects, which ultimately
produces program behavior. It makes programming simple, readable, and makes
programs maintainable. Imperative ADTs are basis for object orientation. Do you
agree? Discuss your answer.
Author agree
Abstract Data Type (ADT) A series of information and a fixed of operations that perform on
that information is referred to as an summary information type. ADT binds information and
operations together. This so-referred to as closed feature creates the interface of ADT. Data
move is likewise called information hiding. Here the information is hidden to the consumer
due to the fact the consumer can get entry to the information the use of unique features
referred to as methodology. The gadget allows positive regulations on get entry to to
constrained information. In programming, information is posted privately and strategies or
features are made public. The benefit of information consolidation is that it's miles very
critical to shield the data while the use of the gadget. Data is covered from encryption and
hidden from the outdoor world. For example, humans watch tv however the man or woman
looking it does now no longer recognize the intricacies of tv. In turn, the man or woman sees
a lovely color screen. Users get entry to ADT thru operations. Users do now no longer see
how the operation works outdoor. This is referred to as data concealment, so customers can
recognize ADT now no longer with the aid of using the way it works, however with the aid of
using the way it works.
Data type is basically a type of data that can be used for various computer programs. It
represents integers, floats, etc. It takes up 4 bytes of space, as well as 1-bytes of characters.
An abstract database is a specific database whose behavior is defined by a set of values and a
set of operations. The term "summary" is used because we can use these data types and we
can perform various operations. But how those operations work is completely hidden from
the user. ADT is made up of primary databases but the operational logic is hidden.
Stack –
A stock is a last activated linear data structure (LIFO).
Final Out (FILO) Order. The last item to go in is to go out. It operates in two basic operations
Called push and pop. The push operation always adds an item to the top of the stock and
pops it together
Operation removes an item from the top of the inventory. Inventory is always accessible
Up. Contains a stock of the same type of element arranged in sequence.
2. Pop () - If not, remove the element at the top of the stack and send it back.
3. Quantity () - Return the number of elements in stock.
Queue −
Queues are used to retain items needed for processing and different types are provided
Operations such as removal and insertion. New items are added to the queue data structure
The back (tail) and existing items are removed from the front (head) and also contain the
element.
1. The same type is arranged in sequential order.
2. Enqueue ( ) : Insert an element at the tail of the queue.
3. Dequeue ( ) : Remove and return the first element at the head of the
4. Size ( ): Return the number of elements in the queue.
5. Is Empty ( ): Return true if the queue is empty, if not return false.
6. Is Full ( ): Return true if the queue is full, if not return false
List ADT –
1. Get (): Return an element from the given location list.
2. Insert (): Insert an element anywhere in the list.
3. Remove (): Remove the first instance of any element from a non-empty list.
4. Remove (): Here we can remove the element at the identified location from a non-
empty location List.
5. Replace (): Replace an element anywhere with the next element.
6. Size (): Return the number of elements in the given list
7. blank (): If the list is empty go back to true, otherwise it is false.
8. is full (): Go back to true if the list is full, otherwise it is
false. The queue abstract data type
The queue abstract data type is defined by the following structure and operations. As
described above, a queue is structured so that it has a collection of items called "back" at one
end and "front" at the other end. Queues FIFO property orders. Queue operations are as
follows.
1. Queue () Creates an empty new queue. It does not require parameters and provides
an empty queue.
2. enqueue (item) Adds a new item to the back of the queue. It requires the item and
nothing will be returned.
3. dequeue () Removes the front item from the queue. It does not require parameters
and returns the item. The queues have changed.
4. Is Empty () tests to see if queues are empty. It does not require parameters and gives a
Boolean value.
5. Size () returns the number of items in the queue. It does not require parameters
and gives an integer.
For example, if q creates a queue and assumes that it is currently empty, Table 1 shows the
results of the queue operation sequence. The contents of the queue are shown on the front
right. 4 is the first item and is the first item returned by the Duke.
6.1 Advantages of Encapsulation and information and information hiding
1. Reusability
It allows the programmer to reuse programming / encoding methods. Are ADTs Independent
components with high integrity and low connectivity. They can be easily reused in other
ways Applications.
2. Ease of maintenance
ADT is an independent component that does not convert personal data to ADT
Other components may cause side effects. This makes the software very easy to maintain
3. Implementation independence
Has a common interface with ADT operations. How to execute operations
Hidden from end user. Therefore, the implementation can be changed as long as the operation
exists Stay the same.
4. Flexibility
With this we only need to write or read the data
5. Testing of the code
Easy to coding
6. Data Hiding
This allows the programmer to hide the key and give access only to what the user wants.
Codes. It allows developers not to let the user know how to store variables and data.
6.2 Storing banquet hall details
We can use the inventory to store restaurants from the newest to the oldest. Inventory is
abstract data the type that last activates for the first time. The inventory always has access to
the chief Array. New items are added to the top and existing items are removed from the top.
Stock Let us get the first and oldest newest halls the stack ADT specification
Pop () 1. Post-conditions: Top elements removed from stock
2. Input: Inventory
3. Output: Modified stock, upper element removed from stock
4. Algorithm: remove the top element of the stack; Give me a copy
5. Element to the user
6. Exception: Empty
7. Pre-conditions: stack is not empty
Init() 1. Post-conditions: stack is defined and empty
2. Pre-conditions: non
3. Input: No inputs required
4. Output: Invented
5. Algorithm: Start the bulk index
Push (element) 1. Post-conditions: element is put onto the top of the stack
2. Pre-conditions: the stack exits, input element is of appropriate type
3. Input: Inventory and component
4. Output: Modified stock of elemental added
5. Algorithm: Insert the element at the top of the stack
6. Exception: bulk overflow
Is Available(elements) 1. Post-conditions: return true if element available /otherwise return.
2. Pre-conditions: In stock, the input element is of the appropriate type.
3. Input: stock, search elements
4. Output: Boolean value
5. Algorithm: Find the given element from top to bottom
6. Exception: Empty blanks
Uses OOP classes and objects. A class is a template / plan for a similar group of objects. class
Defines data and operations for a similar set of objects. Can define something like a vehicle
class. Vehicle number and speed as vehicle model and operation. Once the class is defined
we Individual vehicle objects can be created. An object is an example of a class. If the idea of
a class. Similar to ADT. They both combine data and operations. Therefore, ADTs may be
Considered as the basis of object orientation. However, OOP's classes are superior to ADT's
Because they support other programming features such as inheritance and polymorphism.
Therefore, Author agree with this object-orientation, that a computer program is driven by
objects called other objects and ultimately produces program behavior. It makes
programming simple, readable and maintainable. Essential ADTs are the basis for object
orientation.
Inheritance
Inheritance in Java is a mechanism by which one object acquires all the attributes and
behaviors of a mother's object. It is an important part of OOPs (Object Oriented
Programming System).
The idea behind Java's legacy is that you can create new classes built on existing ones. Once
you inherit an existing class, you can reuse local class methods and fields. Additionally, you
can add new methods and fields to your current class.
Inheritance represents the IS-A relationship, also known as the parent-child relationship.
(Coursehero.com, 2021)
for an example
Figure 26 Inheritance
Source:(Chaudhary.M, 2020)
Polymorphism
Polymorphism is one of the four main concepts behind object-oriented programming (OOP).
OOP questions are very common in job interviews, so expect multimeter questions in your
next Java job interview.
For example:
In this example, 3 classes are created to represent the polynomial and one class is created to
test the concept. Our super class is called animals. The successors to the animal class are the
dog and cat classes. Those animals, right? That’s what polynomials are - you have many
forms of the same object with slightly different behaviors. To illustrate this, a method called
make Sound () will be used to bypass the output of this method in sequential classes.
Figure 27 Polymorphism
Source: (Java Polymorphism Example | Java Tutorial Network. 2021.)
Task 7
Implement the above scenario using the selected complex ADT by using java.
Demonstrate how the implementation of an ADT/algorithm solves the above problem.
Critically evaluate the complexity of an implemented ADT/algorithm.
Explain the different ways in which the efficiency of an algorithm can be measured,
illustrating your answer the algorithm which you have developed.
The author of Task 3 briefly mentions stocks. Now I execute the ADT stack using the array
Data structure. For example, the author pushes 3 data elements into the following array.
0 01 02 03 04
80 112 170
Stack pointer = 2
The coder below shows only a single stack to keep hall ids.
private int stptr; private int [ ]T; public stack (int size) {
T= new int[size];
}
Public void init()
{
Stptr = -1;
}
Public void push (int data)
{
if (stptr = = T.length -1)
system.out.println(“stack full”)
else
{
Stptr ++;
T[stptr] = data;
}
}// end push
public int pop ()
{int data;
if (stptr = = -1)
{
System.out.println(“stack empty”);
Return 0;
}
else
{
data = T[stptr];
stptr - - ;
return data;
}
}// end loop
public boolean isAvailable(int item)
{ int x = 0;
while (x<T.length)
{ if (item = = T[x])
return true;
else
x + +;
}
return false;
}
}// end stack
The above algorithm solves the problem of storing dining room ID cards from the latest to
old Orders. Whatever it is, there is some sort of weaknesses. Because this is an array
activation the quantity of stock should be defined in advance. Once we have defined it, the
size cannot be changed. If
We declare it too large, then the store is wasted. If the array is too small, the stock will
overflow Held. Another factor is the efficiency of the "existing" operation. This operation a
Search inventory lines. This could be a slow process if we declare a large stock with
thousands from the elements.
Important resources such as time and space complexity cannot be directly compared, so the
complexity of time and space can be considered for algorithm efficiency.
The efficiency of an algorithm depends on how efficiently it uses time and memory space.
The time efficiency of an algorithm is measured by various factors. For example, write a
program for a defined algorithm, execute it using any programming language, and measure
the time it takes to execute. The measured activation time in this case depends on a number
of factors:
1. Machine speed
3. operating system
(BrainKart, n.d.)
Task 8
8. Asymptotic analysis can be used to assess the effectiveness of an algorithm. Discuss
Asymptotic analysis for the scenario given in task 7.Critically review the sort of trade-
offs exists when you use an ADT for implementing programs Describe the benefits of
using independent data structures for implementing programs.
1. In general, the time taken for an algorithm falls into three categories -
2. Best time - Minimum time required to run programs.
3. Normal Case - The average time required to run a program.
4. Worst case scenario - maximum time required to execute programs.
Asymptotic Notations
The following are the most commonly used asymmetric notations for calculating the running
time complexity of an algorithm.
1. Notation
2. Notation
3. Notation
1. Big Oh Notation, Ο
Ο (n) notation is the formal method of expressing the upper limit of the running time of an
algorithm. It measures the worst time complexity or the longest time it can take to complete
an algorithm.
Figure 28 Big Oh Notation, Ο
Source:(Author adapt course.ccs.neu.edu, n.d.)
Ο(f(n)) = { g(n) : there exists c > 0 and n0 such that f(n) ≤ c.g(n) for all n > n0. }
2. , Omega Notation
The lower limit of the running time of the algorithm is the formal method of expressing the
(n) numbering. It measures the best time or the best time it can take to complete an algorithm
3. Theta Notation
θ(f(n)) = {g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n)) for all n > n0. }
Benefits
Agent Independence: Most programs are independent of abstract data representation, which
can improve performance without interrupting the entire program.
Modularity: With representation independence, different parts of a program do not depend on
other parts, but on how other parts work.
Stock Exchange Capacity: Different implementations of an abstract data type may have
different performance characteristics. With abstract data types, activating its data types for
each part of a program is easy to use, making it more efficient for a specific part of the
program.
Source:(course.ccs.neu.edu, n.d.)
Drawbacks –
- A class enabled as ADT must present getters / setters methods and techniques that allow
access to the 'attributes' of the client code.
- More code means - more testing, more room to introduce errors in our code
2. Limited access: We, as the class user (as the server coder who uses the class), may be
limited by the class 'common methods'.
- Operations that we like to "on" objects in this class may include operations that are not
presented in the class 'common interface'.
Given 2 algorithms for a task, however will we ascertain that one is better?
There may be one childish way to do this - implement each algorithm and run 2 programs on
the laptop for different applications and see that it takes less time. Measure some of the
problems with this approach to analyzing the algorithm.
1. It might be attainable that for a few inputs, 1st rule performs higher than the second.
And for a few inputs second performs higher.
2. It might even be potential that for a few inputs, 1st algorithmic rule perform higher on
one machine and therefore the second works higher on different machine for a
few different inputs.
The big idea that handles the above problems when analyzing algorithms is asymmetric
analysis. In asymmetric analysis, we estimate the performance of an algorithm based on the
input volume (we do not measure the actual running time). We calculate how much time (or
space) an algorithm increases with the input size.
(GeeksforGeeks, 2012)
8.3 Advantages of Asymptotic Analysis
Asymmetric analysis is very helpful to analyze the efficiency of an algorithm with runtime
inputs. Otherwise, it can happen if we do it using test cases for different inputs- the
performance may change when the input given to the algorithm changes. The functionality of
the algorithm changes when running on different machines.
Thus, providing a mathematical representation gives a proper understanding of the upper and
lower limits of the running time of the algorithm. This prompts us to select an algorithm
whose performance does not change as the number of inputs provided increases.
(EDUCBA, 2019)
8.4 Reviewing the trade-off types when using ADT
A trade is a situation where one thing increases and another decreases. Here's how to fix the
problem:
1. Either in less time and using more space
Compressed or Uncompressed Data: Spatial trading can be applied to the problem of data
storage. If the stored data is not compressed, it will take up more space but take less time. But
if the data is stored compressed, it will take up less space but will take longer to execute the
decompression algorithm. There are many opportunities to work directly with compressed
data. In compressed bitmap indicators, working with compression without compression is
faster.
Reloading or storing images: In this case, storing only the source and rendering it as an
image will take more time, but it will take less time, that is, storing an image in the cache will
be faster than reloading but will require more memory.
Shortcode or loop unrolling: Shortcode has less space in memory but requires a longer
computation time to jump back to the beginning of the loop at the end of each stop. Loop
unrolling allows you to optimize the execution speed according to the increased binary size
cost. It has more space in memory but requires less computational time.
Query Tables or Recalculation: In a viewing table, activation can include a complete table
that reduces computer time but increases the required amount of memory. It can be
recalculated, counting table entries as needed, increasing computer time but reducing
memory requirements.
For example: Mathematically, the Fn sequential iteration of Fibonacci numbers is defined by:
A simple solution to find the term Nth Fibonacci using the iteration of the recurrence link
above.
Implementation using repetition is as follows:
Figure 32 Recursion
Source: (GeeksforGeeks, 2020)
Abstract data types offer several advantages over concrete data types
After reading this the author returns to the question of ADT testing.
Now, let's look at a simple representation for MyString: an alphabet, exactly the length of the
strings (no extra space at the end). Here's how to express that internal representation as an
illustration variable in class:
To implement this optimization, we can change the internal representation of this class as
follows.
Existing clients in My String depend not only on its private domain, but also on the
specifications of its common methods, so we can check the server code and make this change
without modification. That is the power of representation independence.
Reference:
Educative: Interactive Courses for Software Developers. (n.d.). Data Structures 101: how to
use Stacks and Queues in Java. [online] Available at: https://www.educative.io/blog/data-
structures-stack-queue-java-tutorial. Accessed on may 10th 2021.
EDUCBA. (2019). Asymptotic Analysis | Benefits and Top 5 Asymptotic Notations with
Graphs. [online] Available at: https://www.educba.com/asymptotic-analysis/. Accessed on
April 15th 2021.
Java Polymorphism Example | Java Tutorial Network. 2021. Java Polymorphism Example |
Java Tutorial Network. [ONLINE] Available at: https://javatutorial.net/java-polymorphism-
example. Accessed on April 15th 2021.
Study.com. (2020). Stacks in Computer Memory: Definition & Uses | Study.com. [online]
Available at: https://study.com/academy/lesson/stacks-in-computer-memory-definition-
uses.html. Accessed on April 12th 2021.
Tech Differences. (2017). Difference Between Bubble Sort and Selection Sort (with
Comparison Chart). [online] Available at: https://techdifferences.com/difference-between-
bubble-sort-and-selection-sort.html#ComparisonChart. Accessed on April 12th 2021.