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

DS_Module-1 (1)

The document provides an introduction to data structures, explaining their types, classifications, and operations. It covers primitive and non-primitive data structures, including arrays, linked lists, stacks, queues, trees, and graphs, along with their characteristics and use cases. Additionally, it discusses operations on data structures such as traversing, searching, inserting, deleting, sorting, and merging, while also introducing the concept of Abstract Data Types (ADTs).

Uploaded by

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

DS_Module-1 (1)

The document provides an introduction to data structures, explaining their types, classifications, and operations. It covers primitive and non-primitive data structures, including arrays, linked lists, stacks, queues, trees, and graphs, along with their characteristics and use cases. Additionally, it discusses operations on data structures such as traversing, searching, inserting, deleting, sorting, and merging, while also introducing the concept of Abstract Data Types (ADTs).

Uploaded by

rashmipathak2006
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Introduction

Introduction to Data Structures, Concept


of ADT, Types of Data Structures- Linear,
Nonlinear, Static, Dynamic and operations
on Data Structures.
A data structure is basically a group of data
elements that are put together under one
name, and which defines a particular way of
storing and organizing data in a computer so
that it can be used efficiently.
Elementary Data Structure Organization

Data structures are building blocks of a program.

The term data means a value or set of values. It specifies


either the value of a variable or a constant

A data item that does not have subordinate data items is categorized as
an elementary item, the one that is composed of one or more
subordinate data items is called a group item.

For example, a student’s name may be divided into three sub-items—


first name, middle name, and last name—but his roll number would
normally be treated as a single item.
A record is a collection of data items.
For example, the name, address, course, and marks
obtained are individual data items.

A file is a collection of related records. For example,


if there are 60 students in a class, then there are 60
records of the students.
CLASSIFICATION OF DATA STRUCTURES

Data structures are generally categorized into two classes:


• primitive
• non-primitive data structures.

Non-primitive data structures are


Primitive data structures are the
those data structures which are
fundamental data types which are
created using primitive data
supported by a programming
structures.
language.
Examples of such data structures
Basic data types are integer, real,
include linked lists, stacks, trees,
character, and boolean.
and graphs.
The terms ‘data type’, ‘basic data
Non-primitive data structures can
type’, and ‘primitive data type’
further be classified into two
are often used interchangeably
categories: linear and non-linear
data structures.
Non-primitive data structures can further be classified into two categories:

linear and non-linear data structures

If the elements of a data structure are stored in a linear or sequential order,


then it is a linear data structure.

Examples include arrays, linked lists, stacks, and queues.

Linear data structures can be represented in memory in two different ways.

• One way is to have to a linear relationship between elements by means


of sequential memory locations.

• The other way is to have a linear relationship between elements by


means of links.
Arrays:
An array is a collection of similar data elements.

These data elements have the same data type.

The elements of the array are stored in consecutive

memory locations and are referenced by an index

syntax: type name[size];

For example, int marks[10];


Arrays are generally used when we want to store large amount of

similar type of data. But they have the following limitations:

∑ Arrays are of fixed size.

∑ Data elements are stored in contiguous memory locations

which may not be always available.

∑ Insertion and deletion of elements can be problematic because

of shifting of elements from their positions.


Linked Lists

• A linked list is a very flexible, dynamic data structure in which elements

(called nodes) form a sequential list.

• In contrast to static arrays, a programmer need not worry about how many

elements will be stored in the linked list.

• This feature enables the programmers to write robust programs which

require less maintenance.


Linked Lists

A linked list is a very flexible, dynamic data structure in which elements


(called nodes) form a sequential list.

In contrast to static arrays, a programmer need not worry about how


many elements will be stored in the linked list.

This feature enables the programmers to write robust programs which


require less maintenance.

In a linked list, each node is allocated space as it is added to the list.

Every node in the list points to the next node in the list
Every node contains the following two types of data:

 The value of the node or any other data that corresponds to that node

 A pointer or link to the next node in the list

The last node in the list contains a NULL pointer to indicate that it is the end or
tail of the list.

Since the memory for a node is dynamically allocated when it is added to the
list

The total number of nodes that may be added to a list is limited only by the
amount of memory available.
Advantage: Easier to insert or delete data elements

Disadvantage: Slow search operation and requires


more memory space
Stacks

•A stack is a linear data structure in which insertion


and deletion of elements are done at only one end,
which is known as the top of the stack.

•Stack is called a last-in, first-out (LIFO) structure


because the last element which is added to the stack is
the first element which is deleted from the stack.

•In the computer’s memory, stacks can be


implemented using arrays or linked lists.
Every stack has a variable top associated with it. top is used to store the address
of the topmost element of the stack.

It is this position from where the element will be added or deleted.

There is another variable MAX, which is used to store the maximum number of
elements that the stack can store.

If top = NULL, then it indicates that the stack is empty and if top = MAX–1, then
the stack is full.
stack supports three basic operations:

push, pop, and peep

The push operation adds an element to the top of the stack.

The pop operation removes the element from the top of the
stack.

And the peep operation returns the value of the topmost


element of the stack (without deleting it).
Queues

A queue is a first-in, first-out (FIFO) data structure in which the


element that is inserted first is the first one to be taken out.

The elements in a queue are added at one end called the rear
and removed from the other end called the front.

Like stacks, queues can be implemented by using either arrays or


linked lists.
Every queue has front and rear variables that point to
the position from where deletions and insertions can be
done
If we want to add one more value to the list then the rear would
be incremented by 1 and the value would be stored at the position
pointed by the rear.

if we want to delete an element from the queue, then


the value of front will be incremented. Deletions are
done only from this end of the queue
Trees

A tree is a non-linear data structure which consists of


a collection of nodes arranged in a hierarchical order.

One of the nodes is designated as the root node, and


the remaining nodes can be partitioned into disjoint
sets such that each set is a sub-tree of the root.
Graph
A graph is a non-linear data structure which is a
collection of vertices (also called nodes) and edges that
connect these vertices.
In a tree structure, nodes can have any number
of children but only one parent, a graph on the
other hand relaxes all such kinds of restrictions
OPERATIONS ON DATA STRUCTURES
Traversing It means to access each data item exactly once so that it
can be processed.
Example: to print the names of all the students in a class.

Searching It is used to find the location of one or more data items


that satisfy the given constraint.
Such a data item may or may not be present in the given collection
of data items.
Example :to find the names of all the students who secured 100
marks in mathematics.

Inserting It is used to add new data items to the given list of data
items.
Example: to add the details of a new student who has recently joined
the course.
Deleting It means to remove (delete) a particular data item from the
given collection of data items.

Example: to delete the name of a student who has left the course.

Sorting Data items can be arranged in some order like ascending


order or descending order depending on the type of application.

example: arranging the names of students in a class in an


alphabetical order, or calculating the top three winners by arranging
the participants’ scores in descending order and then extracting the
top three.

Merging Lists of two sorted data items can be combined to form a


single list of sorted data items.
ABSTRACT DATA TYPE

Data type : Data type of a variable is the set of values that the variable can take.
data types in C include int, char, float, and double.

Abstract : The word ‘abstract’ in the context of data structures means


considered apart from the detailed specifications or implementation

It is the act of representing essential features without including background details


•It provide Abstraction- Hiding details from the user

•ADT are like user defined data type which define operations on values using
Functions without specifying what is there inside the functions and how operations
are performed

Ex: stack ADT


Algorithms
Algorithm to add two numbers

Step 1: Input first number as A


Step 2: Input second number as B
Step 3: SET SUM = A+B
Step 4: PRINT SUM
Step 5: END

Algorithm to print the first 10 natural number


Algorithm to test for equality of two number
Write an algorithm to print the grade obtained by a student using the
following rules.
Inserting an Element in an Array

#include<stdio.h>

#include <conio.h>
int main()
{
int i, n, num, pos, arr[10];
clrscr();
printf("\n Enter the number of elements in the array : ");
scanf("%d", &n);
for(i=0;i=pos;i––)
arr[i+1] = arr[i];
arr[pos] = num;
n = n+1;
printf("\n The array after insertion of %d is : ", num);
for(i=0;i<n;i++)
Printf(“\n arr[%d]=%d", i, arr[i]);
getch();
return 0;
}
Write a program to delete a number from a given location in an array

You might also like