0% found this document useful (0 votes)
11 views25 pages

DS-Unit I

Uploaded by

Sahil Memane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views25 pages

DS-Unit I

Uploaded by

Sahil Memane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Data may be organized in many different ways : the

logical or mathematical model of a particular


organization of data is called a data structure. The
choice of data structure needs following two
considerations
1. It must be rich enough in structure to mirror the
actual relationships of the data in the real world.
2. The structure should be simple enough that one can
effectively process the data when necessary.
1)Correctness : DS implementation should implements
interface correctly
2) Time complexity:- running time or execution time
must be as small as possible
3) Space Complexity:- Memory usage of a data structure
operation should be as little as possible
Need for Data Structure
 Data Search
 Processor Speed
 Multiple requests
 Efficient
Abstract Data Type(ADT)
 The abstract Date type is a triple of D –Set of domains,
F- Set of functions, A – Axioms in which only what is
to be done is mentioned but how is to be done is not
mentioned.

ADT= Type +function names + behavior of each function


Operations on ADT
Create , Display, Insertion ,Deletion,Modification
Review Questions
1. Define the term data type, data object and data
structure. Give an example for each term.
2. Describe the need for data structure
3. Explain the concept of ADT with suitable example.
4. What is ADT? Write ADT for an array.
Types of Data structure
Fig:- Classification of Data Structure
Data structure

Primitive Data structure Non primitive


Example: int,char,float Data Structures

Linear Data Structures:-


Array ,Stack, Queue, Non Linear Data
Linked List Structure:- Trees,
Graphs
Review Questions
1. Define Data Structure. Enlist ant two types of non
linear data structure.
2. Define primitive and nom primitive data structure.
Algorithm Complexity
The efficiency of an algorithm can be decided by
measuring the performance of an algorithm by
computing two factors
1) Time complexity:- Amount of time required by an
algorithm to execute.
2) Space complexity:- Amount of storage required by an
algorithm.
Review Questions
1 ) Explain time and space complexity with example.
2) What is complexity of an algorithm? Describe time
and space complexity.
3) Define complexity and classify it.
Operations on Data Structures
1. Traversing
2. Searching
3. Insertion
4. Deletion
Review Questions
1. Describe any four operations on data structure.
2. Enlist the operations on data structure.
The simplest type of data structure is a linear (or one-
dimensional) array. By a linear array, we mean a list of a
finite number n of similar data elements referenced
respectively by a set of n consecutive number, usually 1, 2,
3,…, n. If we choose the name A for the array, then the
elements of A are denoted by subscript notation
a1, a2, a3,…, an
or by the parenthesis notation
A(1), A(2), A(3),…, A (N)
Or by the bracket notation
A[1], A[2], A[3],…, A[N]

Regardless of the notation, the number K in A[K] is called a


subscript and A[K] is called a subscripted variable.
STUDENT

John Brown

Tom Jones

Alan Smith

Mary Reed

M. Singh
P. Mathur
Dept.
1 2 3 4
Store

1 2872 805 3211 1560


2 2196 1223 2525 1744
3 3257 1017 3686 1951
… … … … …
2618 931 2333 982
28
Customer Salesperson
1 Adams Smith
2 Brown Ray
3 Clark Jones
4 Drew Ray
5 Evans Smith
6 Farmer Jones
7 Geller Ray
8 Hill Smith
9 Infeld Ray
Customer Pointer Sales Persons
1 Adams 3 Jones 1
2 Brown 2 Ray 2
3 Clark 1 Smith 3
4 Drew 2
5 Evans 3
6 Farmer 1
7 Geller 2
8 Hill 3
9 Infeld 2
Salesperson Pointer

1 Jones 3, 6
2 Ray 2, 4, 7, 9
3 Smith 1, 5, 8
Customer Link Sales Persons Pointer
5 Jones 3 1
1 Adams
4 Ray 2 2
2 Brown
3 Clark 6 Smith 1 3
4 Drew 7
5 Evans 8
6 Farmer 0
7 Geller 9
8 Hill 0
9 Infeld 0
Algorithm: It is a finite step-by –step list of well defined instruction for solving the particular problem
•Identifying number
•Step, control, exit
•Comments
•Variable names
•Assignment statement
•Input Output
•Control structures
•Sequence logic or sequential flow
Algorithm flow chart equivalent
.
.
Module A Module A
.
.
Module B Module B
.
.
Module C Module C
Fig.Sequnece logic

•Selection logic or conditional flow


•Iteration logic or Reparative flow
•Selection logic or conditional flow
•Single Alternative
If condition, then:
[Module A]
[End of If structure.]
•Double Alternative
If condition, then:
[Module A]
Else:
[Module B]
[End of If structure.]

•Multiple alternative
If condition, then:
[Module A1]
Else: If condition(1), then:
[Module A2]
Else: If condition(2), then:
[Module A3]
Else: [Module B]
[End of If structure.]

•Iteration logic or Reparative flow


Algorithm(Traversing a linear array) LA is a linear array with lower
bound LB and upper bound UB. This algorithm traverses LA
applying an operation PROCESS to each element of LA.

1. [Initialize counter] Set K:= LB


2. Repeat Steps 3 and 4 while K<= UB
3. [Visit element] Apply Process to LA[K]
4. [Increment counter ] Set K:=K+1
[End of Step 2 loop ]
5 . Exit.
1)Write a C program which perform traversing operation
 Let LA is a linear array(unordered ) with elements
#include<stdio.h>
Void main()
{
int LA[]={2,4,6,8,9};
int i,n=5;
printf(“The array elements are:\n”);
For(i=0;i<n;i++)
{
print(“ LA[%d] = %d \n”,i, LA[i);
}
}
Output
The array elements are:
LA[0]=2
LA[1]=4
LA[2]=6
LA[3]=8
LA[4]=9
Let A be a collection of data elements in the memory of computer. Inserting
refers to the operation of adding another element to the collection A and
deleting refers to the operation of removing one of the element from A.
Algorithm(Inserting into a linear Array)
INSERT(LA,N,K,ITEM)
LA is linear array with N elements and K is a positive integer such that K<=N.
This algorithm inserts an element ITEM into the K th position in LA .
1.[Initialize counter ] Set J:= N.
2. Repeat Steps 3 and 4 while J>=K
3.[ Move J th element downward] Set LA[J + 1] := LA[J]
4. [Decrease counter ] Set J:= J – 1
[ End of step 2 loop ]
5. [Insert item ] Set LA[K] := ITEM.
6. [Reset N] Set N:=N +1
7. Exit.
Deletion at the end is simple task but deleting an element somewhere in the
middle of the array would require that each subsequent element be moved one
Location upward .

Algorithm ( Deleting form a linear Array) DELETE(LA,N,K,ITEM)


LA is a linear array with N elements and K is a positive integer such that
K<= N . This algorithm deletes the Kth element from LA.
1. Set ITEM := LAK[K]
2. Repeat for J = K to N – 1
[ Move j+1 th element upward] Set LA[J] = LA [J + 1 ]
3. [Reset the number N of elements in LA] Set N:= N – 1.
Review Questions
1)Write a C program which perform traversing operation
2 ) Write a C program to search a given element within
defined array list
3)Write a C program to insert new element to existing
array
4)Write a C program to delete an element form the
specified location from array list.
5)Write a c program to sort the array in an ascending
order

You might also like