Dsa Fab Assign2
Dsa Fab Assign2
Dsa Fab Assign2
HOMEWORK #2
1. What is Array?
Array is a container which can hold a fix number of items and these items should
be of the same type. Most of the data structures make use of arrays to implement
their algorithms. Following are the important terms to understand the concept of
Array.
o Element − Each item stored in an array is called an element.
o Index − Each location of an element in an array has a numerical index,
which is used to identify the element.
Array size
Elements
Array data type
Int array [10] = {10,12, 14, 16, 18, 20, 22, 24, 26, 28}
Array name
elements 10 12 14 16 18 20 22 24 26 28
index 0 1 2 3 4 5 6 7 8 9
Deletion refers to removing an existing element from the array and re-organizing
all elements of an array.
o For example, from the elements on question number 2, we will delete the
value 16
o Therefore, the output will be = 10, 12, 14, 18, 20, 22, 24, 26, 28.
Insertion operation is to insert one or more data elements into an array. Based
on the requirement, a new element can be added at the beginning, end, or any
given index of array.
o Following the same elements, we can insert a value from any given index
in of array, for example we will insert a value 8 in the first index or the
beginning.
o Therefore, the output will be = 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28.
o Note that the first index is Zero (0).
Search operation, you can perform a search for any array element based on its
value or its index.
o Following the same elements, we will be searching for a specific value,
and it will tell us at where index will we find it. For example, we search for
the value 22.
o Therefore, the output will be = The value 22 is at position 6.
o Whereas value is the element, and position is the index.
Update operation refers to updating an existing element from the array at a given
index.
o Following the same elements, when we update, we will input a new
element and replace it to a certain index. For example, we want to change
the element on the 9th index to 30.
o Therefore, the output will show all the unchanged elements, but on the 9 th
index it will be:
X [9] = 30
Note that upon using the operations, we must have a code first to compile and
execute, so that we can have the results or outputs as we use the operations.
Reference:
S, R. A. (2022, October 11). Arrays in data structure: A guide with examples [updated].
Simplilearn.com. from https://www.simplilearn.com/tutorials/data-structure-
tutorial/arrays-in-data-structure#:~:text=ScienceEnroll%20Now-,How%20Do
%20You%20Declare%20an%20Array%3F,Arrays%3A%20int%20arr%5Bn%5D
%3B