Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
28 views15 pages

Data Structure

Data structures are essential for efficiently storing and managing data in applications, especially as complexity and data volume increase. Learning data structures and algorithms helps address common issues like slow data searches, processor limitations, and handling multiple requests. The document also outlines algorithmic notations, control structures, variable naming rules, and characteristics of algorithms.

Uploaded by

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

Data Structure

Data structures are essential for efficiently storing and managing data in applications, especially as complexity and data volume increase. Learning data structures and algorithms helps address common issues like slow data searches, processor limitations, and handling multiple requests. The document also outlines algorithmic notations, control structures, variable naming rules, and characteristics of algorithms.

Uploaded by

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

Data Structures

Introduction:
 Data Structures are the programmatic way of storing data so that data can be
used efficiently. Almost every enterprise application uses various types of data
structures in one or the other way.
 Why to Learn Data Structure and Algorithms?
As applications are getting complex and data rich, there are three
common problems that applications face now-a-days.
• Data Search − Consider an inventory of 1 million(106) items of a store. If the
application is to search an item, it has to search an item in 1 million(10 6) items
every time slowing down the search. As data grows, search will become slower.
• Processor speed − Processor speed although being very high, falls limited if
the data grows to billion records.
• Multiple requests − As thousands of users can search data simultaneously on
a web server, even the fast server fails while searching the data.
Algorithmic notations:

 1. Format Conventions
The following subsections summarize the basic format conventions used in
formulation of algorithms.
a. Name of the algorithm:Every algorithm is given an identifying name. The
algorithm name should be in capital letters.
b. Introductory Comment: The algorithm name is followed by the brief
description of task the algorithm performs. The description gives names and types of
the variable used in the algorithm.
c. Steps: Actual algorithm is made up of sequence of numbered steps
beginning with the phrase enclosed in the square brackets that describes that steps.
Following this is an ordered sequence of statements which describe action to be
executed or tasks to be performed
d. Comments: Algorithm steps terminates with a comment enclosed in
parenthesis which helps better understanding of the step .
Statements and Control Structures:
The following sub sections summarize the type of statement and control structures available in
algorithmic notation
a. Assignment Statement:
The assignment statement is indicated by placing the arrow () between the RHS of the
statement and the variable receiving the value.
LHS  RHS
Temp  A // assigning A to Temp
AB // assigning B to A
B  Temp // assigning Temp to B
i  0 , j  0 and k  0
b. If statement:
The if statement has one of the following two forms:
General forms:
1. if condition if(condition){
then //true
}
 Example
int main(){
int i = 10;
if(i > 15){
cout<<“10 is less than 15”;
}
cout<<“I am Not in if”;
}
2. If condition if(condition){
then //true
--------------- }else{
--------------- //false
else }
--------------
--------------
 Example
main(){
int i = 20;
if(i < 15 ){
cout<<“i is smaller than 15”;
}else{
cout<<“i is greater than 15”;
}
}
c. Case Statement: the case statement is used to select one expression from several
alternatives.
General form of case statement
Select case(expression)
Case value 1:
Case value 2:
.
.
Case value N:
Default:
The expression is evaluated and its value is compared, to that of all of the cases. The case
that matches is branched to if the expression value does not match that of any case then a
branch is made to default case if there is one or to the next step if there is not.
 Example
int day = 4;
switch (day) {
case 1:
cout << "Monday";
break;
case 2:
cout << "Tuesday";
break;
case 3:
cout << "Wednesday";
break;
case 4:
cout << "Thursday";
break;
case 5:
cout << "Friday";
break;
case 6:
cout << "Saturday";
break;
case 7:
cout << "Sunday";
break;
default:
cout<<“Invalid day”;
}
 d. Repeat Statement:
For easy control of iteration( looping) a repeat statement as been provided. This
statement has one of the forms:
1.Repeat for INDEX = sequence
2. Repeat while logical expression

The type 1 is used when a step is repeated for counted number of times. INDEX is
variable used as a loop counter.
Example:
for(int i = 1; i < 5;i++){
cout<<“value of i is ”<<i<<endl ;
}
Type 2 is used to repeat a step until a given logical expression is false. The evaluation
and the testing of the logical expression is performed at the beginning of the loop.
Example:
int i = 1
while( i < 5 ){
cout<<“hello world”<<endl;
i++;
}
 f. Goto and Exit loop Statements
Go to and exit loop statements are conditional statements, these
causes unconditional transfer of control.
Go to statement:
This statement causes unconditional control transfer to the step
referenced, Regardless of the other statements.
Example:
Label :
----
----
----
Go to label.
Exit statement:
Exit statement causes the immediate termination the control.
Example:
if I <10
Exit ( Causes the loop to exit when I value is read as less than 10)
Variable Names
 A variable is an entity that possess the value and its name is chosen to be
meaningful of the value it holds.

Rules for declaring Variable Names


I. All variable names must begin with a letter of the alphabet or an underscore(_) or $.
II. After the first initial letter, variable names can also contain letters and numbers.
III. Variable names are case sensitive.
IV. No spaces or special characters are allowed.
V. You cannot use a C++ keyword (a reserved word) as a variable name.

 Arrays
Array elements are denoted by ARRAY [DIM1,DIM2,...DIM N] , where ARRAY is the
array name and DIM1 thru DIM N are its subscripts. Subscripts are enclosed in square brackets that
denotes the location of array elements.
Arithmetic Operations and Expressions
 Operator is the symbol it operates on operands
 Operands are expression or values on which an operator operates or works
Example
5 + 4 , a + b , 3++
 Unary operators operate on only one operands
Example
a++, b--, 2++, 5—
 A binary operator operate on two operands
Example
a + b, c – d, A * B

 Expression is valid combination of operators and operands.


 Arithmetic expression formed using arithmetic operators and character or numeric
operands.
 Relations and Relational Operators:
The relational such as < ,> ,<=,>= ,!=. Relation between variables and expressions will
be considered if the variables have been assigned some value.
Example : Z<=9/3+2 (If Z=10 then 3+2(RHS) 10<=5)
A relation evaluates a logical expression , ie, it has one of two possible values True or False.
 Logical Operations and Expressions:
The Algorithmic notation also includes the standard Logical operators such as:
__________________________________________
OPERATOR NOTATION
___________________________________________
Negation NOT
Logical And AND
Logical Or OR
___________________________________________
 Operator’s Preccedence
__________________________________
Precedence Operators
__________________________________
1. parenthesis
2. arithmetic
3. relational
4. logical
Algorithm and it’s characteristics
 Algorithm is a step-by-step procedure, which defines a set of instructions to be
executed in a certain order to get the desired output.
Characteristics
I. Unambiguous − Algorithm should be clear and unambiguous. Each of its
steps (or phases), and their inputs/outputs should be clear and must lead to
only one meaning.
II. Input − An algorithm should have 0 or more well-defined inputs.
III. Output − An algorithm should have 1 or more well-defined outputs, and should
match the desired output.
IV. Finiteness − Algorithms must terminate after a finite number of steps.
V. Feasibility − Should be feasible with the available resources.
VI. Independent − An algorithm should have step-by-step directions, which should
be independent of any programming code.
Classification of Data Structure
THANK YOU

You might also like