Psa Notes
Psa Notes
FREQUENCY
start n=0
{
for (i=0,i<=n,i++)
{
print "PSIT" N+1
FOR(J=0, J<=N , J++) n^2 + 3n+2
Print "WORLD" n^2+2n+1
}
}
---------------------
2n^2+7n+6
---------------------
(2)
start
{
for(i=0,i<=n, i++) n+2
{
print"PSIT" n+1
for(j=1, j<m, j++) (n+1)m = nm+m
Print"WORLD" (n+1)(m-1) = nm+m-n-1
}
}
---------------------
2nm+2m+n+2
---------------------
big[O] = n^2 or m^2
(3)
start
{
for(i=1,i<n, i+3 )
NOTE: PROVIDED n IS DIVISBLE BY 3
print "PSIT"
}
(4)
start
Value for i is true = 0,03,6,9,12 so n=9
{
for(i=0,i<=n, i+3 ) n/3+2
print "PSIT" n/3+1
}
---------------------
2(n/3)+3
---------------------
(5)
start
NOTE: THIS IS INFINITE LOOP
{
for(i=0,i<=n, i*2 )
print "PSIT"
} ---------------------
---------------------
(6)
start
i=(1,2,)t, (4 )f ; n=2 i n
{
i=(1,2,4,)t ; (8)f ;n=4 2^1 2
for(i=1,i<=n, i*2 ) (k+1)+1
i=(1,2,4,8)t;(16)f ;n=8 2^2 4
print "PSIT"
. .
} ---------------------
(k+1)+1 . .
(log (base 2) n )+2
-------------------------------------------------------------
---------------------
2^k n n=2^k
BIG[O]=log (base 2) n
[ k= log (base 2) n]
(7)
start
{
for(i=1,i<n, i*2 ) log (base 2) n +1
print "PSIT" log (base 2) n
}
----------------------------
f(n)= 2log (base 2) n+1
----------------------------
BIG[O]=log (base 2) n
(8)
start
{
for(i=1,i<n, i*3 ) log (base 3) n +1
print "PSIT" log (base 2) n
}
---------------------------------------
f(n)= 2log (base 3) n+1
----------------------------------------
BIG[O]=log (base 3) n
REVISION OF OPERATORS
1)Assignment
2)Arithmetic
i) +
ii) –
iii) *
iv) /
v) %(modulus operator )
3)Increment and decrement
i) ++
ii) --
4)Relational
a) <
b) >
c) >=
d)<=
e) ==
f) !=
5)Logical(gates)
a) &&(and)
b) ||(or)
c) !(not)
6)Bitwise
a) &(and)
b) |(or)
c) ^(xor)
d)~(not)
e) <<(left shift)
f) >>(right shift)
7)Other
a) ?(conditional operator)
b) Sizeof( )
c) ,(comma)…………………………………etc
How to solve
i. First solve pre
ii. Then expression
iii. Then post
Logical operator
&&truth table
A B A&&b
0 0 0
0 1 1
1 0 1
1 0 1
Ex
Main()
D= a&b;
E=a|c
F= a^b;
}
<<LEFT SHIFT
Syntax: value<<position
Eg: int a 23<<2
Ans: a=92
0 0 0 0 0 0 0 0 0 0 0 0 10 11
SYNTAX
VALUE>>Position
Ans: a=5
0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1
Msb gives (-ve\+ve)
Date – 26/12/2023
~(BITWISE NOT)
A= - 24
0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1
(For binary magnitude)
1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0
111111111101000
= 24
2 (binary)- 0000000000000010
QUES: main()
int a ,b ;
a~ =23
B=~-7810
printf(a=%d, b=%d”,a,b)}
ans:
a = -24 ; b= +7809
{+ve ho to ek no increase krke sign change and –ve ho to decrease karke sign change }
#Branching statement
conditional branching
looping
date- 29/12/2023
program- count 0
PSEUDO CODE :
1. START
2. INPUT:N
3. INTILIAZE COUNT FROM 0
#jump statement in c
1. Break
2. Continue
3. Go to
4. Return
# break statement
Jumpstatement- used within switch or within
loop body
Whenever break statement is encountered within
loop body will be terminated to out at that line
will be transferred to out of the nearest and
closing loop.
Syntax-
While(……)
{
1. ….
2. …..
3. …
4. If(condition)
break
5. …
6. …
IT IS JUMPM STATEMENT
Syntax –
While(…)
1. {
2. ..
3. .
4. .
5. .
6. .
8.
9.
10…
#go to statement
Jump statement
Goto statement jump the control to a specified label
Label is an identifier (name) which specifies the phase
where jump is to be done
Syntax:
1. __________________
2. _____________________ [backwardjump]
3. __________________
4. ___________
5. If(condition)
6. Goto label ;
7. ____________
8. ____________
1. ___________________
2. ______________
3. ______________
4. If(condition)
Int main()
Int n,I,fact;
Scanf(“%d,&n);
I=1;
Fact=1;
X:
Fact=fact*1;
I++;
If(i<=n)
Goto x ;
Printf(“%d, fact),
Return 0;
9/01/2024
#perfect number
= 1+2+3=6
ans:
1. start
2. Use for loop
If i<n; i++
If(n%i==0)
Sum=sum+I;
Print that the number entered is entered is a
perfect number
Date :
Int main()
{ CALLING FUNCTION
Int n= 5, a;
Formal
a=factorial(n);
Called parameter
printf(“%d,a);
function
return 0;
Int factorial (int n )
Int I , f=1;
f=j*I;
Return 0;
FUNCTION
User defined
Library or switching function
function
1) Function declaration(prototype)
2) Function definition(body or logic)
3) Function – call(use- point)
FUNCTION DECLARATION
Function header
i) Return type
ii) Function name
iii) Argument
Semi-colon (;)
Return type
FUNCTION DEFINITION
Int function name( type, arg 1, type, )
{
Int a , b, sum = 0
.
.
.
. Body
.
Return 0 ;
}
Function call
Syntax
o Write a program to divide a number into sum of two prime number print all the possibilities……
#include<stdio.h>
#include<math.h>
Int prime(int n)
{
Int i;
For(i=2; i<=sqrt(n); i++)
{
If (n%i==0)
Return 0;
}
Return1;
Int main()
{
Int a ,b,i;
Printf(enter the range );
Home assignment
Pseudo code
1 Start
2 Input: num
3 Copy n num
4 Initialize sum 0
5 While (num!=0)
Do
D num%10
F last factorial d)
Sum sum =!f
Num sum/10
Endloop
6 Check if (sum==n)
7 Else
Print(“not a strong no”);
RECURSION
IT is a top down approach. It is based on a divide and conquer
approach in which a big problem will be broken into similar type
of problem but in smaller size until and unless we reach the base
case. Once we reaches the base case then solution are getting
combined and then back to the previous stage and the finally we
got the solution of our original problems. Every recursive solution
consist of two cases:
Types of recursion
1 Direct recursion: when a function calls itself within its body
2 Indirect recursion: when function calls itself again through
another function.
3 Non- tail recursion: if there are some pending task which will be
evaluated after the return of recursive call of the function.
4 Tail recursive: if there is no pending task, after the return of
recursive call of the function.
1. Direct recursion.
Eg int fun (int n)
{
If(n==0)
Return 1;
Else
{
Int a = function(n/2);
Int s = a+n;
Return s;
}
}
INDIRECT FUNCTION
C – MEMORY LAYOUT
Date – 16 February 2024
Searching technique
1. Linear search
2. Binary search
Linear search
Start
Input n
Input array : arr
Input : key
Initialize found
While ( i<n)
If (arr [i]== key)
Print: ”key found at index =”i
found 1
break the loop
I i+1
If(found==0)
Print: ”key is not found”
End
Time complexity
1. Best case