stack,queue, linked list,recurrsion
stack,queue, linked list,recurrsion
linked list
Types of data-
two types
1)Numerical data
2)Alphanumerical data
These two data types specify the nature of data item that undergo certain
operations
Integers, floating point- numerical data type
Strings constants, character constants- alphanumerical data type
Data structures are building blocks of program.Selection of data structure stress on two main
things
1.The data structure must be rich enough in structure to reflect the real relationship
existing between the data
2. The structure should be simple so that we can process data effectively, whenever required
Array Lists
Set consisting of fixed no of data Ordered set consisting of a variable
items number of data items
No insertion and deletion Insertion and deletion operations
operations performed performed
Example
A file consisting of student information
Reg no, name , branch, percentage
A file consisting of employee of an organization
Emp_no, emp_name,designation, basic_salary, HRA, CCA, gross_salary
Files are always stored in secondary storage devices such as floppy disks, hard
disks
Files are accessed sequentially or directly
Stack
Representation of stack
Operation of stack
Algorithms
Applications of stack
Infix , postfix , prefix
Conversion from infix to postfix
Evaluation of postfix expression
LIFO
Stack create-----Top changes-------it is most accessible element
base remains fixed-------least accessible element
Examples of stack
1. A man carrying suitcase on head
2. A stack of plates in cafeteria
3. A biscuits in biscuit bundle
Static representation-
Is array representation
Stack is created by statement
Int stack [MAXSIZE]
We can use macro
# define MAXSIZE 10
# include <stdio.h>
funct2( int x)
main ()
{
{
int y,z;
int i=10,j;
y=x+10;
j=funct1(i);
z=funct3(y);
printf(%d”,j);
return(z);
}
}
funct1( int k)
funct3(int a)
{
{
int m=20,n;
int b;
n= funct2(m);
b= a* 5;
return(n* k)
return(b);
}
}
Jayashree M Oli ECE department
Jayashree M Oli ECE department
Infix , postfix,prefix expression
An expression in any programming language is combination of operands and
operations
Operands may be of int,float,double
Operations may be of arithmetic,logical,bitwise etc
Here we study arithmetic operations
Three ways
1. infix
It is the form of an arithmetic expression in which we fix place the arithmetic
operator in between the two operands
Example
A + B, A-B, A*B, A/B----------------A,B are operands
(A+B)-C, A+(B *C), (A/B)+C--------------A,B,C ARE operands
Parentheses impose a precedence of operation, i.e order of operation
Jayashree M Oli ECE department
Post fix
it is form of arithmetic expression in which we fix arithmetic operator after its
two operands
infix Prefix
A+B +AB
A-B -AB
A*B *AB
A/B /AB
infix Prefix
A+B*c
A+b-c
(3+4)*(8-9)
x/y^z+A
+* AB / CD---------------pre
Post index
AB * CD / + ------------post
(A+B) * (C-D)/E-F
A^ B ^ C * D
Algorithm
Scan the infix expression from left and right
a) If scanned symbol is left parenthesis , push it onto the stack
b) If scanned symbol is an operand, then place directly in the postfix expression
c) If scanned symbol is right parenthesis , then pop all the items from the stack and
place them in postfix expression till we get matching left parenthesis
d) If scanned symbol is an operator ,then go on removing all the operators from the
stack and place them in postfix expression . If and only if the precedence of the
operator which is on the top of the stack is greater than or equal to the
precedence of scanned operator else push scanned operator on stack
Jayashree M Oli ECE department
Recursion
Definition
It is powerful programming concept
It helps the programmer to carry out certain task repeatedly for a known
number of times or as long as desired condition is true
It is modular programming technique
Recursion is the name given to the ability of function to call itself , until
desired condition is satisfied.
There must be an exclusive stopping condition statement within body of a
recursive function . Otherwise function enters infinite loop.
Function_1
Function_1( )
{
{
function_2( )
function_1( )
}
}
Function_2( )
{
function_1( )
Jayashree M Oli ECE department
#include <stdio.h>
Main ( ) Factorial of number
{
int n,f;
printf(“enter the number \n”)
scanf(“%d”, &n)
f=fact(n)
printf(“factorial of %d= %d\n”, n,f);
}
/* recursive function for factorial*/
Int fact(int m)
Output
{ Enter the number
int factor; 5
If (m=0) Factorial of 5=120
return(1)
Else
factor=m*fact(m-1);
Return(factor)
Jayashree M Oli ECE department
}
HW
Write a program to accept two positive integers and find their gcd using
recursive function
iteration recursion
Process of executing a statement Name given to technique of
or a set of statements repeatedly defining something in terms of
until some specified condition is itself
satisfied
Their will be stopping condition
Process involves four clear parts, within the body of the recursive
initialization,decisions, function
computation and updation
Worse as compared to iterative
More efficient in terms of memory
It is defined as a function to call
utilization and speed
and recall itself
For,while,do-while are used
Jayashree M Oli ECE department
queues
Definition
Representation
Operation
Algorithms
Circular queues
Double ended queues
10 20 30 40 50 60
Examples
Printing queue- multiple print job sent to printer
Time sharing computer system
Representation of queue
Two ways
1. Static(array)
2. Dynamic(linked list)
Jayashree M Oli ECE department
An array based representation of queue involves during a one dimensional
array of some specified size
The array representation of queue needs two indices: FRONT and REAR which
indicate position of front and rear ends
Declaration of array in C
Int queue[MAXSIZE]
Queue is name of array
MAXSIZE –no of elements
Once a queue with specified size is created then addition of new element at
the rear end and deletion of an element from the front end can be performed
Two indices to be maintained front and rear- helps in deleting and inserting
data items
Assumptions
Intial front=0;
Initial rear=0;
FRONT=REAR if the queue is empty
Definition
Operations
Front ( ), rear( ), enqueue( ), dequeue( )
Applications
Advantages and disadvantages
Definition-linked list
Components of a linked list
Representation of linked list
Types of linked list
Basic operations performed on linked list
Singly linked list
Doubly linked list
Circular doubly linked list
Linked representation of stacks and queues