A979968895 - 21482 - 28 - 2020 - Ds 1-Basic Data Structure
A979968895 - 21482 - 28 - 2020 - Ds 1-Basic Data Structure
A979968895 - 21482 - 28 - 2020 - Ds 1-Basic Data Structure
• Data structures are the basis of the programming tools. The choice of data
structures should provide the following:
1. The data structure should satisfactorily represent the relationship between the
data elements.
2. The data structure should be easy so that the programmer can easily process the
data.
Classification of Data Structures
• Linear: The values are arranged in a linear fashion. E.g. Arrays, Linked Lists, Stacks,
Queues etc.
• Non-Linear: The values are not arranged in an order. E.g. Tree, Graph, Table etc.
• Homogeneous: Here all the values stored are of same type e.g. arrays
• Non- Homogeneous: Here all the values stored are of different type e.g. structures and
classes.
• Static:They're essentially fixed-size and often use much space E.g. Array
Basic Notations
Algorithmic Notations:
Finite step by step list of well-defined instructions for solving a particular problem.
Formal presentation of the Algorithm consists of two parts:
1. A paragraph that tells the purpose of an algorithm. Identifies the variables which occur in the algorithm
and lists the input data.
2. The list of the steps that is to be executed.
Some conventions used in Algorithms:
Steps, Control and Exit ( All statements are numbered, Go to and Exit)
Input and output (Read: variable names, Write: Messages and/or variable names)
Procedure
Basic Notations
Control Structures:
-----
[Endif]
• If (condition) , then:
-----
Else :
-------
[ Endif]
• Multiple If (condition), then : -----
Elseif : -----
Else :
------
[Endif]
Primitive Non-Primitive
Data Structures Data Structures
• Integer Linear Non-Linear
• Real Data Structures Data Structures
• Character • Array • Tree
• Boolean • Stack • Graph
• Queue
• Linked List
Data Structure Operations
Data Structures are processed by using certain operations.
1.Traversing: Accessing each record exactly once so that certain
items in the record may be processed.
A space-time or time-memory tradeoff is a way of
solving a problem or calculation in less time by using
more storage space (or memory), or by solving a problem
in very little space by spending a long time.
time space tradeoff
As the relative costs of CPU cycles, RAM space, and hard
drive space change—hard drive space has for some time
been getting cheaper at a much faster rate than other
components of computers—the appropriate choices for
time space tradeoff have changed radically.
}
Example 11
while(n>=1)
{
n=n-20;
n=n+5;
n=n-30;
}
Example 12
while(n>=1)
{
n=n/2;
}
Example 13
while(n>=1)
{
n=n/2;
n=n/3;
}
Example 14
while(n>=1)
{
n=n-2;
n=n/2;
}
Example 15
for(int i = 1; i < n; i *= 2) {
cout << i << endl;
}
There are n iterations, however, instead of simply
incrementing, 'i' is increased by 2*itself each run.
Thus the loop is log(n).
Example 16
for(int i = 0; i < n; i++) { //linear
for(int j = 1; j < n; j *= 2){ // log (n)
//do constant time stuff
}
}
Ans: n*log(n)
Example 17
while(n>2)
{
n=√n;
}
Example 18
while(n>2)
{
n=n2;
n=√n;
n=n-2;
}
Example 19
x=y+z;
}
Example 20
Main()
{
While(n>2)
{
n=√n;
n=n/2;
n=n-2;
}
}
Example 21
main()
{
While(n>1)
{
n=n/2;
a=a+b;
}
}
Example 22
main()
{
While(n>=1)
{
n=n/2;
}
}
Example 23
main()
{
While(n3>1)
{
n=n-1;
a=b+c;
X=x+y;
}
}
Example 24
main()
{
for(i=1;i<=n;i=3*i)
{j=1;
While(j<=n)
{
j=j*3;
}
}
}
Example 25
main()
{
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
for(k=1;i<=143;k++)
{
x=y+z;
}
}
}
}
Comp 122
Thank You