Unit 34 Data Structures and Algorithms
Unit 34 Data Structures and Algorithms
Assignment title
Learner’s name
Have the learner and assessor confirmed Yes. the learner and assessor confirmed the
Y/N
the authenticity of the evidence? authenticity of the evidence
Has the work been assessed accurately? Y/N Yes. the work been assessed accurately
Does the assessment feedback to the the assessment feedback to the learner is
learner: Y/N
Link to relevant assessment criteria with appropriate
Link to relevant assessment criteria? justifications
Justify each assessment criterion awarded?
Internal Verifier
t Date 2019/01/10
signature
Internal Verifier
Date
signature
QCF BTEC
INTERNAL VERIFICATION – ASSESSMENT DECISIONS
HND in Computing & Systems Development
Assignment Brief
BTEC Level 4-5 HNC/HND Diploma (QCF)
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 way. I further understand what it means to copy
another’s work.
Task 1
A palindrome is a phrase that reads the same forwards as it does backwards. For example, “DAD”,”
MOM”,” madam” are examples for palindrome.
HND in Computing & Systems Development
1.1. Write a program that figures out whether the given string is a palindrome. Use suitable
String operations to avoid white spaces and punctuation (LO3.2) (D3.4)
For example:
"Never a foot too far, even." is a palindrome.
"Top step -- Sara's pet spot." is a palindrome.
1.2. Create an Example Stack class for this problem. Use Array List or an array to
implement the Stack, use suitable stack operations. (LO 2.1)
1.3. Identify and implement opportunities for error handling and reporting. (LO 2.2)
1.4. Prepare a user manual for the developed solution to assist the users to work with it. (M 3.1)
Task 2
‘Read-With-Us’ Library Systems provides book reservation facilities to their members. The reservation
system uses a waiting list or book or other reading material allocation. According to the library
rules and regulations, when possible match between reservation and the book is found the member
is contacted via email or SMS and informed. If member is not responding within the given time
period, she or she is places back of the waiting list and must wait again.
We will simulate this process using a queue, and simplify the rules. We will ignore the realistic
constraints of the members, and simply have each member store a reference number for the book
(a random number). We will also assume that each book, once accepted, will be occupied from a
member ID.
Insert book details through the keyboard. Each book should have Reference number (a random
number ex: 2552)
The book Assignment process should remove a member from the queue if the member “accepts” the
reservation. If the member accepts then delete the member node. If the member rejects the
reservation delete the member, insert him to the back of the queue and compare next member and
repeat. This process repeats until all members find their book
2.1. Write your own implementation of the queue by using a linked list for this problem
with all the queue operations. (LO 1.1)
2.2. Test the above application with a suitable test cases (LO 2.3)
Task 3
3.1 Implement Linear/Binary search using recursive algorithm and non-recursive algorithm,
and compare the performance. (LO 1.3)
HND in Computing & Systems Development
3.2. Sort the array given below with two different algorithms and compare the performance.
3.3. Explain common string operations such as concatenation, substring, etc., also state
their practical applications by giving suitable examples. (LO 3.1) (M1.3)
ACKNOWLEDGEMENT
I would like to offer my special gratitude to our Lecturer, Miss. Tharuka Sandamini who gave
me suggestions and encouragement as well as helped me in writing my project.
HND in Computing & Systems Development
Then, I would like to appreciate all those who gave me the great opportunity to make this
assignment on the topic Data Structures & Algorithms.
Further, I must express my deepest appreciation to the Mr.Damith Pathirana, the head of
Esoft Metro Campus who gave full effort in guiding to complete this project.
I must really remember our lecturer Miss.Tharika Amali, who gave me guidance to complete
this project.
At last, I would like to thank all the staff of Esoft Metro Campus who provided all the
facilities to complete this project. I would also like to thank my parents and my friends who
helped to finalize this project.
Contents
ACKNOWLEDGEMENT.........................................................................................................v
LIST OF FIGURES................................................................................................................viii
HND in Computing & Systems Development
LIST OF TABLES...................................................................................................................xii
Introduction.............................................................................................................................1
Data Structures....................................................................................................................1
Algorithms...........................................................................................................................1
Task 1.........................................................................................................................................2
A palindrome is a phrase that reads the same forwards as it does backwards. For example,
“DAD”,” MOM”,” madam” are examples for palindrome........................................................2
1.1. Write a program that figures out whether the given string is a palindrome. Use suitable
String operations to avoid white spaces and punctuation (LO3.2) (D3.4).................................2
1.2. Create an Example Stack class for this problem. Use Array List or an array to implement
the Stack, use suitable stack operations. (LO 2.1).....................................................................6
Stack Operations..................................................................................................................7
1.3. Identify and implement opportunities for error handling and reporting. (LO 2.2)...........19
Error Handling......................................................................................................................19
Exceptions Handling.........................................................................................................20
1.4. Prepare a user manual for the developed solution to assist the users to work with it. (M
3.1)...........................................................................................................................................27
Contents................................................................................................................................28
Introduction.......................................................................................................................28
Conclusion.........................................................................................................................35
Task 2.......................................................................................................................................37
2.1 Write your own implementation of the queue by using a linked list for this problem with
all the queue operations. (LO 1.1)............................................................................................37
HND in Computing & Systems Development
Queue Operations..............................................................................................................37
Login..................................................................................................................................51
Menu..................................................................................................................................54
Reservation........................................................................................................................57
Search................................................................................................................................60
2.2 Test the above application with a suitable test cases (LO 2.3)..........................................70
Introduction.......................................................................................................................71
Scope.................................................................................................................................74
Test Objectives..................................................................................................................74
Testing Procedure..............................................................................................................75
Test Case for Load All Reference No to the Drop down List...........................................79
Conclusion.........................................................................................................................87
Task 3.......................................................................................................................................88
HND in Computing & Systems Development
3.1 Implement Linear/Binary search using recursive algorithm and non-recursive algorithm,
and compare the performance. (LO 1.3).................................................................................88
Algorithm..............................................................................................................................88
Search Algorithms................................................................................................................88
Linear Search.....................................................................................................................88
Binary Search....................................................................................................................90
3.2. Sort the array given below with two different algorithms and compare the performance.
{12, 35, 30, 85, 69, 102, 99} (LO 1.2)....................................................................................97
Sorting Algorithms...............................................................................................................97
Sorting...............................................................................................................................97
3.3. Explain common string operations such as concatenation, substring, etc., also state their
practical applications by giving suitable examples. (LO 3.1) (M1.3)....................................109
String...................................................................................................................................109
String Operations................................................................................................................110
Concatenation..................................................................................................................110
Examples of Concatenation.............................................................................................110
Length..............................................................................................................................115
Examples of Length.........................................................................................................115
Substring..........................................................................................................................118
Examples of Substring.....................................................................................................118
Trim.................................................................................................................................121
Examples of Trim............................................................................................................122
CompareTo......................................................................................................................124
Examples of CompareTo.................................................................................................124
CONCLUSION......................................................................................................................126
HND in Computing & Systems Development
REFERENCES.......................................................................................................................128
APPENDIX............................................................................................................................133
LIST OF FIGURES
LIST OF TABLES
Task 01
HND in Computing & Systems Development
Introduction
Computers store, retrieve and process large amount of data. The data can be retrieved very
quickly for processing that further decreases the feature and the user is supplied fast response
if the data is stored in well-organized way on storage media and in computer’s memory.
Data Structures
A specific way of organizing data in a computer as it can be used efficiently is known as
Data Structure. It is about execution data elements according to some relationship for better
organization and storage. (Developerinsider, 2018) This data structures can be seen as a
logical concept that should give solution for two fundamental concerns such as how the data
will be stored and what operations will be performed on it. This is method of data schema.
And also, it should be independent of its implementation. ADT (Abstract Data Type) is
functional definition of a data structure that is independent of implementation. Examples of
several common data structures are arrays, linked lists, queues, stacks, binary trees, and hash
tables. There are two types of data structures such as Primitive Data Structures and Non-
primitive Data Structures.
Algorithms
A limited set of instructions or logic written in order to accomplish a certain predefined task
is known as an algorithm. It not a complete program or code. Algorithm is just the core
solution (logic) of a problem that can be expressed both as an informal high level explanation
as pseudo code or using a flowchart. (Studytonight, 2018)
Commonly, the algorithms are useful for searching for a specific data item and sorting the
data. And also, it is a step by step process of solving problems. The algorithms are
implemented in form of methods or functions or routines. The performance of the algorithms
are used to measure two basic properties such as,
Time Complexity
Space Complexity
Time Complexity is used to define the amount of time need by the program to run till its
completion. Normally, it is a better practice to try to keep the time required minimum.
Therefore, the algorithm completes its execution in the minimum time possible.
Space Complexity is the amount of memory space need by the algorithm in the sequence of
its execution. This can be taken for multi-user systems and in occasions where limited
memory is available.
HND in Computing & Systems Development
Task 1
A palindrome is a phrase that reads the same forwards as it does backwards. For
example, “DAD”,” MOM”,” madam” are examples for palindrome.
1.1. Write a program that figures out whether the given string is a palindrome. Use
suitable String operations to avoid white spaces and punctuation (LO3.2) (D3.4)
The author has implemented a Palindrome Application to check whether the any string is a
palindrome or not. The author has used Netbeans IDE to implement this application. And
also, Java Programming Language is used to implement this application. It can identify any
string is a palindrome or not by using this application. Below show the palindrome
application.
When entering a string, it shows that string is a palindrome or not as in the below. Below
figure shows the entering string is a palindrome.
The source code related to that application is shown in the below. It shows the code that is
written for the CHECK button.
In this application, when entering a string and press CHECK button, it shows the reverse of
that string. In the below code shows the code lines of that makes the reverse of string.
In here, the author has made the exception handling in this application. The author has avoid
the NullPointerException by using this code lines.
Below shows the code of CLEAR button. This code is used to clear inputs in the text fields.
1.2. Create an Example Stack class for this problem. Use Array List or an array to
implement the Stack, use suitable stack operations. (LO 2.1)
Stack Data Structure
Stack is simple data structure. It is an abstract data type with a predefined size. Stack can
adding and removing elements in a certain order. When an element is added to a stack, every
time it goes on the top of the stack and when removing also, it has to remove element form
the top. (Studytonight, 2018) Stack is behaved according to the LIFO principle. It means,
Last in First Out. There are two main functions in Stack data structure such as push function
and pop function. Push function is used to add new element in to the stack. Pop is used to
eliminate an element from the stack. Elements can be added and eliminated from the stack
only at the top. Therefore, a stack is a limited access data structure.
Stack Operations
Mainly, there are two operations allowed in the stack data structure.
1. Push Operation – Inserting an element in to the stack
2. Pop Operation – Eliminating an element from the stack
Push Operation
Pushing or storing an element to the stack. A new element is added at the top of the stack at
every time. It needs the item and no return value when pushing an element to the stack. When
inserting an element to the stack, it should be inserted from the top of the stack.
There are five steps are taken in to consideration in push operation.
1. Step 01 - Check whether the stack is full or not
2. Step 02 - Produces an error and exit, if the stack is full
3. Step 03 - Increments top to point next empty space, if the stack is not full
4. Step 04 - Insert an element to the stack location where top is pointing
5. Step 05 - Returns success
(Tutorialspoint, 2018)
Pop Operation
Removing or eliminating an element from the stack. First element is removed from the top of
the stack at every time. It needs no parameters and returns the item. When removing an
element from the stack, the stack is modified. When removing an element from the stack, it
should be removed from the top of the stack.
A pop operation can be consider in five steps such as,
1. Step 01 – Check whether the stack is empty
2. Step 02 – Produces an error and exit, if the stack is empty
3. Step 03 – Remove an element at which top is pointing, if the stack is not empty
4. Step 04 – Reduces the value of top by 1
5. Step 05 – Returns Success
(Tutorialspoint, 2018)
HND in Computing & Systems Development
Peek ()
In here, remove the top item from the stack but does not remove it. Only the copy of that
element is removed. It needs no parameters. The stack is not modified as it does not make a
change here. The algorithm of peek () function is shown in the below.
Begin procedure peek
Return stack [top];
End procedure
IsFull ()
In this function, it tests to see whether the stack is full. It needs no parameters and returns a
Boolean value (true or false). The algorithm is shown in the below.
Begin procedure isFull
If top equals to MAXSIZE;
Return true;
Else
Return false;
Endif
End procedure
IsEmpty ()
This checks to see whether the stack is empty. It needs no parameters and returns a Boolean
value. The algorithm is shown in the below.
Begin procedure isEmpty
If top less than 1;
Return true;
Else
Return false;
Endif
End procedure
HND in Computing & Systems Development
The author has used Stack class also to create this palindrome application that is used to
check the string is a palindrome or not using the Stack operations such as Push, Pop, and
IsEmpty.
In here, the author has first create a Stack class as below.
Then, this stack class call in the button of the palindrome application by making objects as
shown in the figure.
Then, stack operations such as Push, Pop and IsEmpty are called using object name.
However, palindrome application are performed using Stack class with Stack operations.
1.3. Identify and implement opportunities for error handling and reporting. (LO 2.2)
Error Handling
In Error handling, it mentions to the expectation, finding, and resolving errors of
programming, application, and communications. Some applications have presented
specialized programs, it means error handlers. It can recover the error when the error occur
without ending the application or gracefully end an affected application and then save the
error information to a log file. (Techtarget, 2018)
When developing systems and scripts, error handling is mostly important part. Appropriate
error handling is mostly essential for the software systems to reduce the number of errors in
the code.
Importance of Error Handling and Reporting
Error handling and reporting is very important to end users of the code. It makes very easier
for them to use the code correctly. And also, error handling makes easy to maintain the code.
Then, it will made easier to insert input specifications into the code. Therefore, the users
don’t have to look up the design when they write and later maintain the code.
The program will likely continue to function after an error, the customers can likely continue
working and it can supply a report of accurately how the bugs happened. Therefore, it can fix
the errors. If they handle their errors.
But, it does not handle the errors in the program, the program may crash. Therefore, error
handling is mostly important for programming.
Methods of Error Handling
Due to all the above things, there are some error handling method in programming. Some of
them are,
Exceptions Handling
Debugging
HND in Computing & Systems Development
Exceptions Handling
Exceptions
The mechanisms that used to reporting and handling errors, sudden or exceptional conditions
that can occur during the execution of an object’s methods are known as exceptions. The
code that discovers the error or condition “throws” an exception, when such a situation
occurs. The client of the code that threw the exception may “catch” the exception and handle
it or propagate the exception. Exception supply a method to change the program’s execution
path for times when unexpected behaviour occurs. (Dccc, 2018)
When a program is running, the process of responding to exceptions are known as exception
handling. It means, the errors that occurred in the run time of the program is called as an
exception. An exception happens, when an unexpected incident happens that requires special
processing. When a user giving irregular input or not giving an input, a system error being
met when trying to read or write a file. It means, the system gets stuck. Exception handling
tries to handle these conditions. It that occasions, it needs to give a considerable response to
the user. Therefore, the program does not crash/stuck.
Types of Exceptions
There are many exceptions that can occurred in a program. Some of them are,
Arithmetic Exception
ArrayIndexOutOfBound Exception
FileNotFound Exception
NullPointer Exception
(Study, 2018)
Arithmetic Exception
This can be occurred when an exceptional condition has occurred in an arithmetic operations.
Below shows the code of handling of arithmetic exception.
HND in Computing & Systems Development
ArrayIndexOutOfBound Exception
This exception can occur to show that an array has been retrieved with an illegal index. Either
the index is negative or greater than or equal to the size of the array.
Below figure shows program of handling Arrayindexoutofbound exception.
FileNotFound Exception
When a file is not accessible or does not open, this exception can be occurred.
Figure 23 - FileNotFoundException
(Geeksforgeeks, 2018)
NullPointer Exception
This exception is occurred when referring to the members of a null object. Null means empty.
Below shows a code for handling nullpointer exception.
Figure 24 - NullPointerException
(Geeksforgeeks, 2018)
Try-Catch Block
The throws
Try-Catch Block
The try-catch block is situated in the code that could be occurred an exception. The code
inside the try-catch block is denoted to as protected code. The try-catch block syntax is
shown in the below.
Try {
Code
Catch Block
}
It is placed in the try block that the code which is prone to exceptions. The exception that is
occurred when an exception occurs. Each and every try block is consists of either by a catch
block or finally block.
The catch includes stating the type of exception that is trying to catch. The catch block that
followed the try is tested if an exception occurs in the protected code. The exceptions is
passed to the catch block much as an argument is passed into a method parameter, if the type
of exception that occurred is listed in a catch block.
The author has used try-catch blocks in this application. Examples of try-catch block used in
this code is shown in the below.
HND in Computing & Systems Development
The throws
It can throw an exception, either a newly prepared one or an exception that just caught by
using the throws. Throw is used to appeal an exception clearly.
Figure 27 - Throws
(BeginnersBook, 2018)
Figure 28 – Throws
(Tutorialspoint, 2018)
According to this palindrome application, the author has handled NullPointer Exception. This
exception is occurred if the user clicks the CHECK button without entering an input. That is
the exception that can occurred in this application. Therefore, the author has handled this
exception properly. Below shows the source code of handling nullpointer exception.
1.4. Prepare a user manual for the developed solution to assist the users to work with it.
(M 3.1)
Contents
1. Introduction
What is a User Manual
Purpose of User Manual
2. Describing the System
3. Instructions for User
4. Conclusion
Introduction
User Manual
User Manual is a document that is written to help people understand a software application or
IT system. When writing a User Manual, use simple language with short sentences. This
simple writing style helps the user understand the application. By using this document, the
user can get clear understanding about the application. The User Manual includes all
information for the user about full use of the application. It contains a description of the
system functions and step by step procedures for system access and use.
In this Palindrome Application, the user can see below interface at first.
Then, the user has to enter the string that need to check for palindrome as in the below.
Then the user has to press CHECK button. After that the user can see whether that string is a
palindrome or not as in the below figure.
After pressing CHECK button, this shows the Reverse of the String in the field. And also, the
Result is shows in the field as in the below.
HND in Computing & Systems Development
Other than the Result showing in the field, the application gives the result from the message
dialog box also.
If the user has entered different strings, as in the below the application shows that string is not
a palindrome. The user can see this message from a message dialog box also. The result is
proved well as this message dialog box.
When the user entering a string consists of numbers, as the below it shows the results.
Numbers also falls under the strings.
If the user has pressed CHECK button without entering a string, a message will automatically
come as in the below by informing the message “Please Insert String Value”.
After finishing the checking for palindromes, the user can exit from the application. The user
can exit from the application by pressing Exit button as shown in the below.
Figure 36 - Exit
(Author, 2018)
Conclusion
In this document, it can get the clear understanding about the User Manual. It clearly shows
how to write a user Manual for usage of users. User Manual is very important and essential
document for users as they can get clear knowledge about the application and how it works.
In the earlier, the author does not has much enough knowledge about how to write a User
Manual. At present the author has better knowledge about the User Manual. User Manual
includes all the instructions essential for the user about use of the application. In here, it has
mentioned about how perform the Palindrome Application. In here, it has mentioned easily
understandable steps. However, this document is mostly important for the users who use this
Palindrome Application. Finally, it can conclude that the User Manual is a very essential to
HND in Computing & Systems Development
the user to get the idea about the application. The User Manual is definitely prepared for the
user after developing an application.
Task 02
HND in Computing & Systems Development
Task 2
2.1 Write your own implementation of the queue by using a linked list for this problem
with all the queue operations. (LO 1.1)
Queue Data Structure
Queue is a linear data structure or abstract data type. It is also like stack data structure. The
first element that is inserted from one end is known as Rear or Tail. The other end that the
removable of existing element takes place is known as Front or Head. This data structure is
behaved according to the FIFO (First in First Out) principle. It means, when the element is
inserted first, it will be removed first. (Studytonight, 2018) The queue data structure is also an
ordered list of elements with same data types. New element is inserted in to the rear of the
queue when inserting new element in to a queue. To remove an element from the queue, all
the elements before the removing element should be removed in the queue.
Figure 37 – Queue
(Studytonight, 2018)
Queue Operations
When considering the queues, there are basic queue operations can be identified.
1. Enqueue – Insert an item to the queue
HND in Computing & Systems Development
Begin
If queue isEmpty;
Return underflow;
Endif
Item = queue [front];
Front = front + 1;
Return true;
End
It can understand about the Enqueue and Dequeue operations using below figure.
There are some supportive functions of the queue as in the stack data structure. These
functions make the queue operations efficient.
Peek () – Take the item at the front of the queue without removing it. Only like a copy
of the item taken.
Algorithm is shown below for this function
Begin procedure peek
Return queue [front];
End procedure
Traversing
Traversing is the process of start with the head and access each node until reach null. It does
not change the head reference. (Cs.cmu, 2018) Simply this means, moving through node by
node sequentially. The main pattern of processing the data element of a node can be shown as
follows.
Start at the first node
Repeat until there are no more nodes
Process the existing node
Move to the next node
This pattern of process is the standard sequential processing. Links are involved in each step.
It need to use link variables to access every node in the data structure. As it moving every
node, update this link to keep up with the current place in the data structure.
This process can be mostly understand by using the below figure.
Figure 41 - Traversing
(Sqa, 2018)
Operations
Mainly, it can perform these functions using singly link list.
1. Insert
2. Delete
Insert
This insert operation is used to add new node to the link list. Insert can be happened in three
ways. (Tutorialride, 2018)
1. At the Start of the list
2. At the Middle position of the list
3. At the End of the list
At the Start of the list
HND in Computing & Systems Development
In here, to insert a new node to the start, it means to the head of the list, a new node need to
add head and the first data node. The steps are,
1. Form a new node using the data to be added.
2. Set new node to the first data node, the head is pointing.
3. Set head to the new node
Inserting a new node to begin of the list can be shown in below figure.
The following steps can be followed when adding a new node at the end of the link list.
1. Observe through the list until the final node is met.
2. Form a new node using the data to be added.
3. Set the new node’s next reference to null.
4. Set the end node’s next reference to the new node.
Using the below figure, it can understand the process of inserting a new node at he end of the
list.
Delete
Delete operation can be used to delete a node from the list. When considering the deleting a
node from the link list, according to the below figure find the required node and delete it from
the list.
In the below figure, it has deleted a node with X.
Operations
Mainly, it can identify two operations using doubly link list.
1. Insertion
2. Deletion
Insertion
In here, the insertion it means add node can be done in three ways.
1. Insert a node at the front
2. Insert a node after given node
3. Insert a node at the end
Insert a node at the front
In this process, a new node is inserted before the head of the link list. Then, newly inserted
node becomes the new head of the doubly link list. Then, call the push () function that adds a
node at the front of the list. Function push () must obtain a pointer to the head pointer since
push must change the head pointer to point to the new node.
Below figure shows a this process.
new_Node.prev = null;
4. Change prev of head node to new node
if (head! = null)
head.prev = new_Node;
5. Move the head to point to the new node
head = new_Node;
}
It needs two steps extra to change previous pointer of new node and previous pointer of new
node’s next node.
public void InsertAfter (Node prev_Node, int new_data)
{
1. Check if the given prev_node is NULL
if (prev_Node == null) {
System.out.println ("The given previous node cannot be NULL ");
return;
}
2. Allocate node
HND in Computing & Systems Development
It has represented a code of deletion of a node at the beginning of a doubly linked list.
Login
Below shows an interface of login. It can login to the system using this interface.
Figure 53 – Login
(Author, 2018)
This system is run from the below code. It means, it starts run the system from the main
method.
HND in Computing & Systems Development
If it has
By entering correct username and password, welcome message can be seen as in the below.
HND in Computing & Systems Development
Menu
It can enter to the Menu page by successful login.
Figure 58 – Menu
(Author, 2018)
HND in Computing & Systems Development
In this interface, it can perform functions related to the library. It can perform Book
Reservation and Search Book as in the below figure.
Unlike the other system, this system is implemented using MDI form concept. Then, it can
perform several functions at once. MDI method means, it can open several interfaces and
perform the task as in the below.
Reservation
This interface used to make book reservation. Member can reserve book using this. In here,
load the Reference No in the drop down list automatically. Then, it can select Reference No
using this list. After that, it fills the Member ID field automatically related to that Reference
No. The reason is when implementing the system, it has inserted book details through
keyboard. Then, that details automatically filled. By pressing Reserve button, it can reserve a
book successfully as in the below. Successful message also comes.
Below shows the code lines of reservation function. It has used integer type variables to store
Reference No and Member ID. Then, takes values from the fields and call to the Enqueue
method by making objects related to the Enqueue method in this class as in the code.
According to this system, all the Reference No are load to the drop down list. Due to this
code, this process is happened. Switch case control structure is used to perform this process
as in the figure. According to this, when selecting the Reference No from the Drop down list,
the Member ID is fills automatically in the field related to that Reference No.
HND in Computing & Systems Development
In the below, it has shown object that create in the reservation class to join with Queue class.
(Author, 2018)
If it will pressed Yes, show message again as in the figure.
If it is given Yes, reservation can be accessed. Message is shown in the figure.
(Author, 2018)
HND in Computing & Systems Development
There is no response from the member, the reservation will cancelled as in the below.
Figure 70 - Search Function
(Author, 2018)
Search is happened using Reference No. Details are get from the earlier made New_Object. If
it happen a reservation, the Enqueue details are Dequeue from the list. Message dialogue
boxes are used for show this process.
Mainly, this system performs according to the implementing this Queue Class. Whole process
is happened according to this class. Inside this class. It has includes all the methods such as
inserting and deleting details from the list. It means like Enqueue, Dequeue functions and
same as insert, delete functions using linked list.
Below shows the Enqueue function and variable declaration for head, front and rear.
QueueNode class is shown in the below. Integer type variables are defined in here and made
these as public so as to use these variables in any method.
2.2 Test the above application with a suitable test cases (LO 2.3)
TEST PLAN
FOR THE
“READ WITH US”
LIBRARY SYSTEM
Introduction
“Read with Us” Library System can use to reserve book to their members. In here, this
system performs a waiting list or book or other reading material allocation. A member is
contacted through email or SMS and informed if the possible match between reservation and
the book is found. Author has used Queue Data Structure with Linked list to develop this
system. Author has used test plan to test this system.
System Testing
Testing of a complete and fully integrated software product is the System Testing. Generally,
software is only one element of a larger computer based system. This testing is really a series
of different tests whose single purpose is to exercise the full computer based system.
(guru99, 2018)
HND in Computing & Systems Development
(Tutorialspoint, 2018)
Skilled testers are required to perform white box testing, the cost is increased
Specialized tools are needed such as code analyser and debugging tools
It needs specialized tools like code analyser and debugging tools for white box
testing. Therefore, it is difficult to maintain white box testing
(Tutorialspoint, 2018)
Scope
In here, this system performs a waiting list or book or other reading material allocation. A
member is contacted through email or SMS and informed if the possible match between
reservation and the book is found. Before hand over the output to the user, the testing should
be done to the whole system.
Author has created different test cases to system testing. In here, the author has check the
actual results and expected results and compare both results. By using sample data, the author
has checked whether actual results has been come or not. The author has tested whether all
records are deal with system properly or not.
Test Objectives
System test expects to verify all the functions are performed properly. System testing make
sure that all the user requirements are meet. It is very useful to find errors and minimize
them. System test is used to find incorrect and missing function. It shows the errors in code
also. It is easy to identify performance errors also using system testing. System tests expects
confidence in and supplying information about the level of quality.
Testing Procedure
In here, author has gave the system to test others as the testing procedure. Author has selected
some persons and test the system. Then the author can identify all errors in the system. And
also, the user can identify the efficiency, performance, speed, accuracy and all other things in
the system by this testing procedure.
Input Status
Test Case Expected Results Actual Results
Data (Pass/Fail)
2. Password
123
Data (Pass/Fail)
12456
Menu
Show
1. Press Reservation Reservation and Show Reservation
Pass
2. Press Search Search and Search Interfaces
Table 4 - Test Case for Invalid Login
Interfaces
(Author, 2018)
HND in Computing & Systems Development
Test Case for Load All Reference No to the Drop down List
Test Case: 04
Test Case Name: Load All Reference No to the Drop down List
Input Status
Test Case Expected Results Actual Results
Data (Pass/Fail)
According to above case, the author has prepared this function to show all the Reference
Numbers in the drop down list when click on the Combo Box. But, when testing the system it
has not worked properly as in the above. The author has prepared this issue by making
changes to the source code. Finally, this function is worked properly as in the below figure.
The author would be able to identify this problem due to the testing the system. The author
could be able to understand the importance of the system testing due to this problem.
Input Status
Test Case Expected Results Actual Results
Data (Pass/Fail)
Input Status
Test Case Expected Results Actual Results
Data (Pass/Fail)
Status
Test Case Input Data Expected Results Actual Results
(Pass/Fail)
Pass
Conclusion
The author has tested interfaces in this system properly. In here, the author can be able to
identify how to make a test case for the testing a system. It can be able to identify if there is
any error in the system. By testing the system, it can give proper output to the user. It means,
user can get quality system to perform their tasks easily. When testing these things, the author
can get practical knowledge and the clear idea about how to testing a system and what are the
errors can occur during development of this system.
Table 9 - Test Case for Exit In most of test cases, both expected result and the actual result
are matched successfully. It means it can conclude that there is
(Author, 2018)
no considerable error in the system. But, in some cases one of
the test case found with Fail. Then, the author has fixed it by changing the source code and
making interfaces suitably.
Furthermore, the author has got better experience about the system testing. However, in the
above most of test cases, both expected result and the actual result are matched successfully.
Some issues are solved properly. Finally, it can conclude that there are no considerable errors
in the functions that have tested in the above.
HND in Computing & Systems Development
Task 3
that used to find the real place of a given element or value in the list. There are some
searching techniques are used in the data structure. These standard techniques are,
1. Linear Search
2. Binary Search
Linear Search
The basic search algorithm used in data structure is Linear Search. It’s also known as
Sequential Search. This linear search is used to find a specific element in an array. It is not
need to arrange the array in ascending or descending order compulsory. (Codeburst, 2018)
Linear Search is mostly used for short lists since this algorithm is simple and need minimum
code to implement.
In a list, the best case is when the value is equal to the first element of the list, in which case
only one comparison is needed. The poorest case is when the value is not in the list or occurs
only once at the end of the list, in which number of elements in the list comparisons are
needed.
As an example, it can consider following list of element. In here the Search element is 33.
Both elements are not matching. Therefore, check the next element. Likewise, move near to
the elements and check those elements are matched with the search element.
Finally, search element 33 is matched with an element 33 in the list. Therefore, stop
comparing and display element as the output.
Binary Search
Very efficient and the fast searching techniques is the Binary Search. It compulsory need the
list to be in sorted order in the Binary Search. (W3schools, 2018) It can compare the element
with the present element at the center of the list when searching an element. The search is
success, if the element is matches. Otherwise, the element list is divided in to two parts. One
part is zero to the middle element. Other part from middle element to the last element. This
binary search is continues from either of the two parts depending upon whether the required
element is smaller or greater than the central than the middle element. Searching is done in
the first part, if the element is smaller than the middle element. Otherwise, searching is done
in the second part.
As an example, it can consider following array. The array should be sorted in the binary
search. In here, Search element is 23.
2 5 8 12 16 23 38 56 72 91
Then, it has to find the mid value first. According to this example, the mid value is the 16. If
the value of the search element is less than mid value, it narrow the lower half of the array.
HND in Computing & Systems Development
Otherwise, it narrow the upper half of the array. This process is happened repeatedly until the
value is found as in the below figure.
23 is higher than 16. Therefore, this narrows upper half of the array.
Lower Upper
2 5 8 12 16 23 38 56 72 91
0 1 2 3 4 5 6 7 8 9
23 is lesser than 56. Therefore, this narrows lower half.
Lower Upper
2 5 8 12 16 23 38 56 72 91
0 1 2 3 4 5 6 7 8 9
Lower Upper
02 15 28 12
3 16
4 23
5 38
6 56
7 72
8 91
9
Normally, recursive means that a function calls itself. This may not be planned. Planned
recursion, where a function performs part of an operation, then calls itself to perform the
remaining part, is often a useful programming paradigm. Mainly, recursion can be used to
replace "repetition" (loops) and to replace associated array allocations (with variables local to
the function body). But not each iterative or array-using function can be effectively converted
to its recursive equivalent.
It can often write a recursive version that is about equivalent in execution efficiency to the
non-recursive version, maybe slightly better or worse depending on how efficient the call
mechanism is compared to looping and array indexing in the language/compiler, if the
problem is suitable for recursion In terms of storage, recursion is rarely more efficient, but it
benefits from not having to pre-allocate (and pre-know the size of the allocation) for the
particular problem at hand.
Mostly recursion is better than non-recursive (when it actually is) because it makes an
implementation much simpler and less error-prone, and errors are by far the biggest cost in
computing. (And of course improperly done it can cost you big time as well.)
By considering above few facts, it can conclude that the recursive algorithm is better than
non-recursive algorithm.
HND in Computing & Systems Development
3.2. Sort the array given below with two different algorithms and compare the
performance. {12, 35, 30, 85, 69, 102, 99} (LO 1.2)
Sorting Algorithms
Sorting
Sorting is an arrangement of data in a particular format. Sorting algorithms state the way of
arranging in a particular order. Order can be taken as ascending or descending order. Sorting
is very useful to show data in a more readable formats. (Tutorialspoint, 2018)
In the real life, it need to search for many things such as records in database, telephone
numbers in telephone directory, particular pages in a book and more. These things get
difficult, if the data was kept unsorted or unordered way. Sorting concept came into existence
fortunately. It makes easy to arrange data in an order. Therefore, it makes easy to search data.
Data is arrange in an order in sorting that makes easier to search. There are different
algorithms to sort data.
Different Sorting Algorithms
Different techniques can be seen for sorting. These techniques are different from their
efficiency and space requirements. Some of the sorting techniques are,
1. Insertion Sort
2. Bubble Sort
3. Selection Sort
4. Quick Sort
Insertion Sort
This is a simple sorting algorithm. It makes the final sorted array one element at a time.
Insertion sort is less efficient on large lists than other sort algorithms. (Java2novice, 2018)
Insertion sort is efficient for smaller data sets. It can follow following steps in insertion sort.
First element is already sorted. It returns 1.
It can start by making the second element of the given array, element at index 1, the
key.
Compare the key element with the element before it, in this case, element at index 0.
Insert the key element before the first element, if the key element is less than the first
element. And insert it after the first element, if the key element is greater than the first
element.
Then, it takes third element of the array as key and it will compare with elements and
insert it at the correct position.
HND in Computing & Systems Development
Bubble Sort
Bubble sort is also a simple algorithm that compares the first element of the array to the next
one. The elements are swapped, if the current element of the array is numerically greater than
the next one. This process will happen repeatedly through the entire elements of the array.
(Guru99, 2018)
If any array need to be sorted in ascending order, bubble sort will start by comparing the first
element of the array with the second element. Both elements are swap, if the first element is
greater than the second element. Then take second and third elements and compare. Proceed
this process until the array is sorted.
Overall, the sorting is happened by stepping through all the elements one-by-one and
compare it with the nearby element and swapping them if necessary.
When considering the below array, it can sort by using bubble sort.
40 20 60 10 50 30
Above array can be sort using bubble sort as in the below steps.
In the bubble sort, compare nearby elements and swap them if they are out of order. In each
situation, largest element will be moved as its suitable place.
In the above array, firstly 20 and 40 compared. Check 40>20. Condition is true. Therefore, 40
and 20 will be swapped. Then, 40 and 60 will be compared, check 40>60. Condition is false.
Therefore, not need to swap and go ahead.
Then, 60 and 10 will be compared, check 60>10. Condition is true. Therefore, 60 and 10 will
be swapped.
HND in Computing & Systems Development
Then, 60 and 30 will be compared, check 60>30. Condition is true. Therefore, 60 and 30 will
be swapped and largest element 60 bubbled up at its suitable place.
Repeat the steps for remaining unsorted sub array and every situation through the array places
the next largest value in its suitable place.
(Javabypatel, 2018)
HND in Computing & Systems Development
Selection Sort
In the Selection sort, it sorts an array by repeatedly finding the smallest element (considering
ascending order) from unsorted part and placing it at the beginning. (Geeksforgeeks, 2018) In
this sorting technique, the algorithm contains two sub arrays in a given array.
1. Already sorted sub array
2. Unsorted remaining sub array
In the selection sort, the smallest element (considering ascending order) from the unsorted
sub array is picked and moved to the sorted sub array.
It can understand the selection sort by using below example.
It can consider below array.
arr [] = 63 24 13 23 10
First, find the smallest element in arr [0...4] and place it at beginning
10 24 13 23 63
And, find smallest element in arr [1…4] and place it at beginning of arr [1…4]
10 13 24 23 63
Find smallest element in arr [2…4] and place it at beginning of arr [2…4]
10 13 23 24 63
Find smallest element in arr [3…4] and place it at beginning of arr [3…4]
10 13 23 24 63
It can consider about a program that is written to sort an array using selection sort.
Quick Sort
Quick sort is widely used sorting algorithm technique. It is based on Divide and Conquer
concept. In this sort, every heavy work is done while dividing the array into sub arrays. This
sort is known Partion-exchange sort also. (Studytonight, 2018)
Some steps have to follow in the quick sort.
An element is selected from a given array. This selected element is named as “Pivot
Element”. As an example, select the middle element of the array.
Then, place all the elements which are smaller than the pivot element in one array and
larger all elements placed in another array.
Then, apply quick sort to them and sort both arrays.
Finally, combine sorted arrays.
Using below figure, it can get clear idea about the quick sort.
The author has sort this array {12, 25, 30, 85, 69, 102, 99} using Insertion Sort and Bubble
Sort.
Implementation of Insertion Sort Algorithm to Sort the Array {12, 25, 30, 85, 69, 102,
99}
HND in Computing & Systems Development
The author has sort the above array using insertion sort algorithm. It has shown the algorithm
that is used to sort above array in the below.
Implementation of Bubble Sort Algorithm to Sort the Array {12, 25, 30, 85, 69, 102, 99}
HND in Computing & Systems Development
The author has sort above array using bubble sort algorithm also. In the below shows the
algorithm.
3.3. Explain common string operations such as concatenation, substring, etc., also state
their practical applications by giving suitable examples. (LO 3.1) (M1.3)
String
String is an object that represents a series of characters. (Eureka, 2018) Mainly, String is an
array of characters. There some syntax example of String shown in the below.
Syntax that represented as String is an array of characters.
String Operations
String operations allow to perform different manipulations on a String. It can identify various
String Operations. Some of them are,
1. Concatenation
2. Length
3. Substring
4. Trim
5. CompareTo
Concatenation
Simply, concatenation is combining of two or more Strings together. Joins a string to the end
of another string. Finally, returns a combined string. (Edureka, 2018) Concatenate string act
as a new another string. It can concat string in two ways such as by + operator and by concat
() method.
HND in Computing & Systems Development
Examples of Concatenation
By using + operator, it can add strings. It means concat strings. Concatenation operator (+)
can concat both string and primitive values. As an example,
Example 01:
By using concat () method, it can concat strings. In this method, concat the specified string to
the end of existing string.
HND in Computing & Systems Development
Example 02:
Output: welcomeback
Example 03:
When comparing with Example 02, it can clearly see the concatenating multiple strings can
be done in one line also as in the Example 03. It reduces the number of lines of the program.
It is easily write using few lines.
Example 04:
Below example is used to concat spaces and special symbols. It means, it makes the space
among strings when concatenating the strings.
It can use this string operations practically. The author has create some simple applications to
show how these operations are performed.
HND in Computing & Systems Development
Below shows an application that is created to show the Concatenation and Length string
operations. In here, according to this application when entering two different string values
and pressing the Concatenation button, the result string is shown in the message box as in the
below figure by concatenating these two entering values.
The source code for the above application is shown in the below.
Length
To returns a length of a String, it can use String length () method. Length of any string is
equal to the number of 16-bit Unicode characters in the String.
HND in Computing & Systems Development
Examples of Length
Example 01:
According to above example, Str1, Str2 are String objects that declare in the program. Length
() method is returns a length of Str1 and Str2. Therefore, 29 is the length of String “Welcome
to Tutorialspoint.com” and 9 is the length of String “Tutorials”.
Example 02:
When comparing this example with the example 01, this is different. In here, it consider
about the condition also. String variable is declared and assign it to a value. Then, check
string is empty or not. It means, the length is greater than 0. If it is, print the length.
Otherwise, check the value is equal to 0. If it is, print output as 0. It means, the length is 0.
HND in Computing & Systems Development
This operation is also can be used as a practically as in the below application. Same as the
concatenation, in here by entering string value and pressing the button, it can obtain the
length of the string as the result in the message dialog box.
HND in Computing & Systems Development
Substring
This is used to get a substring of a particular String. (BeginnersBook, 2018) Substring ()
method has two forms.
1. String substring (int beginIndex)
HND in Computing & Systems Development
In
Example 02:
The author has created an application to show the practical situation of using substring
operation as in the below. It has already mentioned what is substring operation about. Using
below it can understand, how this operation used practically. By entering string value and
begin index as the value field, the result can be taken by pressing Result button.
HND in Computing & Systems Development
Trim
This is used to take a string which value is this string, with any leading and irregular
whitespace removed. If a string object denotes an empty character order or the first and last
characters of character arrangement denoted by this string object both have codes greater than
'\u0020' (the space character), then a mention to this string object is returned.
Then, a string object denoting an empty string is returned, if there are no characters with a
code greater than '\u0020' in the string. (W3resource, 2018)
HND in Computing & Systems Development
In simply, in the trim it checks the Unicode value of space character (‘\u0020’) before and
after the string. If the value exists, then removes the spaces and return the omitted string.
Examples of Trim
Example 01:
In here, it removes the spaces and return and print the omitted string as in the below figure.
Example 02:
Below example is somewhat different than above one. In here, removes all the trailing spaces
as well as the length of string also reduces.
Output: 22
hello java string
17
hello java string
Below application shows how it perform in the trim sting operation in practically. By
entering string value and press Result button, it can get the result of the string. The author has
explained about the trim string operation earlier. Therefore, it can understand what happened
in this application.
HND in Computing & Systems Development
CompareTo
According to this operation, it compares current string with a given string. Then returns a
positive number, negative number or 0. This compares strings on the beginning of Unicode
value of every character in the strings. (Javatpoint, 2018)
HND in Computing & Systems Development
In here, it returns positive number (difference of character value), if the first string is greater
than second string. And also, it returns negative number, if first string is less than second
string. First string is equal to second string, it returns 0.
Examples of CompareTo
Example 01:
According to below example, it has considered about three strings and comparing them each
other by using CompareTo () method.
Example 02:
HND in Computing & Systems Development
This example is different from above example. It means, it has considered about empty string
also when comparing. If anyone compares string with empty string, it returns a length of the
string. The result will be positive, if the second string is empty. And also, the result will be
negative, if the first string is empty.
CONCLUSION
This study is based on Data Structures and Algorithms. In this case, the author has
implemented a palindrome application. In the earlier, the author does not has a clear idea
HND in Computing & Systems Development
about a palindrome application. But, when developing this application the author could be
able to get clear knowledge about the palindrome application. The author has used both in
build class in the java and create stack class with stack operations. Therefore, it could be able
to get well experience of using stack operations. The author has given attention for the error
handling also when developing this application. It has handled the null pointer exception in
this application. In here, author has study about types of exceptions and methods of handling
exceptions. Practically, the author has used try catch block to handle exceptions. Not only
that, the author has prepared user manual for this application. It helps to the user to
understand how to use this application.
According to this study, the author has to implement a Library System using queue and
linked list data structures. Mainly, this system provides a book reservation facility for
members. In this case, queue operations and linked list operations are used. Queue and linked
list operations are used to create functions and classes of this system. The author could be
able to get clear knowledge about queue and linked list data structures. After implementing
the system, the author has tested this system separately. By using the testing, the author can
understand what are the errors can occur in the system and how to fix them. It has get good
practical experience about the system that was made from data structures. The author has
realized that the testing is important and essential thing when implementing a system. When
testing the system, the author has get some fail test cases also. It was a mistake of the author.
As an example, in this system, it has not loading the data when clicking. It was an issue
identified by the testing. The author has prepared this issue by making changes to the source
code. Then, this function works properly.
In here, the author has implement a binary search using recursive and non-recursive
algorithms. The author has made a study about searching algorithms. It means linear search
algorithms and binary search algorithms. And the author has compare performance of these
algorithms. Not only that, the author has get clear knowledge about sorting algorithms also
using this study. It has study different soring algorithms such as insertion sort, bubble sort,
selection sort and quick sort and compare performance of some of those algorithms.
Finally, in this study, the author could be able to study about common string operations such
as concatenation, length, substring, trim, compareto. The author shows examples for these
operations by making practical applications. The author has suggest some improvements to
these application such as palindrome application and library system. It can suggest to
improve the palindrome application as to get the longest palindrome string among set of
HND in Computing & Systems Development
palindrome strings. It means, by entering set of palindrome strings, it will able to show what
the longest palindrome word as the output. Not only that, it can suggest to improve this
application as to see whether the numbers are palindrome or not. In here, it does not checks
strings. It has only check the palindrome numbers. For the library system, it can suggest to
improve other function as View member. It means, it can see all the members who making
reservation in table. It can get members enters to the queue when reserving a book. By
improving the above improvements, the author can improve this system much more effective
and high performance in the future.
REFERENCES
Beginnersbook.com (2018) java string compareto method example [online]. Available at:
https://beginnersbook.com/2013/12/java-string-compareto-method-example/ [Accessed on
04th of December 2018]
Beginnersbook.com (2018) java string concat method example [online]. Available at:
https://beginnersbook.com/2013/12/java-string-concat-method-example/ [Accessed on 04th of
December 2018
Beginnersbook.com (2018) java string substring method example [online]. Available at:
https://beginnersbook.com/2013/12/java-string-substring-method-example/ [Accessed on 04th
of December 2018]
Beginnersbook.com (2018) java throws [online]. Available at:
https://beginnersbook.com/2013/04/java-throws/ [Accessed on 09th of November 2018]
Codeburst.io (2018) searching and sorting algorithms [online]. Available at:
https://codeburst.io/algorithms-i-searching-and-sorting-algorithms-56497dbaef20 [Accessed
on 28th of November 2018]
Cs.cmu.edu (2018) linked list [online]. Available at: https://www.cs.cmu.edu/~adamchik/15-
121/lectures/Linked%20Lists/linked%20lists.html [Accessed on 15th of November 2018]
Cs-fundamentals.com (2018) what is an algorithm [online]. Available at: http://cs-
fundamentals.com/tech-interview/dsa/what-is-an-algorithm.php [Accessed on 28th of
November 2018]
Dccc.edu (2018) exception handling [online]. Available at:
https://www.dccc.edu/sites/default/files/faculty/william_manley/exception-handling.pdf
[Accessed on 09th of November 2018]
Developerinsider.co (2018) introduction to data structures and algorithms [online].
Available at: https://developerinsider.co/introduction-to-data-structures-and-algorithms/
[Accessed on 04th of November 2018]
Edureka.co (2018) java string [online]. Available at: https://www.edureka.co/blog/java-
string/ [Accessed on 04th of December 2018]
Edureka.co (2018) java string [online]. Available at: https://www.edureka.co/blog/java-
string/ [Accessed on 04th of December 2018]
Edureka.co (2018) java strings [online]. Available at: https://www.edureka.co/blog/java-
string/ [Accessed on 04th of December 2018]
Geeksforgeeks.org (2018) linked list [online]. Available at:
https://www.geeksforgeeks.org/data-structures/linked-list/ [Accessed on 14th of November
2018]
HND in Computing & Systems Development
APPENDIX
HND in Computing & Systems Development
Date : 26/12/2018
Signature : tharukawijetunga@gmail.com
Comments:
Assessment Criteria (Students are not authorized to modify or write anything on below)
Possible
Outcomes/Criteria for PASS Page Feedback
evidence
LO1 Understand data structures and algorithms
1.1 produce design specification for data structures Task 1.1, Task 2-5 Learner has produced design specification for data structures
explaining the valid operations that can be carried out 2.1 37-69 explaining the valid operations that can be carried out
on the structures on the structures
1.2 explain the operation and performance of sorting and Task 3.1, Task 88-96 Learner has implemented the binary search using recursive and non-recursive
search algorithms 3.2 97-108 algorithms and has compared the performance. Also learner has done a good
research on the topic. Learner has identified the situations where recursion is
used.
1.3 explain the operation of recursive algorithms and Task 3.2 97-108 Learner has implemented the binary search using recursive and non-recursive
identify situations when recursion is used algorithms and has compared the performance.
2.3 test results to enable comparison with expected results Task 1.4,Task 27-35 Learner has defined several test cases to compare the expected result and the
2.2 70-87 actual result.
M1.3 an effective approach to study and research has been Compare different algorithms for searching and sorting
Applied searching and sorting Also learner has Searched about different string
Search about different string operations
operations
Learner has done a sufficient research on different data structures and their
operations.