Data Structures Primer

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 22

REVISION PRIMER

DATA STRUCTURES AND ALGORITHM


ICS 2105 :
KARANJA
ON Definition
•Data structure is representation of the
logical relationship existing between
individual elements of data.
•In other words, a data structure is a way of
organizing all data items that considers not
only the elements stored but also their
relationship to each other.
Introduction
•Data structure affects the design of both
structural & functional aspects of a program.
Program = algorithm + Data Structure
•A algorithm is a step by step procedure to
solve a particular function.
Introduction
•Algorithm is a set of instruction written to
carry out certain tasks and the data
structure is the way of organizing the data
with their logical relationship retained.
•To develop a program of an algorithm, we
should select an appropriate data structure
for that algorithm.
•Therefore algorithm and its associated data
structures from a program.
Classification of Data Structure
•Data structure are normally divided into two broad
categories:
• Primitive Data Structure
• Non-Primitive Data Structure
Classification of Data Structure

Data structure

Primitive DS Non-Primitive DS

Integer Float Character Pointer


Classification of Data Structure

Non-Primitive DS

Linear List Non-Linear List

Array Queue Graph Trees

Link List Stack


Primitive Data Structure
•There are basic structures and directly
operated upon by the machine instructions.
•In general, there are different
representation on different computers.
•Integer, Floating-point number, Character
constants, string constants, pointers etc.,
fall in this category.
Non-Primitive Data Structure
•There are more sophisticated data
structures.
•These are derived from the primitive data
structures.
•The non-primitive data structures
emphasize on structuring of a group of
homogeneous (same type) or
heterogeneous (different type) data items.
Non-Primitive Data Structure
•Lists, Stack, Queue, Tree, Graph are
example of non-primitive data structures.
•This will be our main interests -Non-
Primitive Data Structure
•The design of an efficient data structure
must take operations to be performed on
the data structure.
Non-Primitive Data Structure
•The most commonly used operation on data structure
are broadly categorized into following types:
• Create
• Selection
• Updating
• Searching
• Sorting
• Merging
• Destroy or Delete
Differences
•A primitive data structure is generally a basic
structure that is usually built into the language,
such as an integer, a float.
•A non-primitive data structure is built out of
primitive data structures linked together in
meaningful ways, such as a or a linked-list, binary
search tree, AVL Tree, graph etc.
Descriptions: Arrays
•An array is defined as a set of finite number of
homogeneous elements or same data items.
•It means an array can contain one type of data
only, either all integer, all float-point number or all
character.
Arrays
•Simply, declaration of array is as follows:

int arr[10]
•Where int specifies the data type or type of
elements arrays stores.
•“arr” is the name of array & the number specified
inside the square brackets is the number of
elements an array can store, this is also called
sized or length of array.
Arrays
•Following are some of the concepts to be
remembered about arrays:
• The individual element of an array can be
accessed by specifying name of the array,
following by index or subscript inside square
brackets.

• The first element of the array has index zero[0].


It means the first element and last element will
be specified as: arr[0] and arr[9] respectively.
Arrays
• The elements of array will always be stored in
the consecutive (continues) memory location.

• The number of elements that can be stored in


an array, that is the size of array or its length is
given by the following equation:
(Upperbound-lowerbound)+1
Arrays
• For the above array it would be ( 9 – 0 ) + 1 = 10
where 0 is the lower bound of array and 9 is the
upper bound of array.

• Array can always be read or written through


loop. If we read a one-dimensional array it
require one loop for reading and other for writing
the array.
Arrays
• For example: Reading an array

for(i=0; i <= 9; i++)


scanf(“%d”,&arr[i]);

• For example: Writing an array

for(i=0; i<=9; i++)


printf(“%d”,arr[i]);
Arrays
• If we are reading or writing two-dimensional
array it would require two loops. And similarly
the array of a N dimension would required N
loops.

• Some common operation performed on array


are:
• Creation of an array
• Traversing an array
Arrays
• Insertion of new element
• Deletion of required element
• Modification of an element
• Merging of arrays
More on arrays
• https://www.guru99.com/array-data-structure.html
• https://
www.simplilearn.com/tutorials/data-structure-tutorial/array
s-in-data-structure
• https://www.faun.dev/c/stories/thenjikubheka/data-structur
es-and-algorithms-arrays-in-python
/
• https://
www.datacamp.com/community/tutorials/data-structures-p
ython
• https://careerkarma.com/blog/python-array/
• https://www.w3schools.in/data-structures-tutorial/data-stru
ctures-arrays
/
More on arrays 2D arrays
• https://www.javatpoint.com/data-structure-array
• https://www.simplilearn.com/tutorials/data-structure-
tutorial/two-dimensional-arrays
• https://www.javatpoint.com/python-2d-array
• https://www.tutorialspoint.com/
data_structures_algorithms/array_data_structure.htm

You might also like