Data Structure & Algorithm
Data Structure & Algorithm
ASSIGNMENT BRIEF
Learner declaration
Marks Awarded
First assessor
IV marks
Agreed grade
Marks Awarded:
Task List
“POP” is a famous game among school boys. Player one will put the ball one by one and each ball will
locate on top of each other. Very first ball is located in the bottom of the tube and last ball is located in
the top.
Player 2 will fire the ball which is located in the top. Then the next ball become the top
Identify and properly justify the most suitable data structure with their operations for above
requirement. (Explain and evaluate the advantages and disadvantages of suitable data structure.
And evaluate the suitability of selected algorithm with real-time examples)
Crate a Program for search value in the given int array. Student can select any search algorithm
for execute the program.
30 45 55 56 70 72 74 76 80 120
5. Create the main method to declare the given array. Call search and display methods.
Task 3 Marks 35 (LO 3)
To improve the performance of the system memory management recursion algorithms, play big
role.
Note: You can make any valid assumptions and need to mention your assumptions clearly
Referencing Guidance
To use Harvard referencing for citation and compile reference list you can go through
following guidance provided by Anglia Ruskin University.
In the Harvard system, the author's surname and year of publication are cited in the text of your
work. The full details of the source are included in a reference list at the end of the
assignment.
(Anglia Ruskin University,2013)
Guide to the Harvard Style of Referencing 2013. University Library. [pdf] Anglia Ruskin University.
Available at: <http://libweb.anglia.ac.uk/referencing/files/Harvard_referencing_2013.pdf> [Accessed
20 Octomber 2014].
Resources
Books
An Introduction to Object-Oriented Programming with Java, 5th Edition(McGraw-
Hill)978-0-07352-330-9
Data Structures and Algorithms in Java , 2nd Edition (Robert Lafore)
Websites
http://www.javaworld.com/article/2073390/core-java/datastructures-and-algorithms-
part-1.html
https://www.udemy.com/introduction-to-data-structures-algorithms-in-java/
Contents
Table of Figures....................................................................................................................................................7
Acknowledgement.................................................................................................................................................8
Task 1.................................................................................................................................................................. 10
Data structure.................................................................................................................................................10
Operations on Data Structures.....................................................................................................................11
Identifying the appropriate data structure for the “POP” game...............................................................12
Other Advantages......................................................................................................................................12
Other Disadvantages.................................................................................................................................12
Task 2.................................................................................................................................................................. 13
Crate a Program for search value in the given int array. Student can select any search algorithm for
execute the program......................................................................................................................................13
Task 3.................................................................................................................................................................. 16
What is recursion in data structure? Identify the advantages and disadvantages of recursion
algorithms......................................................................................................................................................16
Advantages.................................................................................................................................................16
Disadvantages............................................................................................................................................16
Develop method for recursion algorithm to print factorial value numbers..............................................16
References...............................................................................................................Error! Bookmark not defined.
Table of Figures
Figure 1 Create an appropriate Java class & method to Sort the above mention array.......................13
Figure 2 Create a method to search the given values in above mention array and method requires
array parameter with search key............................................................................................................14
Figure 3 Create a method to print the values in array and method require array parameter& Create
the main method to declare the given array. Call search and display methods.....................................15
Figure 4 Ouput.......................................................................................................................................15
Figure 5 Develop method for recursion algorithm to print factorial value numbers............................16
Acknowledgement
I would really like to give my special thanks to my lecturer Mr. Priyanga Siriwardana as well as our
Campus (ICBT) who gave me the golden opportunity to do this wonderful project on the Data
structures and algorithms, which also helped me do a lot of homework and I came to know so many
new things that I'm very grateful to them. During the lecture sessions Mr Priyanga Siriwardana shows
us to solve different kind data structures and algorithms Tasks and errors. Now I understand how data
structures and algorithms works.
Introduction
Data Structure is a means to gather and organize information in such a way that we can efficiently
execute operations on that data. In terms of certain partnerships, Data Structures is about making data
components for better organization and storage.in this assignment we need to Identify and properly
justify the most suitable data structure with their operations for above requirement. and also, we need to create
proper algorithms. For given scenarios.
Task 1
What is Algorithm?
Data structure
A data structure is a way of organizing and storing the data in computer in a manner that it can be used
effectively.
We may choose a data structure to work with various algorithms in computer programming. There is
details in and data structure about the relationship between data values and the functions that can be
added to the data. [ CITATION gee1 \l 1033 ]
Primitive data structures are data types which holds a single value.
Linear data structures are arranged in a way that a data item is connected to one other data item in a
sequential manner. Data structure where data elements are organized sequentially or linearly in what is
called a linear data structure where the elements are connected to their prior and next neighboring
elements. Single stages are involved in the linear data structure. We can, thus, only traverse all the
elements in a single sprint. It is easy to enforce linear data structures since machine memory is
organized in a linear fashion.
Insertion - Insertion implies the addition to a data structure of a new data element
Detection- Deletion means the elimination, if detected, of a data entity from a data system.
Searching - Searching requires searching within a data structure for the defined data function.
Traversal- That means adding a new dimension to the structure of the crated data
Sorting - Sorting is called organizing data elements of a data structure in a given order.
Merging - It is called combining, which incorporates components of two identical data structures to
create a single data structure of the same kind.
[CITATION sca \l 1033 ]
Identifying the appropriate data structure for the “POP” game
In this game balls are added in a manner that the first ball added stays at the bottom of the tube and the
next one on top of it. Finally, the last ball added to the tube is the one we can fire first. And once it is
fired, the previously added ball comes to the top. This scenario follows first in last out (FILO)
procedure. So, we need a data structure which also follows First in last out procedure. So, Stack data
structure is the best data structure to implement this game.
Stack data structure has an operation named “push” which can be used to implement putting the balls
to the tube with respect to the game. And the “pop” operation of the stack can be used to implement
the Firing operation of the game.
The advantage of using Stack data structure is, it helps to manage the First in Last out method easily
and it won’t make any errors when ordering the items. The Disadvantage of this is, if we wanted to
select a random ball to shoot in the future, we can’t do that. Because Stack data structure always
allows us to fire the last ball that added to the tube.
Other Advantages
Unlike arrays, memory can be allocated dynamically in stacks
Adding and removing elements is faster it does not need much effort compared to arrays
Stacks automatically deallocates variables once removed
Other Disadvantages
Because of the dynamic memory allocation, if all the memory space is not used, then there will
be memory space wastage
Stacks are not much flexible and it lacks of scalability
Can only access local variables
Needs to be careful when adding too much elements to the stacks, there’s a risk of stack
overflow
Task 2
Crate a Program for search value in the given int array. Student can select any search
algorithm for execute the program.
Figure 1Create an appropriate Java class & method to Sort the above mention array
A method to sort the elements in the array in ascending order was created. Bubble sort method is
used in here because it is easier to understand and it is simple.
Bubble Sort is a basic algorithm that is used in the context of an array of n elements to sort a given set
of n elements supplied. Bubble Sort compares one by one all the elements and sorts them on the basis
of their values.
If the array in question needs to be sorted in ascending order, so the bubble sort begins by matching the
first element of the array with the second element, and if the first element is bigger than the second
element, all elements are switched, then the second and third elements are compared, and so on.
Figure 2Create a method to search the given values in above mention array and method requires array parameter with search key.
A method to search for an element in array is implemented named “searchArray”. This method
requires 2 arguments: an array and a search key. If the search value is found inside the array, the index
is returned. Binary Search method is the best method suitable here, because the array is already sorted.
So it is more efficient than linear search in this situation
Figure 3Create a method to print the values in array and method require array parameter& Create the main method to declare the
given array. Call search and display methods.
“display Array” method is implemented to print the values in the array. And a main method is
implemented to define the array elements and call the above created methods to get the output of the
program.
Figure 4Ouput
The output of the program is received as this, after the program is executed through NetBeans
Task 3
What is recursion in data structure? Identify the advantages and disadvantages of
recursion algorithms.
Recursion in data structures happens when a method calls itself within its own definition scope. It calls
itself over and over again until an exit condition is met which cause to breaks the loop.
Recursion method idea is to break a bigger problem into smaller pieces and compute these small pieces
individually and finally merge the results to get the final output.
Advantages
The main advantage of using recursion is sometimes it is much simpler to implement some
functionalities as a recursive function such as finding a factorial of a number. And also, it needs less
code and its much clearer because its closer to the mathematical definition.
Recursion methods are very helpful when traversing through tree elements. Since recursion methods
use a stack memory to store intermediate results it is faster in accessing the data. So the execution cam
be faster.
Disadvantages
However, it has some disadvantages. It needs more memory to work because intermediate values are
stored in the stack until the execution completes. So, this could lead to stack overflows if the program
is going much deeper. Also, if the exit conditions are not correctly defined, recursion methods could
lead to infinite loops and crash the program.
Figure 5 Develop method for recursion algorithm to print factorial value numbers.
We assume that, N is not a very big number, because it may cause errors due to stack overflow
if N is too big.
References
geeksforgeeks. (n.d.). . Retrieved from www.geeksforgeeks.org: https://www.geeksforgeeks.org/data-
structures/
www.datastructure.com. (n.d.).
Conclusion
in this Data Structure & Algorithm assignment we have to identified and properly justified the most
suitable data structure with their operations for above requirement. and also, we had to create proper
algorithms. For given scenarios. I learnt lot from our lecturer Mr Priyanga Siriwardana and also, I have
read data structure and Algorithm E book online. I am thanking again Mr. Priyanga Siriwardana as
well as our Campus (ICBT) who gave me the golden opportunity to do this wonderful Data Structure
& Algorithm Project.
Page 19 of 19