You are on page 1of 31

INTERNATIONAL COLLEGE OF BUSINESS &

TECHNOLOGY LTD
ASSIGNMENT BRIEF

Assignment Cover Sheet

Qualification Module Number and Title


HND in Computing and Software Data Structures and Algorithms SED52013
Engineering
Student Name & No. Assessor
THENUJA UTHAYAKUMAR Priyanga Siriwardana
JF/HNDCSE/07/07
Hand out date Submission Date

10.04.2021
Assessment type Duration/Length of Weighting of Assessment
Assessment Type
Coursework 100%

Learner declaration

I, ………………………………………….<name of the student and registration number>,


certify that the work submitted for this assignment is my own and research sources are fully
acknowledged.

Marks Awarded
First assessor

IV marks

Agreed grade

Signature of the assessor Date

1
FEEDBACK FORM
INTERNATIONAL COLLEGE OF BUSINESS & TECHNOLOGY
Module: SED52013

Student: THENUJA UTHAYAKUMAR

Assessor: Mr. Priyanga Siriwardana


Assignment: Data Structures and Algorithms

Strong features of your work:

Areas for improvement:

Marks Awarded:

2
Table of Contents
ACKNOWLEGEMENT............................................................................................................5
INTRODUCTION......................................................................................................................5
TASK 1......................................................................................................................................6
TASK 2....................................................................................................................................14
TASK 3....................................................................................................................................26
Conclusion................................................................................................................................30
Gantt chart................................................................................................................................30
REFERENCES.........................................................................................................................30
Appendix..................................................................................................................................31

3
Table of Figures
Figure 1......................................................................................................................................7
Figure 2......................................................................................................................................7
Figure 3......................................................................................................................................9
Figure 4....................................................................................................................................10
Figure 5....................................................................................................................................10
Figure 6....................................................................................................................................11
Figure 7....................................................................................................................................12
Figure 8....................................................................................................................................12
Figure 9....................................................................................................................................13
Figure 10..................................................................................................................................14
Figure 11..................................................................................................................................15
Figure 12..................................................................................................................................16
Figure 13..................................................................................................................................16
Figure 14..................................................................................................................................17
Figure 15..................................................................................................................................18
Figure 16..................................................................................................................................19
Figure 17..................................................................................................................................20
Figure 18..................................................................................................................................20
Figure 19..................................................................................................................................21
Figure 20..................................................................................................................................21
Figure 21..................................................................................................................................22
Figure 22..................................................................................................................................22
Figure 23..................................................................................................................................23
Figure 24..................................................................................................................................23
Figure 25..................................................................................................................................24
Figure 26..................................................................................................................................25
Figure 27..................................................................................................................................25
Figure 28..................................................................................................................................26
Figure 29..................................................................................................................................27
Figure 30..................................................................................................................................27
Figure 31..................................................................................................................................29
Figure 32..................................................................................................................................30
Figure 33..................................................................................................................................31

4
ACKNOWLEGEMENT
I gratefully thanks to my Lecturer Mr.Saikrishnan, Manage for providing me an
opportunity to do this assignment. I sincerely thank to my classmates for their
guidance and encourage me to do this assignment. And finally thank to my
parents keep the supported to me.

INTRODUCTION
In simple terms, data structures are structures that are designed to store ordered
data so that various functions can be easily performed. It refers to the
knowledge of data that needs to be organized in memory. It should be designed
and implemented in such a way as to reduce complexity and increase efficiency.

In this we are going to look at Data , Array, sort and Factorial in this report.

5
TASK 1
Data Structure
In computer terms, a data system is a specific way of storing and organizing data in a
computer's memory so that this data can then be used efficiently. Data can be organized in
many ways, such as a logical or mathematical model for a specific structure of data.

The data structure can be subdivided into major types:

1. Linear Data Structure


2. Non-linear Data Structure

Linear Data Structure


The data structure is said to be linear if its components are combined to form any particular
sequence. There are two techniques for representing such a linear structure within memory.

1. The first way is to provide linear relationships between all represented items using
linear memory location. These linear structures are called rows.

2. The second technique is to provide a linear relationship between all referenced items
using the concept of pointers or links. These linear structures are called linked lists.

The common examples of the linear data structure are:

A. Arrays
B. Queues
C. Stacks
D. Linked lists

Array
In computing, an array data structure, or simply an array, is a data structure that consists of a
set of elements (values or variables), each identified by at least one array code or key. An
array is stored, that is, the position of each element can be calculated using a mathematical
formula from its index node.

6
Figure 1
Queues
This is a compression data system. This is different from the others. The array is open at both
ends. One is used to insert data and the other is used to remove data.

Figure 2

7
Stack
A layer is an ideological structure based on homogeneous factors, which is mainly based on
Based on the remaining first out (LIFO) policy. This is the most widely used type of abstract
statistic. Two main characters, especially Push and pop. Bush and Bob are carried away
Element, which is currently the overlapping element. The push function adds one thing the
pop function removes a factor from the peak. Layered thinking is used in memory systems
and computer programming.

A layer is considered a restricted data structure because only a limited number of functions
are allowed. In addition to the push and pop functions, some processes can be allowed to
improve

Functions like:

1. Peek: View the tallest item on the layer.


2. Duplicate: Copy the value of the top item into a variable and place it back on the
layer.
3. Swap: Replaces the top two elements of the layer.
4. Rotate: move the highest elements of the layer or move them by a as indicated by a
number Rotating fashion.
5. Push
Inserting any item into a stack is called an insert operation. In our task 1, each player
put the ball one at a time. Insert item on stack will be incremented by one.
6. Pop
This operation refers to the removal of an item. Used to access the item at the top of
the stack. There is only one item that we can remove.

Advantages of Using Stack over other data structures


1. Allows you to control how memory is allocated and deal located
2. Stack automatically cleanses the object
3. Not easily corrupted
4. Variables cannot be resized

Disadvantages of Using Stack over other data structures


1. Layer memory is very low
2. Creating more material in the layer will increase the risk of stock overflow
3. Random access is not possible

8
Stack Representation
The following diagram Stack a layer and it’s Representation

Figure 3

Conclusion
A cascade can be executed by sequence, configuration, pointer and linked list. Both layers
can be a standard measurement or it can also have the experience of dynamic resizing. Here,
we are going to stack the application of arrays, which form a fixed size layer implementation.

Basic operations of Stack


When pushed into the data Stack. To use a layer efficiently, we need to check the condition
of the Stack As well as. For the same purpose, the following functionality is added in Stack:

1. Peek or Top: Returns top element of stack


2. Is Empty: Returns true if stack is empty, else false

Stack operations include stack boot, use it, and boot it. In addition to these basic things, a
layer is used for the following two primary functions:

1. Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow
condition.
2. Pop: Removes an item from the stack. The items are popped in the reversed order in
which they are pushed. If the stack is empty, then it is said to be an Underflow
condition.

9
Linked List
The linked list is a linear data structure in which the items are not stored in continuous
memory space.

Figure 4
Non-linear Data Structure
This structure is used primarily to represent data that contains a hierarchical relationship
between multiple items.

Examples of Non-Linear Data Structures are listed below:

A. Graphs
B. Trees
C. Table of contents

Tree: In this case, the data usually has a hierarchical relationship between several
components. The data system that reflects this relationship is called a tree chart with roots or
a tree.

Figure 5

10
Graph: In this case, the data sometimes maintains a relationship between pairs of elements,
which does not need to follow a hierarchical structure. This data system is called a map.

(prepinsta.com, 2020)

Push and POP Stack


Coding

Figure 6

11
Figure 7

Figure 8

12
Output

Figure 9
Real life example of stack
1. A good real-life example of a stack is the pile of bangles that you encounter when you
ready at the to function: When you remove a plate from the pile, you take the plate on
the top of the pile. But this is exactly the bangle that was added ("inserted'') most
recently to the pile by the bangles. If you want the bangle at the bottom of the pile,
you must remove all the bangle on top of it to reach it.
2. A sadder, example of a stack is the slogan, "last hired, first fired,'' which is typically
utilized when a company reduces its work force.
3. Many computer algorithms work best with stacks --- stacks are used for
Remembering partially completed tasks, and undoing (backtracking from) an action.
4. Arithmetic expression evaluation
5. The Java compiler translates programs into postfix notation
6. The Java Virtual Machine uses a stack

13
TASK 2
Sort Algorithm
We use sorting algorithms to rearrange the given order or list element according to the
element comparison operator. The comparator operator helps determine the new order of
elements in the respective data structure.

Different Sorting Algorithms


1. Bubble Sort
Bubble sorting is a simple method used to sort a set of n elements with the number of
n elements in a row. The bubble sequence compares all the elements one by one and
sorts them based on their values.

Figure 10

14
2. Insertion Sort
This is how the insertion type works. It starts with index 1 (not 0), and each code
starting with index 1 is like a new card, you have to place it in the right position on
the saber lined up on the left.

Figure 11

15
3. Selection Sort
The selection sequence is theoretically the simplest sorting algorithm. This algorithm
first finds the smallest element in the row and replaces it with the element in the first
position, then it finds the second smallest element and replaces it with the element in
the second position, and the whole sequence that continues up to this point is sorted.

Figure 12
4. Quick Sort
It is also called partition-exchange sort. This algorithm divides the list into three main
parts:
1. Elements less than the Pivot element
2. Pivot element(Central element)
3. Elements greater than the pivot element

Figure 13

16
5. Merge Sort
Merge Sort follows the rule of Divide and Conquer to sort a given set of
numbers/elements, recursively, hence consuming less time.

Figure 14

17
6. Heap Sort
Heap sorting is one of the best sorting methods, and there is no time to run double bad
position. Pile sorting involves creating a pile data structure from a given array and
then using the pile to sort the array.

Figure 15
(www.studytonight.com)

18
Selection sort
In task 2, we are going to take the selection sort to solve the instructions. The very simple
best way to understand the sorting element does not depend on the initial arrangement of the
element.

Below the numbers we use the 30, 80, 05,50,40,90,70,60,100,20 selection sort

1. Coding with output

Figure 16

19
2. Coding

Figure 17

Figure 18

20
3. Output

Figure 19
I created class as Selections. We create method as calculate. Array parameter help to find the
minimum value of the given array. The swapping function help to swap the number with other
lowest number.
Bubble Sort
In task 2, we are going to take the Bubble sort to solve the instructions. The very simple best
way to understand the sorting element does not depend on the initial arrangement of the
element.

Below the numbers we use the 30, 80, 05,50,40,90,70,60,100,20 bubble sort

1. Coding With Output

Figure 20

21
2. Coding

Figure 21

Figure 22

22
3. Output

Figure 23
Insertion Sort
In task 2, we are going to take the Insertion Sort to solve the instructions. The very simple
best way to understand the sorting element does not depend on the initial arrangement of the
element.

Below the numbers we use the 30, 80, 05,50,40,90,70,60,100,20 Insertion Sort

1. Coding with Output

Figure 24

23
2. Coding

Figure 25

24
Figure 26
3. Output

Figure 27
Conclusion
I have put all three of these in the selection sort, bubble sort and insertion sort and put them in
ascending order. I have used the algorithm in these.

1. Algorithm
a. Step 1 - Select the first element of the list
b. Step 2: Compare the selected element with all the other elements in the list
c. Step 3: In every comparison, if any element is found smaller than the selected
element (for Ascending order), then both are swapped
d. Step 4: Repeat the same procedure with element in the next position in the list till
the entire list is sorted

25
TASK 3
Recursion in data structure
Recursion is defined as defining itself. Repeat in reverse order, used to solve problems related
to repetitions.

Most computer languages support recursion by allowing a function to call from its own code.
Some programming languages do not define any bracelet structure.

Types of Recursion

There are two types of Recursion

1. Direct recursion
2. Indirect recursion

Direct Recursion
When there is a call to the same system in the body of a system, we say that the system is
directly rotational.

There are three types of Direct Recursion

1. Linear Recursion
Linear recursion begins by examining a set of basic events that must be at least one.

Coding

Figure 28

26
Figure 29
Output

Figure 30
2. Binary Recursion
Binary recursion occurs whenever there are two recursive calls for each base case.
3. Multiple Recursion
In multiple recursions we make not just one or two but many recursive calls.

27
Indirect recursion
There is a simple case of indirect recursion called mutual recursion. It involves only two
functions that depend upon one another.

Advantages of Recursion
1. Recursion can reduce time complexity
2. Recursion adds clarity and reduces the time needed to write and debug code
3. Recursion is better at tree traversal

Disadvantages of Recursion
1. Recursion uses more memory
Because the function has to add to the stack with each recursive call and keep the
values there until the call is finished, the memory allocation is greater than that of an
iterative function
2. Recursion can be slow
If not implemented correctly (as stated above with memorization) it can be much
slower than iteration.

(www.cseworldonline.com)

Factorial
Factor is denoted by an exclamation point (!) Which is defined by all integers as greater than
or equal to 0. For example, if n is greater than or equal to one, then the factor is all integers
less than or equal to n but greater than or equal to 1

Zero factors are different. It generally agrees with 0! = 1

28
I used find factorial value in Java

Figure 31

29
Conclusion
In this report I have clearly stated about data and Sort. For examples I used C ++ and Java
inside. And I'm clearly coded about recursion and the Factorial. Mostly I said it all with the
code.

I have learned a lot through this report. And I also had a clear understanding of data structure
and algorithm. This report was helpful in revisiting C ++ and Java languages. Of course I was
asked to prepare another report on the same subject and I can do better.

Gantt chart

Figure 32

REFERENCES
prepinsta.com. (2020, July 30). prepinsta. Retrieved 03 30, 2021, from prepinsta.com:
https://prepinsta.com/data-structures/introduction-to-stacks-in-data-structures/
#:~:text=Advantages%20of%20Using%20Stack%20over%20other%20data
%20structures,a%20variable%20is%20not%20used%20outside%20that%20function.

www.cseworldonline.com. (n.d.). cseworldonline. Retrieved 04 07, 2021, from


www.cseworldonline.com: https://www.cseworldonline.com/data-structure/recursion-
in-data-structures.php

www.studytonight.com. (n.d.). studytonight. Retrieved 04 01, 2021, from


www.studytonight.com: https://www.studytonight.com/data-structures/introduction-
to-sorting

30
Appendix
I find factorial value in C++. For that I am using C ++ online. Because I don't have C++ in
my PC.

Figure 33

31

You might also like