0% found this document useful (0 votes)
8 views

Week Four Kirinyaga University Arrays and Implementation

Uploaded by

ioenga741
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Week Four Kirinyaga University Arrays and Implementation

Uploaded by

ioenga741
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Operations on data structure

1) Traversing: Every data structure contains the set of data elements. Traversing
the data structure means visiting each element of the data structure in order to
perform some specific operation like searching or sorting.

2) Insertion: Insertion can be defined as the process of adding the elements to the
data structure at any location.

If the size of data structure is n then we can only insert n-1 data elements into it.

3) Deletion:The process of removing an element from the data structure is called


Deletion. We can delete an element from the data structure at any random location.

If we try to delete an element from an empty data structure then underflow occurs.

4) Searching: The process of finding the location of an element within the data
structure is called Searching. There are two algorithms to perform searching,
Linear Search and Binary Search. We will discuss each one of them later in this
tutorial.

5) Sorting: The process of arranging the data structure in a specific order is known
as Sorting. There are many algorithms that can be used to perform sorting, for
example, insertion sort, selection sort, bubble sort, etc.

6) Merging: When two lists List A and List B of size M and N respectively, of
similar type of elements, clubbed or joined to produce the third list, List C of size
(M+N), then this process is called merging

Array
Definition
 Arrays are defined as the collection of similar type of data items stored at
contiguous memory locations.
 Arrays are the derived data type in C programming language which can store the
primitive type of data such as int, char, double, float, etc.
 Array is the simplest data structure where each data element can be randomly
accessed by using its index number.
 For example, if we want to store the marks of a student in 6 subjects, then we
don’t need to define different variable for the marks in different subject. instead
of that, we can define an array which can store the marks in each subject at a the
contiguous memory locations.

The array marks[10] defines the marks of the student in 10 different subjects
where each subject marks are located at a particular subscript in the array
i.e. marks[0] denotes the marks in first subject, marks[1] denotes the marks in
2nd subject and so on.

Properties of the Array


1. Each element is of same data type and carries a same size i.e. int = 4 bytes.
2. Elements of the array are stored at contiguous memory locations where the first
element is stored at the smallest memory location.
3. Elements of the array can be randomly accessed since we can calculate the
address of each element of the array with the given base address and the size of
data element.

Characteristics
 An array is always stored in consecutive memory location.
 It can store multiple value of similar type, which can be referred with single name.
 The pointer points to the first location of memory block, which is allocated to the array
name.
 An array can either be an integer, character, or float data type that can be initialised
only during the declaration.
 The particular element of an array can be modified separately without changing the
other elements.
 All elements of an array can be distinguishing with the help of index number.

Operations
The operations of an array include −
 Searching − It is used to find whether particular element is present or not.
 Sorting − Helps in arranging the elements in an array either in an ascending or
descending order.
 Traversing − Processing every element in an array, sequentially.
 Inserting − Helps in inserting elements in an array.
 Deleting − helps in deleting the element in an array.

Advantages of Array
 Array provides the single name for the group of variables of the same type
therefore, it is easy to remember the name of all the elements of an array.
 Traversing an array is a very simple process, we just need to increment the base
address of the array in order to visit each element one by one.
 Any element in the array can be directly accessed by using the index.

You might also like