COL-A-056062 DSA COM73 FMSuhail
COL-A-056062 DSA COM73 FMSuhail
COL-A-056062 DSA COM73 FMSuhail
Herewith I agree for the given terms and conditions on plagiarism & Academic dishonesty also
I declare the work submitted doesn’t breach these regulation.
Note: Keep the softcopy of the assignment with you until the official results released by ESOFT. ESOFT has all rights
to request the softcopy again at any time.
_______________________ ________________________
Signature Date
Assignment Brief
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.
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)
For example:
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
Unit No: 34
Comments:
Assessor Name :
Date :
Signature :
Assessment Criteria
Possible
Outcomes/Criteria for PASS Page Feedback
evidence
LO1 Understand data structures and algorithms
1.1 produce design Task 2.1
specification for data
structures
explaining the valid
operations that can be carried
out on the structures
1.2 explain the operation and Task 3.2
performance of sorting and
search algorithms
1.3 explain the operation of Task 3.1
recursive algorithms and
identify situations when
recursion is used
Strengths: Weaknesses:
Assessor: Signature:
Date: ____/____/______
Internal Verifier’s Comments:
Initially, I would like to thank my parents for their valuable contributions for their morally,
financially towards the completion of this project. I am also grateful to appreciate my lecturer
at ESOFT Computer Studies (Pvt.) Ltd, Colombo, Mr. Siva raam who was guiding me with
his kindness and patience throughout the assignment, without his help and kind guidance this
project would not have been completed.
Thank you!
-FM Suhail-
3.1 Implement Linear/Binary search using recursive algorithm and non-recursive algorithm,
and compare the performance. ............................................................................................. 14
3.2 Sort the array given below with two different algorithms and compare the performance.
{12, 35, 30, 85, 69, 102, 99} ................................................................................................ 18
Conclusion ................................................................................................................................. 0
Appendix .................................................................................................................................... 2
References .................................................................................................................................. 2
By using charAt() :
By using StringBuilder
By using substring
Figure 4 : DAD
Figure 5 : DADY
Figure 7 : MADAM
Figure 8 : MADAMM
Stack error
Please
Insert enter A
wrong or B
Success
input for otherwise
1st search it’s not
work
Getting
reference
number
Book
and Success
order
success
message
of order
Sorry,
Wrong the book
Success
book ask is not in
stock
Please
check
Wrong ID
your Success
input
member
ID
Enter A
for
Accepting
accepting Success
order
R for
rejecting
Linear search is a way for finding a goal fee inside a listing. It sequentially exams every element
of the list for the target value until an in shape is determined or until all of the elements had
been searched. Linear search runs in at worst linear time and makes at maximum n
comparisons, in which n is the length of the list. If every detail is equally likely to be searched,
then linear seek has a median case of n/2 comparisons, but the common case may be affected
if the search chances for every element range. Linear search is hardly ever practical because
Linear search is generally quite simple to enforce, and is realistic whilst the listing has only
some factors, or when performing a single search in an unordered list. Whilst many values
ought to be searched in the same list, it often will pay to pre-procedure the listing so as to use
a faster technique. As an example, one can also sort the list and use binary search, or build an
efficient search data structure from it need to the content of the list change often, repeated re-
organisation may be more trouble than it's far well worth.
As an end result, despite the fact that in principle other search algorithms can be quicker than
linear search (as an instance binary search), in practice even on medium-sized arrays (round
100 items or much less) it is probably infeasible to apply something else. On larger arrays, it
only makes experience to apply different, quicker search techniques if the data is huge
sufficient, because the preliminary time to prepare (sort) the facts is corresponding to many
linear searches
Binary search is a search algorithm that finds the placement of a target value inside a sorted
array. Binary search compares the target value to the middle element of the array. If they're no
longer equal, the 1/2 wherein the target cannot lie is eliminated and the search continues at the
closing 1/2, once more taking the middle element to compare to the target value, and repeating
this till the target value is determined. If the search ends with the remaining 1/2 being empty,
the target isn't always in the array. Despite the fact that the idea is easy, implementing binary
search effectively requires attention to a few subtleties about its exit conditions and midpoint
calculation.
Binary search runs in logarithmic time within the worst case, making O (log n) comparisons,
in which n is the number of elements within the array, the O is large O notation, and log is the
logarithm. Binary search takes consistent (O(1)) space, which means that the distance taken by
the algorithm is the same for any range of factors within the array.[6] Binary search is quicker
than linear search except for small arrays, but the array need to be sorted first. Even though
Binary search works on sorted arrays. Binary search starts off evolved with the aid of evaluating
the middle element of the array with the target value. If the target price matches the middle
element, its position in the array is again. If the target value is less than the middle detail, the
search keeps inside the lower 1/2 of the array. If the target value is greater than the middle
element, the search keeps inside the top 1/2 of the array by way of doing this, the algorithm
eliminates the 1/2 wherein the goal cost cannot lie in each generation.
BASIS FOR
LINEAR SEARCH BINARY SEARCH
COMPARISON
Merge sort is a recursive partitioning sort that divides, sorts and reassembles an array
into n/2 parts, and does a comparison on two items, sorts them and returns the result up the
recursion tree. It cannot skip over any already-sorted sections. It has good timing characteristics
Insertion Sort is an in-place sort that places items in their proper order one by one and
can skip over already-sorted areas. It needs n-1 passes and up to n*(n-1) comparisons to find
the right spot, but the average is (n/2) + 1 comparisons per item. Each pass gets faster as the
array gets more in sorted order, as less rearrangement needs to be done. The algorithm is simple
to implement and usually consists of two loops; an outer loop to pick items and an inner loop
to iterate through the array. This leads to a worse case of n2n2 time which is bad for huge data
sets, but on the other hand the code is simple and can run very fast on modern CPUs with cache.
Insertion sort is not as easily paralleled because each item has to be compared with potentially
all the other items. Small data sets can be sorted entirely in-cache, however.
The difference between O (n^2) average and O (NLogN) constant. However Merge
Sort is not adaptive like Insertion Sort, meaning for nearly sorted lists, Insertion Sort beats
Merge Sort. Insertion Sort is also an in-place algorithm and ideal for low memory and nearly
sorted. Insertion Sort is good enough to be used in its binary modification for Tim Sort. So
each has its advantages and disadvantages. For large unordered, go with Merge Sort. For
smaller arrays or ranges, Insertion Sort is fine.
Some quite impressive optimizations have been achieved by beginning a sort with
merge sort and when each partition reaches a small enough threshold, switching to insertions
sort because it is fast on small data sets and beats merge sort once the array is nearly sorted.
The Substring method takes 2 arguments in integer format to identify where it should
start the separation and where it should end. The Substring method does not accept the string
itself as an argument, therefore the string object is required to perform the operation rather than
the string text. The first 3 lines of code in figure 27 demonstrates the use of the Substring
method in C# language. One practical application of this method is that certain phrases from a
user’s input could be extracted to form a more relative output based on the input.
Figure 22 : Sub-String
Concatenation is the process of merging two data literals into a single literal. Concatenation
is not limited to string literals and could be used in any other data type such as binary, integer,
and floating point characters and Boolean. However, concatenation find its syntax to be
different across languages (Techopedia 2016). The application of concatenation for string
literals in the Java programming language is discussed below. Even in the Java programming
language itself, there are various approaches for concatenation of string values. Each approach
has their effects on performance and efficiency of the code. The easiest way to achieve
concatenation of strings in java is to simply merge 2 strings using the operator ‘+’ as shown
in the image below.
Figure 23 : Concatenation
The string trim method in java language is used to eliminate leading and trailing white
spaces from a string. It uses the Unicode value of space which is ‘\u0020’ to check whether
a given String contains such a Unicode at the beginning or the end, so this method cannot
omit middle spaces in the string (Java T Point 2014). A possible use of this method includes
validating user inputs where the user might have accidentally typed in white spaces at
the beginning or the end of the input. In such a case, the absence of omission of middle
spaces in the trim method comes as an advantage, because the input from the user is not
altered while validating. The image below shows how this method is being used in the
java language.
Figure 24 : Trim
In the beginning of this document at Task 1, a program for figuring out whether certain
strings are palindromes is developed. It uses many techniques and methods for
string processing to process the input strings to validate them, for instance removal of white
spaces and punctuation marks from the input string is practiced. This program uses an array
based stack to reverse the string to check whether the reversed output matches the processed
input. This method could be improved in the future where the array based stack could be
replaced with a linked list. However, a program that uses a linked list is developed for the
task 2 based scenario where the program enables processing of students in a waiting list in
the form of a queue using queue operations such as set-queue and unset-queue. As this is
already a better implementation, this program only requires a better design such as a Graphical
User Interface which would be more visually appealing than the current version which aides
an Output Console from the IDE. It is clear from the many types of algorithms presented and
explained through Task 3, that every algorithm is unique and is more efficient than others on
certain tasks, scenarios or conditions. For example, even though insertion sorting algorithms
are less efficient than merge sorting algorithms, for data sets below 10 – 12 elements in size,
insertion sorting out performs most of other types of algorithms available including merge sort.
However, itis worth noting that on average, for most cases, the Divide and Conquer algorithms
are more efficient and faster than Simple Sorting algorithms as they prove a more
logarithmic performance. Therefore, the use of the correct type of data structure as well as the
algorithm for the specific problem is always essential for implementing faster and efficient
programs.
Though it took so long to catch up, Data Structures & Algorithms became an interesting area
which helps in understanding how certain software work and behave. The different types
of data structures, algorithms and multiple approaches for sorting and searching data found on
this module reveals that the area studied is just the surface, and promotes the learning of much
more sophisticated methods in the future. As a novice, it is always hard to understand how
exactly modern software are supported using the techniques introduced in this module,
however while completing this assignment, it became evident that there are vast amounts of
research and experimental work dedicated for this area alone in which cases, the most
efficient approaches, algorithms and methods are found and invented, specially based on
their performance. However, it is a reason to worry, that such great research could not be
referenced in this document. It is a pleasure to learn about strings and how they could be
processed using different methods in a programming language. It is also a pleasure learning
about algorithms and where exactly specific algorithms should be used. However, it was
unclear and hard to understand about certain data structures such as Graphs and Trees, and how
the algorithms are used to sort data in such forms. While it was confusing how certain coding
practices and techniques differ the performance of algorithms, such as in the case of recursive
and non-recursive binary searching algorithms where the recursive always outperforms the
iterative one, they were always promising a whole new perspective of observing the problem
from which knowledge about how they actually work could be increased. These skills whether
great or small would be beneficent in the future whether it would be for sorting data or for
solving other problems as well. Therefore, this document would serve as a problem solver in
the future as it could be used as a revision tool when the above mentioned weaknesses arrive.
Strengths Weaknesses
Confidence in completing the assignment Difficulties in when explaining to others
before the deadline
Interest throughout the module and The time spent on a single task was quite
developing the system long
A big support from my family members Difficulties in arranging the tasks from
within the given time single documents
Appendix
COL-A-056062_DSA
_COM73.rar
References
Beniwal, M., Singh, A., Diwan, A., Kaushik, J., Kumar, K.N., Singh, V., Gautam, N. & Joshi,
V.P. (2016) Insertion sorting.[Online] Available from: http://www.studytonight.com/data-
structures/insertion-sorting [Accessed 06th August 2018].
Cormen, T.H., Leiserson, C.E., Rivest, R.L. & Stein, C. (2009) Introduction to Algorithms,
Third Edition. 3rd edition. [e-book] Massachusetts, MIT Press. Available from:
https://mitpress.mit.edu/books/introduction-algorithms [Accessed 15th August 2018].
Deitel, H.M. & Deitel, P. (2005) Strings, Characters and Regular Expressions. In:JAVA for
Programmers. USA, Prentice Hall Professional, p. 616. Forrest, P. (2016)What is non-recursive
binary search Algorithm? Weblog. [Online] Available from:
http://www.answers.com/Q/What_is_non_recursive_binary_search_algorithm [Accessed 15th
August 2018. GMT 10:23:26].
Ruehr, F. (1998) Data Structures and Algorithms: Sorting Algorithms. Presented at Willamette
University. Oregon. [Online] Available from:
http://www.willamette.edu/~fruehr/dsa/lectures/sorting1.html [Accessed 01st September
2018].
Stoimen. (2011) Computer Algorithms: Binary Search. Weblog. [Online] Available from:
http://www.stoimen.com/blog/2011/12/26/computer-algorithms-binary-search/ [Accessed
01st September 2018. GMT 11:38:26].
Swartz, F. (2003)Java Notes: Algorithms: Recursive Binary Search. [Online] Available from:
http://www.fredosaurus.com/notes-cpp/algorithms/searching/rbinarysearch.html [Accessed
02nd September 2018].
Tripathi, P. (2014) Binary Search Implementation using JAVA . Weblog. [Online] Available
from: http://www.c-sharpcorner.com/blogs/binary-search-implementation-using-c-sharp1
[Accessed 02nd September 2018. GMT 08:22:23].
Tutorials Point. (2016) Java – String concat() Method. [Online] Available from:
http://www.tutorialspoint.com/java/java_string_concat.htm [Accessed 05th September 2018].