Data Structure and Algorithm
Data Structure and Algorithm
ALGORITHM
-SHREYA
Introduction to Data Structures
Primitive data structure is the data structure that allows Non-Primitive data structure is a data structure that allows
you to store only single data type values. you to store multiple data type values.
Primitive data structure always contains some value i.e. You can store a NULL value in the non-primitive data
these data structures do not allow you to store NULL structures.
values.
The size of the primitive data structures is dependent on The size of the non-primitive data structure is not fixed.
the type of the primitive data structure.
Arrays
ARRAYS
Three
One -Dimensional Two dimensional Dimensional
One dimensional:
The simplest type of arrays, one-dimensional arrays, contains a single row
of elements. These arrays are usually indexed from 0 to n-1, where ‘n’ is
the size of the array. Utilizing its assigned index number, each element in
an array can be conveniently accessed.
Two Dimensional Array:
Two-dimensional array type are arrays that contain arrays of elements.
These are also referred to as matrix arrays since they can be thought
of as a grid that lays out the elements into rows and columns. Each
element within the two-dimensional array can be accessed individually
by its row and column location. This array type is useful for storing data
such as tables or pictures, where each element may have multiple
associated values.
Multi-Dimensional
Multi-Dimensional arrays are a powerful data structure used to store
and manage data organizationally. This type of arrays consist of
multiple arrays that are arranged hierarchically. They can have any
number of dimensions, the most common being two dimensions
(rows and columns), but three or more dimensions may also be
used.
Array Operations
Traversal: Array traversal refers to the process of accessing each element of an array in a
sequential order from the beginning to the end or from the end to the beginning.
Search: Search is the process of finding a specific element within an array. This is done by
comparing the target element with each element in the array until a match is found. There are
various search algorithms that can be used.
Sorting: Sorting is the process of arranging the elements in an array in a specific order. The
most common sorting algorithms are bubble sort, insertion sort, selection sort, merge sort, and
quicksort.
Insertion: Insertion is the process of adding a new element to an array. Depending on the
application, the new element can be inserted at the beginning, end, or any other location
within the array.
Here's a simple algorithm in simple language to perform an insertion in an array:
Define the array and the element to be inserted.
Determine the position where the element should be inserted.
Shift the elements after the insertion position to the right by one index to make room for
the new element.
Insert the new element at the desired position.
Update the length of the array
Deletion: Deletion is the process of removing an existing element from an array.
Depending on the application, the element to be deleted can be at any location
within the array. When deleting an element, the other elements in the array may
need to be shifted to fill the gap left by the deleted element.
Here is the algorithm to delete an element from an array in C:
Initialize the array and the index of the element to be deleted.
Traverse the array from the index of the element to be deleted until the end of the
array.
Shift each element one position to the left.
Decrement the size of the array by 1.
Classification:
Data
Structures
n linear search input data need not to be in In binary search input data need to be in
sorted. sorted order.
Linear search performs equality comparisons Binary search performs ordering comparisons
THANK YOU