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

Datastructurespart 2

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

Datastructurespart 2

Data structure all material
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Data Structures and Algorithms

Prepared By
Asst.Prof.Deepali P.Pawar

Referred By

Iinkin.com,bhavnakhivsara.wordpress.co
mtutorialspoint.com
What is Data And Information?
What is Data And Information
What is Data Structures?
 Data Structure: a data structure
is a particular way of storing and
organizing data in a computer so that
it can be used efficiently.
 Data structure is a particular way of
storing and organizing information in
a computer so that it can be
retrieved and used most productively.
What is Data Structures?
 Data structures are used in almost
every program or software system.
Data Objects
 Refer to a run time grouping of one or more
pieces of data in virtual computer.
 It is container for data values –a place where

data values may be stored or later destroyed


 Program Defined
 System defined-virtual computer uses for house

keeping.These house keeping data structures


are automatically generated and destroyed.
Ex-sysyem defined data objects are run time
stacks,file buffers,sub program activation
records.
Need of Data Structures?
Data structures organize data
 more efficient programs.
More powerful computers  more complex
applications.
More complex applications demand more
calculations.
Complex computing tasks are unlike our
everyday experience.
Classification s of Data Structures
 Primitive and Non-primitive
 Linear & Non-Linear
 Static & Dynamic
 Persistent & ephemeral
Classification s of Data Structures
Types of Data Structures
Arrays
 Declaration of arrays

type arrayName [ arraySize ];

Ex-double balance[10];
Arrays
 Initializing Arrays

Ex-double balance[5] = {1000.0, 2.0, 3.4, 7.0,


50.0};
If you omit the size of the array, an array just
big enough to hold the initialization is
created. Therefore, if you write −

Ex-double balance[] = {1000.0, 2.0, 3.4, 7.0,


50.0};
Arrays
 Initializing Arrays

Ex-double balance[5] = {1000.0, 2.0, 3.4, 7.0,


50.0};
If you omit the size of the array, an array just
big enough to hold the initialization is
created. Therefore, if you write −

Ex-double balance[] = {1000.0, 2.0, 3.4, 7.0,


50.0};
Arrays
 Initializing Arrays

 You will create exactly the same array


as you did in the previous example.
Following is an example to assign a
single element of the array −
Ex-balance[4] = 50.0;
Arrays
 Shown below is the pictorial
representation of the array:
Accessing Array Elements

 double salary = balance[4];


#include <stdio.h>
int main ()
{
Ex-Arrays
int a[10],i,size;

printf(“\nhow many no of elements u want to scan”);

scanf(“%d”,&size);

printf(“\nEnter the elements in the array”);

for(i=0;i<size;i++)
{
scanf(“%d”,&a[i]);

} //end for

for(i=0;i<size;i++)
{
printf(“The array is %d”,a[i]); //Displaying Array

} //end for

return 0;
Output will be

1
2
3
4
5
Multi-dimensional Arrays in C

 type name[size1][size2]...[sizeN];
Two-dimensional Arrays in C

 multidimensional array is the two-


dimensional array
 type arrayName [ x ][ y ];
Two-dimensional Arrays in C
 Initializing Two-Dimensional Arrays

int a[3][4] = { {0, 1, 2, 3} , /*


initializers for
{4, 5, 6, 7} ,
{8, 9, 10, 11} /* initializers
for row
/* initializers for row indexed by 2 */ };
 Accessing Two-Dimensional Array
Elements

int val = a[2][3];


Three-dimensional Arrays in C

 For example, the following


declaration creates a three
dimensional integer array −

 Ex-int threedim[5][10][4];
Passing Arrays as Function
Arguments in C

 void myFunction(int param[10])


{...
//Statement Excution
}
Passing Arrays as Function
Arguments in C

Formal parameters as an unsized


array −
void myFunction(int param[])
{..
//Statement Execution
.}
Primitive
Primitive
Primitive and Non-primitive
 NON-PRIMITIVE DATATYPES
The data types that are derived from primary
data types are known as non-Primitive data types.
These data types are used to store group of values.

 The non-primitive data types are


 Arrays
 Structure
 Union
 linked list
 Stacks
 Queue etc
Static and Dynamic
 Static & Dynamic
Static(Array) Vs Dynamic(List)
 Static & Dynamic
Persistent & ephemeral
 Persistent & ephemeral
 persistent data structure is a
data structure that always preserves
the previous version of itself when it
is modified. Such data structures are
effectively immutable, as their
operations do not (visibly) update the
structure in-place, but instead always
yield a new updated structure.
Persistent & ephemeral
 A data structure is partially
persistent if all versions can be
accessed but only the newest version
can be modified. The data structure
is fully persistent if every version
can be both accessed and modified.
ephemeral
 . Structures that are not persistent
are called ephemeral.
 Data structures changes over
time.
Types of problems

 A well-defined problem is one that has a clear


goal or solution, and problem solving
strategies are easily developed. In contrast,
 poorly-defined problem is the opposite. It's
one that is unclear, abstract, or confusing,
and that does not have a clear problem
solving strategy.
 routine problem is one that is typical and has
a simple solution. In contrast,
 non-routine problem is more abstract or
 subjective and requires a strategy to solve.
Problem Solving Stretegies
 The first strategy you might try when solving a
routine problem is called an algorithm.
 Algorithms are step-by-step strategies or
processes for how to solve a problem or
achieve
a goal.
 Another solution that many people use to solve
problems is called heuristics. Heuristics are
general strategies used to make quick, short-cut
solutions to problems that sometimes lead to
solutions but sometimes lead to errors.
 Heuristics are based on past experiences.
Problem Solving Stretegies
 Properties of algorithms:


 Input from a specified set,
 Output from a specified set (solution),
 Definiteness of every step in the
computation,
 Correctness of output for every possible
 input,
Finiteness of the number of calculation steps,
 } Effectiveness of each calculation step and

You might also like