Sei sulla pagina 1di 98

SEERLOGICA INFOTECH

BY

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

SEERLOGICA INFOTECH
Algorithm:- Step by step representation to performing any task is called algorithm.
Algorithm & flowchart for making a tea:
Begin
1.
2.
3.
4.
5.

End

Boil water.
Put tea power in the kettle.
Pour boiled water in the kettle.
Wait for three minutes.
Boil milk.
Put boiled milk in a cup.
6. Add sugar to the cup.
7. Empty the kettle in the cup.
8. Stir the cup with a spoon.

Begin

Boil Water

Put tea power in the kettle

Pour boiled water in the kettle

Wait for 3 minutes


Boil milk
Put boiled milk in a cup

Add sugar to the cup


Empty the kettle

Stir the cup with a spoon

End

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

SEERLOGICA INFOTECH
Steps to write an algorithm:
It is the step by step method of performing any task. When we breakup a big task
into smaller steps what we actually do is to create an algorithm. The steps in an algorithm
can be divided in three basic categories. They are
1. Sequence
2. Selection
3. Iteration
Sequence:
A Sequence is a series of steps that we can follow in any algorithm without any
break i.e.,
Unconditionally.
Begin
2. Take a utensil.
3. Take the utensil to the water tap.
4. Open the tap.
5. Fill the utensil with water.
6. Close the tap.
7. Put the utensil on the gas or in the oven.
8. Start the gas or the oven.
9. Wait until the water boils.
10. Switch off the gas or the oven.
End
Selection:
Selection involves makes a choice from multiple, available options. A selection
statement generally takes the form of

1. If
2.
Then
3. End-if
Eg:
1. If the guest wants tea.
2.
Then give him tea.
3.
Offer biscuits.
4. End-if

Begin
1. If the guest wants tea
2.
Then make tea.
3. End-if
4. Offer biscuits
End.
Offer biscuits to all guests

Begin
1. If the guest wants tea
2. Then make tea;
3. offer biscuits
4. End-if
End
Offer biscuits only to guests who want tea

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

SEERLOGICA INFOTECH
I. Compound conditions:
We combine two or more conditions in to a single compound condition (using the
words like and and/or or to join sentences.
1. Compound conditions with and:
1. If it is a weekday
2.
and it is 7 am or more
3.
and you are feeling ok
4. Then
5.
Take breakfast
6.
Go to work
7. End-if
2. Compound conditions with or:
1. If it is a weekday
2.
or work is pending
3.
or boss is angry
4. Then
5.
Take breakfast
6.
Go to work
7. End-if

II. Nested condition:- Putting a if with in another if forms a nested condition.


Eg 1.
1. If you are feeling ok
2.
Then go to work
3. Else
4.
If you have fever
5.
Then go to the doctor
6.
Else
7.
Just relax
8.
End-if
9. End-if
Eg 2.
1. If a>b
2.
Then If a>c
3.
Then choose a
4.
Else choose c
5.
End-if
6. Else if b>c
7.
Then choose b
8.
Else choose a
9.
End-if
10. End-if
Selecting the largest of three numbers using nested conditions

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

SEERLOGICA INFOTECH

III Testing and debugging:


We are checking to see if our algorithm gives the desired result, Hence we testing
the algorithm. A set of values of a, b and c that we use for testing (e.g. a=18, b=24,c=49) is
called as a test case as we test our algorithm for a possibility (or case) at a given time. A
group of test cases makes up the test data.
If for any one of such conditions, our algorithm gives an incorrect result, we say that
is a bug in the algorithm- it is another name for an error. The process of removing a bug
from an algorithm is called as debugging.

IV Indentation and Algorithm maintenance:


For every if statement there is a end-if statement, for every Begin statement there is
an end statement, writing end-if is exactly below if, end is exactly below begin & start
some sentences at beginning and some after leaving some spaces is called indentation.
Writing algorithms in indentation is very easy to understand & make changes very easily.
Writing the algorithms in indented form is called good maintenance of algorithms.

Iteration: A sequence of steps which are used repeatedly is called iteration.

(a) 1. Repeat
(b) 1. Do
2. Wait for two minutes.
2. Wait for two minutes.
minutes.
3. Until I arrive
3. While I do not arrive
4. Go to Movie
4. Go to Movie

(c) 1. While I do not arrive


2.
Wait for two
3. End-while
4. Go to Movie

Repeat-Until & Do-While (cases a & b) are essentially, first it do the steps then
check for the condition, While- End while(case) is differ from above, Because first checks
the condition then do the steps.

Type casting:
Type conversion
int i,j;
float k;
k = (float) i / j
(float)i is called type casting (we are converting integer to float)
(float) i / j
i is float, j is automatically converts into float (from int)
This is called type conversion.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

SEERLOGICA INFOTECH
Flowchart:- Representation of algorithm in graphical form is called Flowchart.

Flowchart Symbols & its uses


S. NO Symbols

Name

Purpose

Usage of symbol in flowchart

1.

Rounded Rectangle

2.

Parallelogram

Data

It is used for input or


output data

3.

Rectangle

Process

It is used to process the


data

4.

Rhombus

5.

Arrows

Flow of control

It is used to give flow of


given data

6.

Hexagon

Preparation

It is used for loops like


For, While, Do While

7.

Circle

Connector

It is used for connecting


lines

8.

Crossed Circle

9.

10.

------

Dotted Lines

Double Sided Rectangle

Terminal

Decision

Summing Junction

Flow of data

Predefined Process

It is used to start and stop

It is used to give condition

It is used for junctions

It is used to give Flow of


data in loops

It is used for Predefined


process like Macros

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

SEERLOGICA INFOTECH

Flowchart for Process of Compiling & Running a C Program


System Ready

Program Code

Enter Program
Source Program (.C)
Edit
Source Program

C
Compiler

Compile
Source Program

Syntax
Errors ?

System
Library

Yes

No
Object Code
Link with
System Library

(.OBJ)

Executable Object Code (.EXE)


Input
Data

Data Error

Execute
Object Code

Logic and
Data Errors
?

Logic Error

No Errors
CORRECT OUTPUT
Stop

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

SEERLOGICA INFOTECH
C Tokens
Tokens

Keywords
Identifiers
(Reserved words)
int, if
fact, avg

Constants

Operators

abc, A
Numeric

Integer

Special Symbols

+,^

{, #

Character

Real

1.05, 2.4e2
Decimal Binary Octal
(0-9)
(0,1) (0-7)
89, 187 01, 110 05, 017

Strings

Single
Character
A, 1

Multi
Character
ABC, $123

Hexa Decimal
(0-9, A-F)
1A, FF

Data Types
Data Types
User defined
typedef, enum

Derived
Structure, union
Integers

int

long

Primary (fundamental)

Real Numbers

short

Empty
null
Characters

float double long double

Data Type
Size(bytes) Size(bits)
Range
int
2
16
-32,768 to 32,767
signed int
2
16
-32,768 to 32,767
unsigned int
2
16
0 to 65,535
long
4
32
-2,147,483,648 to 2,147,483,647
signed long
4
32
-2,147,483,648 to 2,147,483,647
unsigned long
4
32
0 to 4,294,967,295
short
1
8
-128 to 127
signed long
1
8
-128 to 127
unsigned long
1
8
0 to 255
float
4
32
3.4E-38 to 3.4E+38
double
8
64
1.7E-308 to 1.7E+308
long double
10
80
3.4E-4932 to 1.1E+4932
char
1
8
-128 to 127
signed char
1
8
-128 to 127
unsigned char
1
8
0 to 255

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

char
Range (in 2 power)
-215 to 215-1
-215 to 215-1
0
to 216-1
-231 to 231-1
-231 to 231-1
0
to 232-1
-27 to 27-1
-27 to 27-1
0
to 2 8-1

-27
-27
0

to 27-1
to 27-1
to 2 8-1

SEERLOGICA INFOTECH
Operators
1.
2.
3.
4.
5.
6.
7.
8.

Arithmetic operators
Relational Operators
Logical Operators
Assignment Operator
Increment/Decrement Operators
Bitwise Operators
Conditional Operator
Special Operators

(+, -, *, /, %)
(<, <=, >, >=, ==, !=)
(&&, ||, !)
(=) (a=a+b => a+=b Shorthand notation)
(++, --) (a++, a-- => Post & ++a, a++ Pre)
(&, |, ^, >>, <<,~)
(Combination of ? : => c= a>b ? a+b : a-b)
(,(comma), sizeof())

Truth Tables
Logical Operators
Logical AND

Logical OR

A
B
A&&B
0
0
0
0
non zero
0
non zero
0
0
non zero non zero
1

A
B
A||B
0
0
0
0
non zero
1
non zero
0
1
non zero non zero
1

Logical NOT
A
!A
0
1
non zero 0

Bitwise Operators
Bitwise AND
A
0
0
1
1

B A&B
0
0
1
0
0
0
1
1

Bitwise Ex-OR
A^B=AB+AB
A B A^B
0 0
0
0 1
1
1 0
1
1 1
0

Bitwise OR
A B A|B
0 0
0
0 1
1
1 0
1
1 1
1
Bitwise NOT
Ones Complement

A ~A
0 1
1 0

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

SEERLOGICA INFOTECH
Operator Precedence & Associativity
Operator
( )
[ ]
+
++
-!
~
*
&
Sizeof
(type)
*
/
%
+
<<
>>
<
<=
>
>=
==
!=
&
^
|
&&
||
?:
=
*= /= %=
+= -=
&=
^=
|=
<<= >>=
,

Description
Function Call
Array element reference
Unary Plus
Unary minus
Increment
Decrement
Logical negation (Logical not)
Ones compliment (Bitwise not)
Pointer reference (indirection)
Address
Size of an object
Type cast (conversion)
Multiplication
Division
Modulus
Addition
Subtraction
Left shift
Right shift
Less than
Less than or equal to
Greater than
Greater than or equal to
Equality (Relational equal to)
Inequality (Relational not equal to)
Bitwise AND
Bitwise EX-OR
Bitwise OR
Logical AND
Logical OR
Conditional Operator (Conditional expression)

Associativity Rank
Left to right

Right to left

Left to right

Left to right

Left to right

Left to right

Left to right

Left to right
Left to right
Left to right
Left to right
Left to right
Right to left

8
9
10
11
12
13

Assignment operators

Right to left

14

Comma operator

Left to right

15

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

10

SEERLOGICA INFOTECH
Input Formats
Integer Numbers:
int
a,b,c,x,y,p,q,r;
printf(Enter three integer numbers);
scanf(%d %*d %d,&a,&b,&c);
printf(%d %d %d,a,b,c);
printf(Enter 2 4-digit numbers);
scanf(%2d %4d,&x,&y);
printf(%d %d,x,y);
printf(Enter 2 2-digit numbers);
scanf(%d %d,&a,&x);
printf(%d %d,a,x);
printf(Enter 9-digit number);
scanf(%3d %4d %3d&p,&q,&r);
printf(%d %d %d,p,q,r);
printf(Enter 2 3-digit numbers);
scanf(%d %d,&x,&y);
printf(%d %d,x,y);
Real Numbers:
float
x,y;
double p,q;
printf(Enter two values);
scanf(%f %e,&x,&y);
printf(%f %f,x,y);
scanf(%lf %lf,&p,&q);
printf(%lf %e,&p,&q);

1
1

2
3

3
-3577

6789 4321
67
89
44
66
4321 44
123456789
66
1234 567
123
89

456
123

12.3456
17.5e-2
12.345600
0.175000
4.142857142857 18.5678901234567890
4.142857142857 1.856789012346e+001

Strings:
char name1[15],name2[15],name3[15],char address[80];
printf(Enter a name);
scanf(%15c,name1);
123456789012345
printf(%15s,name1);
123456789012345r
printf(Enter a name);
scanf(%s,name2);
New York
printf(%15s,name2);
New
printf(Enter a name);
scanf(%15s,name1);
London
printf(%s,name1);
York
printf(Enter a name);
scanf(%15c,name1);
123456789012
printf(%15s,name1);
123456789012 r
printf(Enter a name);
scanf(%s,name2);
New-York
printf(%15s,name2);
New-York
printf(Enter a name);
scanf(%15s,name1);
London
printf(%s,name1);
London
printf(Enter address);
scanf(%[a-z],address);
new delhi 110002 (It accepts a to z values)
printf(%s,address);
new delhi
scanf(%[^\n],address);
new delhi 110002 (It accepts up to new line)
printf(%s,address);
new delhi 110002
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

11

SEERLOGICA INFOTECH
Output Formats
Integer Numbers:
int
m=12345;
long n=987654
printf(%d,m);

5
1

printf(%10d,m);
printf(%010d,m);

printf(%-10d,m);

printf(%3d,m);

printf(%-3d,m);

printf(%d,-m);

printf(%10d,-m);

printf(%3d,-m);

printf(%10d,n);
Real Numbers:
float y=98.7654
printf(%f,y);

printf(%7.4f,y);

printf(%10.2e,y);

printf(%12.4e,y);

printf(%7.2f,y);
printf(%-7.2f,y);

printf(%*.*f,7,2,y);
rintf(%07.2f,y);

printf(%-10.2e,y);

printf(%e,y);

printf(%f,-y);

Strings:
char x=A;

char

printf(%s, name);

name[20]=ANIL KUMAR GUPTA;

printf(%20s,name);

R
K

printf(%20.10s,name);

U
A

printf(%-20.10s,name); A

printf(%.5,name);

printf(%5s,name);

A
G
K

U
U

P
M

T
A

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

12

A
R

SEERLOGICA INFOTECH
Decision Making & branching
Decision Making & branching

if

simple if

switch

if- else nested if

goto

Conditional Operator
(Combination of ? : =>
c= a>b ? a+b : a-b)

if-else ladder

Syntax of if statement:
if (Condition)
{
Statement 1;
Statement 2;
}
if (Condition)
Statement 1;

isTrue
condition

True

Statement 1
Statement 2
is
condition

True
Statement 1

Syntax of if-else statement:


if (Condition)
{
Statement 1;
Statement 2;
}
else
{
Statement 3;
Statement 4;
}

is
condition
false

True
Statement 1
Statement 2

Statement 3
Statement 4

Syntax of nested if statement:


if (Condition 1)
{
if (Condition 1)
{
Statement 1;
Statement 2;
}
else
{
Statement 3;
Statement 4;
}
}

is
condition 1

True

is
condition 2
False

True
Statement 1
Statement 2

Statement 3
Statement 4

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

13

SEERLOGICA INFOTECH
Syntax of if-else ladder statement:

Syntax of switch statement:

if (Condition 1)
{
Statement 1;
}
else if (Condition 2)
{
Statement 2;
}
else if (Condition 3)
{
Statement 3;
}
else
{
Statement 4;
}

is
condition 1
True
Statement 1

switch(expression)
{
case 1: statement 1;
break;
case 2: statement 2;
break;
case 3: statement 3;
break;
case 4: statement 4;
break;
default: statement 5;
}

False

False

is
condition 2
True

is
condition 3

Statement 2

True

False

Statement 4

Statement 3

Syntax of goto statement:


main()
{
double x, y;
read:
scanf(%lf,&x);
if(X<0) goto read;
y=sqrt(x);
printf(%lf,x,y);
goto read;

goto label;

label:
statement;

label:
statement;

goto label;

Forward jump

Backward jump

}
Syntax of conditional operator:
If(x<0)
Conditional expression ? expression1 : expression 2

flag=0;
else

Flag=(x<0)? 0: 1

flag=1;
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

14

SEERLOGICA INFOTECH
Decision Making & Looping
Decision Making & looping

While

Do-while

For

Nested loops
Syntax of do-while Loop:

Syntax of while Loop:


while (test condition)
{
body of the loop
}

do
{
body of the loop
} while (test condition);

Body of
the loop

Test
Condition ?

False

True

False
Test
Condition ?

Body of
the loop

True
Syntax of for Loop:
for(initialization ; test-condition; increment)
{
body of the loop
}
Nested loops:
while (condition 1)
{
outer loop

while (condition 2)
{
inner

loop

}
}

do

Nested while loop

Nested do-while loop

do
{

for(i=1;i<10;i++)
{

for(j=0;j<5;j++)
{

}while(condition 1);
}while(condition 2);

}
}
Nested for loop

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

15

SEERLOGICA INFOTECH
Arrays:
Group Similar data types

one dimensional array

int a[10]

type name[dim];

In C, array starts at position 0. The elements of the array occupy adjacent


locations in memory. C treats the name of the array as if it were a pointer to the first
element--this is important in understanding how to do arithmetic with arrays. Thus, if v is
an array, *v is the same thing as v[0], *(v+1) is the same thing as v[1], and so on:

Pointer use for an array


#define SIZE 3
void main()
{
float x[SIZE] ,*fp;
int i;
for (i = 0; i < SIZE; i++)
x[i] = 0.5*(float)i;
for (i = 0; i < SIZE; i++)
printf(" %d %f \n", i, x[i]);
fp = x;
for (i = 0; i < SIZE; i++)
printf(" %d %f \n", i, *(fp+i));
}
x[i] means the i-th element of the array x, fp = x points to the start of the x array,
*(fp+i) is the content of the memory address i locations beyond fp, i.e, x[i].

Two dimensional array


Multi dimensional array

int a[10][10]
int a[10][10][10]

STRINGS:
A string constant, such as I am a string"
String is an array of characters. String terminated by the special null character ``\0''
void main()
{
char text1[100], text2[100], text3[100], *ta, *tb;
int i;
char message[] = "Hello, I am a string; what are you?";
printf("Original message: %s\n", message);
i=0;
while ( (text1[i] = message[i]) != '\0' )
i++;
printf("Text1: %s\n", text1);
ta=message;
tb=text2;
while ( ( *tb++ = *ta++ ) != '\0' )
;
printf("Text2: %s\n", text2);
}
text1=Hello , Text1=text2 are not possible

tb=ta is possible
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

16

SEERLOGICA INFOTECH
String Functions
String1= V

String2= G

\0
\0

1. strcat(s1,s2): The content of string1 is concatenated with string2, string2 can not be changed

strcat(String1,String2)
String1= V

String2= G

strcat(String1,String2,n)
O

\0

\0

2. strcpy(s1,s2): The content of string2 is copied in to string1, string2 can not be changed
strcpy (String1,String2)
String1= G

\0

String2= G

\0

strcpy (String1,String2,n)

3. strcmp(s1,s2): Returns the ASCII values string2 is subtracted from the ASCII values of
string1,if the result is zero the given strings are equal.
String1= T

\0

String2= T

\0

x= strcmp(String1,String2)
here x=-9

i.e. ASCII I ASCII R

4. strlen(s1): Returns the length of the given string


String1= G

\0

x=strlen(string1)
x=4
i.e. Without the null character.
5. strchr(s1,s2) :Return pointer to first occurrence of s2 in s1
S1= This is a book , s2= is
x= strchr(s1,s2)
returns 2

Function in stdlib
6. atoi(s1): string is converted in to integer & Returns a integer value
number=12345
x=atoi(number)
atof(string to float)
7. itoa(i): integer value is converted in to string & Returns a string
char str[20]
str=itoa(123)
fcvt(float to sting)
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

17

SEERLOGICA INFOTECH
Storage Classes:
Storage classes gives the information about the
1. Scope of the variable.
2. Life time of the variable.
3. Where the variable stores.
4. The default initial value of the variable.
There are 4 types of storage classes.
1. Automatic
2. Register
3. Static
4. External.

1. Automatic:
Keyword for this storage class is auto. The scope of the variable is local. That
means life time of the variable is within the block or function. It will get the storage in
RAM. The default initial value is garbage value.

2. Register:
Keyword is register. The scope of the register variable is local that means lifetime is within
the block or function. It will get the storage in register. The default initial value is garbage
value. Register access time is less when compared to the memory access time.

3. Static:
Keyword is static. The scope of the static variable is local & global. That means
lifetime is within the block or function (if it is local) & throughout the program (if it is
global). It will get the storage in RAM. The default initial value is Zero.

4. External:
Keyword is extern. The scope of the extern variable is global. That means lifetime
is throughout the program. It will get the storage in RAM. The default initial value is
Zero.

Storage Class
Auto
Static
Extern
Register

Scope
Local
Global/Local
Global
Local

Default Value Storage Place


Garbage
Zero
Zero
Garbage

RAM
Harddisk /RAM
Harddisk
Register

Function header can be two ways, 1. Classical method 2. Modern method


int sum(a, b)
int sum(int a, int b)
int a, b;
{
{
Body
Body
}
}
Classical method
Modern method
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

18

SEERLOGICA INFOTECH
Functions:
Functions divide complex programs into small blocks to read and write easily
Function types
1. User defined function (define body)
2. Library function
(no body)

main(), sum()
getc(), clrscr()

Syntax:
Return-type function-name (argument-list)
{
...local-declarations...
...statements...
Return return-value;
}

Function declaration
Function definition
Example:
main() {

(Function declaration is in main function)


(Function definition means sub function)
Int sum(int a, int b); --------- Function declaration
Int i=10, j=11,k;
K=sum(i,j);
Printf(%d,k) ;

}
Int sum(int a, int b)
{
Return (a+b); ---------- Function definition
}
First line of function definition is called Function Header.
Main() is called as calling function
Sum() is called as called function
I, j (Arguments in calling function are Actual parameters)
A,b (Arguments in called function are formal parameters)
Categories of functions
1. function no arguments no return type
2. function with arguments no return type
3. function no arguments and with return type
4. function with arguments and with return type
Function
acos(x)
asin(x)
atan(x)
atan2(x, y)
cos(x)
sin(x)
tan(x)
Cosh(x)
sinh(x)
tanh(x)
Call by value
Call by reference

Meaning
Arc cosine of x
Arc sine of x
Arc tangent of x
Arc tangent of x/y
Cosine of x
Sine of x
Tangent of x
Hyperbolic cosine of x
Hyperbolic sine of x
Hyperbolic tangent of x

Function
ceil(x)
exp(x)
fabs(x)
floor(x)
fmod(x, y)
log(x)
log10(x)
pow(x, y)
sqrt(x)

Meaning
X rounded up to the nearest integer
E to the power of x
Absolute value of x
X rounded down to the nearest integer
Reminder of x/y
Natural log of x, x>0
Base 10 log of x, x>0
X to the power y(xy)
Square root of x, x>0

(passing value of the Variable)


(passing Address of the variable)
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

19

SEERLOGICA INFOTECH
#include < stdio.h>
void exchange(int a, int b);
void main()
{
int a, b;
a = 5;
b = 7;
printf("From main: a = %d, b = %d\n", a, b);
exchange(a, b);
printf("Back in main: ");
printf("a = %d, b = %d\n", a, b);
}
void exchange(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
printf(" From function exchange: ");
printf("a = %d, b = %d\n", a, b);
}
a and b are NOT exchanged! Only the copies of the arguments are exchanged (call by Value).
We want to exchange using call by value we have to define global variables
#include < stdio.h>
void exchange ( int *a, int *b );
void main()
{
int a, b;
a = 5;
b = 7;
printf("From main: a = %d, b = %d\n", a, b);
exchange(&a, &b);
printf("Back in main: ");
printf("a = %d, b = %d\n", a, b);
}
void exchange ( int *a, int *b )
{
int temp;
temp = *a;
*a = *b;
*b = temp;
printf(" From function exchange: ");
printf("a = %d, b = %d\n", *a, *b);
}
a and b are exchanged (Values in the addresses are exchanged) (call by reference).
Recursion function: the function calling it self is called recursion function.
Int Fact ( int i) {
If (i=1)
Return i;
Else
Return (i*fact(i-1));
}
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

20

SEERLOGICA INFOTECH
Pointers: pointer is a variable which stores the address of another variable
float x;
x = 6.5;
&x is the address of x.

float x;
float* px;
x = 6.5;
px = &x;
px is a pointer to objects of type float, and sets it equal to the address of x:

Pointer use for a variable


The memory location referenced by a pointer is obtained using the ``*'' operator
(this is called dereferencing the pointer). Thus, *px refers to the value of x.
We can perform arithmetic operations using pointers, but the ``unit'' in pointer arithmetic is
the size (in bytes) of the object to which the pointer points.
For example, if px is a pointer to a variable x of type float, then the expression px + 1
refers not to the next bit or byte in memory but to the location of the next float after x (4 bytes);
if x is of type double, then px + 1 would refer to a location 8 bytes (the size of a double)
Only if x is of type char will px + 1 actually refer to the next byte in memory.
char* pc;
float* px;
float x;
x = 6.5;
px = &x;
pc = (char*) px;
(the (char*) is type casting(which converts one data type to another), px and pc
both point to the same location in memory--the address of x--but px + 1 and pc + 1
point to different memory locations.
void main()
{
float x, y;
/* x and y are of float type
*/
float *fp, *fp2;
/* fp and fp2 are pointers to float */
x = 6.5;
/* x now contains the value 6.5
*/
printf("Value of x is %f, address of x %ld\n", x, &x); /* print contents and address of x */
fp = &x;
/* fp now points to location of x
*/
printf("Value in memory location fp is %f\n", *fp); /* print the contents of fp
*/
*fp = 9.2;
/* change content of memory location*/
printf("New value of x is %f = %f \n", *fp, x);
21
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

SEERLOGICA INFOTECH
*fp = *fp + 1.5;
/* perform arithmetic
printf("Final value of x is %f = %f \n", *fp, x);
y = *fp;
/* transfer values
fp2 = fp;
printf("Transferred value into y = %f and fp2 = %f \n", y, *fp2);

*/
*/

Command-line arguments:
main(int argc, char** argv)
(char** argv declares argv to be a pointer to a pointer to a character, that is, a
pointer to a character array (a character string) an array of character strings.
i.e. char* argv[].
the array argv contains, all the information on the command line (strings are
delineated by white space), including the command itself. The integer argc gives the total
number of strings, and is therefore equal to the number of arguments plus one.
The following program simply prints out its own name and arguments:
#include < stdio.h>
main(int argc, char **argv)
{
int i;
printf("argc = %d\n", argc);
for (i = 0; i < argc; i++)
printf("argv[%d] = \"%s\"\n", i, argv[i]);
}

Structures:
Structure is a collection different types.
struct m{
int a;
char b;
char c[5];
}my_struct;

struct m{
int a;
char b;
char c[5];
};
Struct m my_struct;

m is called structure tag ( name of the structure)


a, b, c are called structure members;
my_struct is structure variable
Size of structure is sum of members size
int
char
char [5]
2
+
1
+
5
= 8 bytes
Accessing Members of a Structure:
my_struct.a

(. is called dot operator)


then my_struct-> a (-> is called arrow operator)

if is a pointer variable ( int *a)


Pointers to Structures:
If p is a pointer to a structure p->member-of-structure refers to the particular member.
Array of Structures
Struct oval_counter
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

22

SEERLOGICA INFOTECH
{
char *name;
int count;
};
struct oval_counter x[] ={
{VOWELS, 0),
{DIGITS, 0),
{COSONENTS. 0),
{SPECIAL SYMBOLS, 0}
};
Unions:
Union follows the same syntax as structure but members having share storage.
union int_or_float{
int i;
float f;
};
Size of structure is maximum size of member
int
float
2
4
= 4 bytes max(2,4)
Bit Field:
the numbers chosen is a power of 2, since when we bitwise AND with the status only the
bit at kth position(given by 2k) is not masked and all other bits will be 0s.
struct{
unsigned int a : 1;
unsigned int b : 2;
unsigned int c : 4;
} flags;
Scanf is not possible with bit fields. These are only unsigned integers

Standard I/O :
Character level I/O
getchar() reads one character at a time from stdin,
putchar() writes one character at a time to stdout.
Higher-Level I/O capabilities
printf handles formatted output to stdout.
scanf handles formatted input from stdin
scanf("format string", variables);
ptintf("format string", variables);
The format string may contain blanks or tabs (ignored), ordinary ASCII characters
Equivalent statements exist to read from or write to character strings. They are:
sprintf(string, "format string", variables);
scanf(string, "format string", variables);

The ``string'' argument is the name of (i.e. a pointer to) the character array into which you want to
write the information.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

23

SEERLOGICA INFOTECH
Files:
File functions
Name
fopen()
fclose()
putc()
fputc()
getc()
fgetc()
fgets()
fputs()
fseek()
ftell()
fprints()
fscanf()
feof()
ferror()
rewind()
remove()
fflush()

Function
Opens a file
Closes a file
Writes a character to a file.
Same as putc()
Reads a character from a file.
Same as getc()
Reads a file from a file
Writes a string to a file
Seeks to a specified byte in a file
Returns the current file position
Is to a file what printf() is to console
Is to a file what scanf() is to the console.
Returns true if end-of-file is reached.
Returns true if end-of-file is reached.
Resets the file position indicator to the
Beginning of the file.
Erases a file.
Flushes a file.

The File Pointer:


The file name can be indicated by a file pointer.
FILE *fptr
Opening a file:
fptr=fopen(filename,mode); (fptr is File pointer)
File name- A file name in which the data to be stored or retrieved. (ex: Test.exe)
Mode-A file can be opened in various ways.
Mode
Meaning
r
Opens a text file for reading.
w
Creates a text file for writing.
a
Append to a text file.
rb
Opens a binary file for reading.
wb
Create a binary file for reading.
R+
opens a text file for read/write.
W+
Create a text file for read/write.
A+
Append or create a text file for read/write.
______________________________________________________________________________
Operations on Files:
#include < stdio.h>
void main()
{
FILE *fp;
int i;
fp = fopen("foo.dat", "w");
/* open foo.dat for writing */
fprintf(fp, "\nSample Code\n\n"); /* write some info */
for (i = 1; i <= 10 ; i++)
fprintf(fp, "i = %d\n", i);
fclose(fp);
/* close the file */
}
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

24

SEERLOGICA INFOTECH
Stacks & Queues
Stack:

Top
Top

30
20

20
Top
Stack created with
size 5 (Stack is
empty, Top=0)

push one element


(Stack having 1
element, Top=1)

Push one element


(Stack having 2 elements,
Top=2)

Top
60
Top
50

50

40

40

40

30

30

30

20

20

20

Top

Push three elements


(Stack is full
(5 elements), Top=5)

Pop one element


(Stack having
4 elements, Top=4)

Pop three elements


(Stack is empty,
Top=0)

Pop one element


(Stack having 3 elements,
Top=3)

Stacked is deleted

Top

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

25

SEERLOGICA INFOTECH
Stack and Its Implementation in C:
A stack is a linear data structure which can be accessed only at one end called a TOP, Stack
follows LIFO (Last In First Out) structure.
There are two basic operations on stack:
1. PUSH (Insertion Operation): Inserts an element at the TOP of the stack.
2. POP (Deletion Operation): Deletes an element from the TOP of the stack.
3. PEEP : Find the poison of an element at any type
Applications of stack structures:
A. Evaluation of arithmetic expressions:

(infix expression to postfix expression & evaluation of postfix expression)


Infix ( a+b )
Prefix ( + ab )
Postfix ( ab+ )

operand1 <operator> operand2


<operator> operand1 operand2
operand1 operand2 <operator>

Prefix form is also called Polish Notation


Postfix form is the Inverse Polish Notation
The process of conversion (INFIX to POSTFIX) requires a certain rules to follow:
INPUT

STACK

+(

+(

-*

-*

OUTPUT

d
-

*
B. Stores address when sub routine call
C. Reverse a string (Push and pop the string)

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

26

SEERLOGICA INFOTECH
Queue:
A queue is a linear data structure insertions can be done at one end called Rear and deletions can
be done at another end called Front, Queue follows FIFO (First In First Out) structure
The basic operations are applied to queue structure:
1. Insertion (Insertion Operation): Inserts an element at the Rear of the Queue.
2. Deletion (Deletion Operation): Deletes an element from the Front of the Queue

20

Front Rear

Front
Queue created with size 5
(Queue is empty,
Front=0 Rear=0)

Inserted one element


(queue having 1 element,
Front=0 Rear=1)

30

20

Front

20

Rear

30

40

50

60

Front

Inserted one element


(Queue having 2 elements,
Front=0 Rear=2)

30

Rear

40

50

Inserted 3 elements
(Queue is full (5 elements),
Front=0 Rear=5)

60

Front

Rear

Rear

Deleted one element


(Queue having 4 elements,
Front=1 Rear=5)

Front Rear
Deleted three Elements
(Queue is empty,
Front=5 Rear=5)

40

50

60

Front

Rear

Deleted one element


(Queue having 3 elements,
Front=2 Rear=5)

Queue is deleted

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

27

SEERLOGICA INFOTECH
Circular Queue :

Front

Front

10
Rear

Rear
Circular Queue created with size 7
(Queue is empty, Front = Rear=0)
%7)

One element is inserted into Circular Queue


(Queue having one element rear= (rear+1)

60

50

70
Front

10

20

Rear

Inserted one element (Queue having 2 elements)


rear= (rear+1)%7

60

10

60

40
20 30

20

30

Inserted 5 elements (Queue is full)


(7 elements) (rear= front)

50

70
Rear

Rear
Front

40

50

70
Rear

40
30

Front

Front
Deleted one element from the queue
(Queue having 6 elements)

Deleted one element from the queue


(Queue having 5 elements)

Front
Rear
Deleted 5 elements from the queue
(Queue is empty, Front = Rear)

Queue is deleted

Applications of stack structures:


1. Spooling of jobs in printer queue
2. Process in processing
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

28

SEERLOGICA INFOTECH
Linked List:
Advantages of arrays

1. Easy to locate
2. Less memory size for one variable

Disadvantages of arrays

1. Memory can be wasted


2. Deletion of an element at particular position

Disadvantages of arrays can be overcome by linked lists


The main advantage of list structure is its dynamic nature, the number of elements in list is
not declared, but instead the elements are allocated in the memory upon request (we need the new
element at run-time), if we compare linked list structure and array structures we will see that in the
case of linked list structure we are loosing the possibility of direct access to linked list's elements
(in array this can be done by simple indexing). If we would like to reach any particular element of
linked list we have to traverse a structure starting from a header.
A variable i can allocate memory as dynamic variable, it is hold in the memory until it is
necessary a call to function free(), will deallocate and return to the system the part of memory
which was used by the variable (dynamic variable i)
malloc(), celloc() functions are used for dynamic memory allocation
Structure of one node:
1. Information field (it keeps the value of the element).
2. Link field (it points to the next node).
The link field on the last node should not point to anything, this can be done by assigning a
value NULL to this pointer (The value NULL stands for address which does not correspond to any
valid memory location.
<Pointer> = malloc ( sizeof (type)
<Pointer> = celloc ( sizeof (type,n)

(single block of memory)


(Multiple blocks of memory)

Linked list structure does not impose any restrictions on the positions to insert / delete
elements. Suppose that we want to delete one element from list, first of all we have to find this
element (it can be achieved by traversing list). For traversing linked list we need to have two
pointers (header is not used -it always keeps the starting address of the list), temp (will point to the
element to be deleted after traversing is done)
Depending on the application of linked list structure we may need also to control the
number of elements which are in linked list at each moment of time, one of the possibilities to do it
is to traverse linked list structure any time we want to know the number of elements, but if linked
list is big enough and traversing is repeated frequently. Such control of number of elements
becomes very time consuming. The other possibility to keep track on number of elements in linked
list is to modify a header which can be represented as a struct structure with two fields. One of
these fields keeps the number of element of linked list. Declaration part in this case should be
modified as in corresponding

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

29

SEERLOGICA INFOTECH
Single linked list:

Data Field
10

\0

Link Field

Linked list with one element

20

10

\0

20

10

30

\0

One element is inserted as last node

20

10

30

\0

One element is inserted at desired position


(3 rd position)

One element is inserted as first node

40

20

10

40

30

\0
One element is inserted after data is 40

50

20

10

40

50

30

\0

40

50

30

\0

Completed linked list

20

10

One element is deleted form the list (now list having 4 elements)

Circularly Single linked list:

20

10

40

50

10

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

30

SEERLOGICA INFOTECH
Doubly linked list structure:
Node in linked list has one pointer field which always keeps the address (if it is not the last
element) of the next element in the structure, such linked list are often called One-Way or Single
Linked List. Certain applications require knowing at each moment of time not only a successor of
a current node, but also a predecessor of a current node, that is the reason Double linked list
structure is used.
The representation of doubly linked list "combines together" two-one way linked list, so
header consists of two pointer fields, each field references its own one-way linked list.
To insert a new node somewhere in the middle of Doubly linked list, have to find a
position for insertion of a new element start traversing from first position, and a pointer current in
this case will point to the node which will become a predecessor of the inserted node.
Deletion of nodes from Doubly linked list structures when we found the element to be
deleted, we automatically know its predecessor and successor, combine both of them
In linked list every node is points to the next, but the last node having Null pointer.
If the last node point to the first node than it called as Circular linked list
In Single Linked List last node points to first node it is called as Circularly Single linked list
In Double Linked List last node points to first node it is called as Circularly Doubly linked list

The advantage of Circular linked list is in simplified approach to traversing of structure,


because a search for particular element can be started not from the header, but from any current
node (finally we are in the circle, and sooner or later the element we are looking for will be found,
if it is in the structure). Circular linked list simplifies also a procedure of deletion. Unfortunately
Circular linked lists are becoming dangerous in the sense of potential traversing (if a logical
mistake is done in specifying a condition to stop traversing it goes to infinite loop).

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

31

SEERLOGICA INFOTECH
Double linked list:
Link Field

Link Field

Data Field
\0

10

\0

\0

20

10

\0

20

10

30

\0

\0

20

10

30

\0

Double Linked list with one element

One element is inserted as first node

\0

One element is inserted as


last node

One element is inserted at


desired position (3rd position)

40
\0

20

40

10

30

\0

One element is inserted after data is 40


50
\0

10

20

40

50

30

\0

40

50

30

\0

Completed linked list


\0

10

20

One element is deleted form the list


(now list having 4 elements)
Circularly doubly linked list:

20

10

40

50

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

30

32

SEERLOGICA INFOTECH
Searching:
Searching is a algorithm that accepts an argument K (the key value) and tries to find a
record whose key is K . The algorithm may return the entire record or more commonly a pointer
(location) of the record. It is possible that the searching for a particular key in a file may be
unsuccessful; that is there is no record in the file, whose key value matchers with that of the
searching key K so that the algorithm may returns a special value or a NULL pointer.
They are two types: 1. Linear search
2. Binary search.
Linear Search:
Linear search compares the search key value with every key going through the entire array.
The worst case time complexity of any algorithm that searchs linearly that will be O(n), where n
is the number of keys( records).
int lin_search( int x [] , int n , int k )
{
int i ;
for ( i =0 ; i<n ; i++)
if ( x [ i ] == k)
return i ;
return (-1 ) ;
}
In linear search given array need not be in sorted order.
Binary Search:
The given elements are in sorted order, no need to check each and every element
of the array. Find the middle element of the array and compare with the searching
element. If searching element is bigger than middle element we can search elements
which are after the middle element and omit the elements before middle element. Like
this way we can reduce the no. of comparisons. So it is faster than the linear search. It is
called as Binary Search. The worst case complexity O(log n) .
int bin_search ( int x [] , int n , int k )
{
int low,high, mid ;
low = 0;
high= n;
while ( high>=low)
{
mid= (low+high)/2;
if (x [mid] == k)
return (mid) ;
if ( x [mid ] > k )
high = mid 1;
else
low = mid + 1;
}
return (-1 ) ;
}
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

33

SEERLOGICA INFOTECH
Sorting Methods
S. NO
1
2
3
4
5
6
7
8
9
10
11

Enter the size of array

Name of the Sort


Complexity
Normal Sort
O(n2)
Bubble Sort
O(n2)
Modified Bubble Sort
O(n2)
Selection Sort
O(n2)
Insertion Sort
O(n2)
Radix (Bucket) Sort
O(n log d n)
Quick Sort
O(n log n)
Merge Sort
O(n log n)
Shell Sort
O(n2)
Heap Sort
O(n2)
Radix Exchange Sort O(n log d k)

10

Enter the array elements 24 58 63 84 30 43 18 93 04 70


Normal Sort:
Pass 1:

93 24 58 63 30 43 18 84 04 70

Pass 2:

24 93 58 63 30 43 18 84 04 70

Pass 3:

24 58 93 63 30 43 18 84 04 70

Pass 4:

24 58 63 93 30 43 18 84 04 70

Pass 5:

24 30 58 63 93 43 18 84 04 70

Pass 6:

24 30 43 58 63 93 18 84 04 70

Pass 7:

18 24 30 43 58 63 93 84 04 70

Pass 8:

18 24 30 43 58 63 84 93 04 70

Pass 9:

04 18 24 30 43 58 63 84 93 70

Pass 10:

04 18 24 30 43 58 63 70 84 93

Note: Biggest element is at 1 st pos in 1 st pass, at 2 nd pos in 2 nd pass & last pos in last pass.

Radix (Bucket) Sort:


Pass 1:

30 70 63 43 93 24 84 04

58 18

Pass 2:

04 18 24 30 43 58 63 70 84 93

Note: Units Place sorted in the 1st pass, 10s Place sorted in the 2nd pass.
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

34

SEERLOGICA INFOTECH
Bubble Sort:
Pass 1:

24 58 63 30 43 18 84 04 70 93

Pass 2:

24 58 30 43 18 63 04 70 84 93

Pass 3:

24 30 43 18 58 04 63 70 84 93

Pass 4:

24 30 18 43 04 58 63 70 84 93

Pass 5:

24 18 30 04 43 58 63 70 84 93

Pass 6:

18 24 04 30 43 58 63 70 84 93

Pass 7:

18 04 24 30 43 58 63 70 84 93

Pass 8:

04 18 24 30 43 58 63 70 84 93

Pass 9:

04 18 24 30 43 58 63 70 84 93

Pass 10:

04 18 24 30 43 58 63 70 84 93

Note: Biggest element is at last position in 1 st pass, 2nd biggest element is at last but one
position in 2 nd pass & smallest element at 1 st position in the last pass.

Modified Bubble Sort:


Pass 1: 24 58 63 30 43 18 84 04 70 93
Pass 2:

24 58 30 43 18 63 04 70 84 93

Pass 3:

24 30 43 18 58 04 63 70 84 93

Pass 4:

24 30 18 43 04 58 63 70 84 93

Pass 5:

24 18 30 04 43 58 63 70 84 93

Pass 6:

18 24 04 30 43 58 63 70 84 93

Pass 7:

18 04 24 30 43 58 63 70 84 93

Pass 8:

04 18 24 30 43 58 63 70 84 93

Note: Biggest element is at last pos in 1 st pass, 2 nd biggest element is at last-1 pos in 2nd pass,
smallest element at 1 st pos in the last pass. But once numbers sorted done process stopped.

Shell Sort:
Pass 1:

24 18 63 04 30 43 58 93 84 70

Pass 2:

24 04 30 18 58 43 63 70 84 93

Pass 3:

04 18 24 30 43 58 63 70 84 93

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

35

SEERLOGICA INFOTECH
Note: Every element is compare with size/2 (4 th) element, if bigger swap two elements and do
the same step until swapping not done in 1 st pass, Every element is compare with +2nd
element, if bigger swap two elements & do the same step until swapping not done in 2nd pass,
Every element is compare with next element, if bigger swap two elements & do the same step
until swapping not done in 3rd pass.

Selection Sort:
Pass 1:

04 58 63 84 30 43 18 93 24 70

Pass 2:

04 18 63 84 30 43 58 93 24 70

Pass 3:

04 18 24 84 30 43 58 93 63 70

Pass 4:

04 18 24 30 84 43 58 93 63 70

Pass 5:

04 18 24 30 43 84 58 93 63 70

Pass 6:

04 18 24 30 43 58 84 93 63 70

Pass 7:

04 18 24 30 43 58 63 93 84 70

Pass 8:

04 18 24 30 43 58 63 70 84 93

Pass 9:

04 18 24 30 43 58 63 70 84 93

Pass 10: 04

18

24

30

43

58

63

70

84

93

Note: smallest element is at 1 st pos in 1st pass, 2nd smallest element is at 2nd pos in 2nd pass &
biggest element at last pos in the last pass.

Insertion Sort:
Pass 1:

24 58 63 84 30 43 18 93 04 70

Pass 2:

24 58 63 84 30 43 18 93 04 70

Pass 3:

24 58 63 84 30 43 18 93 04 70

Pass 4:

24 58 63 84 30 43 18 93 04 70

Pass 5:

24 30 58 63 84 43 18 93 04 70

Pass 6:

24 30 43 58 63 84 18 93 04 70

Pass 7:

18 24 30 43 58 63 84 93 04 70

Pass 8:

18 24 30 43 58 63 84 93 04 70

Pass 9:

04 18 24 30 43 58 63 84 93 70

Pass 10: 04

18

24

30

43

58

63

70

84

93

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

36

SEERLOGICA INFOTECH
Note: Every element is checked with before elements and inserted at proper position (Here
swapping is not done).

Merge Sort:
24

58

63

84

30

43

18

93

04

70

70

Pass 1:

24 58

63

84

30

43

18

93

04

Pass 2:

24 58 63

84

18

30

43

93

04

70

Pass 3:

18

24

30

43

58

63

84

93

04

70

Pass 4:

04

18

24

30

43

58

63

70

84

93

Note: Divided into 2 elements array and sorted each array in the 1 st pass. Merge every two
arrays and sorted (4 elements in each array) in the 2 nd pass. Merge every two arrays and
sorted (8 elements in each array) in the 3rd pass. Merge every two arrays and sorted

Quick Sort:

(Key Element is First Element)

Pass 1:

04 18 63 84 30 43 58 93 24 70

Pass 2:

04 18 63 84 30 43 58 93 24 70

Pass 3:

04 18 24 58 30 43 84 93 63 70

Pass 4:

04 18 24 58 30 43 84 93 63 70

Pass 5:

04 18 24 43 30 58 84 93 63 70

Pass 6:

04 18 24 30 43 58 84 93 63 70

Pass 7:

04 18 24 30 43 58 70 63 93 84

Pass 8:

04 18 24 30 43 58 63 70 93 84

Pass 9:

04 18 24 30 43 58 63 70 84 93

Quick Sort:

(Key Element is Middle Element)

Pass 1:

24 04 18 30 84 43 63 93 58 70

Pass 2:

04 24 18 30 84 43 63 93 58 70

Pass 3:

04 18 24 30 84 43 63 93 58 70

Pass 4:

04 18 24 30 84 43 63 93 58 70

Pass 5:

04 18 24 30 58 43 63 93 84 70

Pass 6:

04 18 24 30 43 58 63 93 84 70

Pass 7:

04 18 24 30 43 58 63 70 84 93

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

37

SEERLOGICA INFOTECH
Note: (Key element is First element or middle element) take the key element and then find the bigger
element before key, find the smaller element after key and interchange those two. Now Take the
elements before key element into one array & after key element into another array.

Radix Exchange Sort:


Given Binary
Pass1
Numbers equivalents

Pass2

Pass3

Pass4

Pass5

Pass6

Pass7 Sorted
Elements

24

0011000

0011000 0011000

0011000 0010010 0000100

0000100 0000100

04

58

0111010

0111010 1010100

0111010 1010100 1000110

1000110 0010010

18

63

0111111

1010100 0000100

0010010 0000100 0101011

0010010 0011000

24

84

1010100

0011110 1011101

0101011 1000110 0010010

1010100 0011110

30

30

0011110

0010010 0111010

1010100 0011000 1010100

0011000 0101011

43

43

0101011

0000100 0011110

0000100 0111010 0011000

1011101 0111010

58

18

0010010

1000110 0010010

1011101 0101011 0111010

0011110 0111111

63

93

1011101

0111111 1000110

0011110 1011101 1011101

0101011 1000110

70

04

0000100

0101011 0111111

1000110 0011110 0011110

0111010 1010100

84

70 1000110

1011101 0101011

0111111 0111111 0111111 0111111 1011101

93

Note: Convert decimal numbers into its Binary equivalents. Units place is sorted in the 1st pass,10s place is
sorted in the 2nd pass,100s place is sorted in the 3rd pass, 1000s place is sorted in the 4th pass, 10000s place is
sorted in the 4th pass, 100000s place is sorted in the 5th pass, 1000000s place is sorted in the 6th pass,
10000000s place is sorted in the last pass.

Heap Sort:

24 58 63 84 30 43 18 93 04 70

After Heap Given Elements are : 93 84 58 63 70 43 18 24 04 30


Pass 1:

84

70

58

63

30

43

18 24

04

93

Pass 2:

70

63

58

24

30

43

18 04

84

93

Pass 3:

63

30

58

24

04

43

18 70

84

93

Pass 4:

58

30

43

24

04

18

63 70

84

93

Pass 5:

43

30

18

24

04

58

63 70

84

93

Pass 6:

30

24

18

04

43

58

63 70

84

93

Pass 7:

24

04

18

30

43

58

63 70

84

93

Pass 8:

18

04

24

30

43

58

63 70

84

93

Pass 9:

04

18

24

30

43

58

63 70

84

93

Note: Create maximum heap with the given elements. Interchange First element with last element
(maximum element go to last position). Then create with all the elements except sorted elements,
interchange first element with last element (elements used for heap).

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

38

SEERLOGICA INFOTECH
Trees
Trees are often used in everyday life to represent hierarchical relationships between the
data elements. For example, the genealogical tree (family tree) is one in which we represent a
hierarchical relationship between parents, children, brothers, sisters, Uncles, and so on. Other uses
of trees include organisational circuit like table of contents and pairing in a tournament. This type
of organizing is very useful to show the precedence between the elements.
A tree is a nonlinear data structure. This is mainly for the traversing techniques. A tree is a
data structure in which each element is attached to one or more elements directly. The graph is also
non-linear data structure. This having different types of trees. Like Complete Binary tree, full
binary tree, NULL branches, B+ tree etc.
Every tree having some nodes. And Level numbers .These is the give the Depth and
Breadth of a tree. The full Binary tree, complete binary tree are have both left and right children or
siblings.

Binary Trees:
A binary tree is a tree in which each node has atmost two children, a left child and right child.
Thus the order of binary tree is 2.
A Binary tree is either empty or consists of
(a) a node (called the root node) &
(b) left and right subtrees.
Both the subtrees are themselves are binary trees.

In the fig 4.3,node is the root and also parent of the nodes B and C. Nodes D,F,H,I and j are leaves.
Interchanging the right and left subtrees results a new and different tree. That is binary tree is not
symmetric tree structures. If two binary trees have same structure then they are said to be similar
structure.
Binary trees structures are very useful in processing arithmetic expressions. And is used to
evaluate the arithmetic expression.
Consider the following expression;
(A+B)-(C/(D*E))
If we traversal the tree in a particular order we will get one of the basic three forms.
A binary tree can be represented mainly in two ways.
(a)Sequential representation
(b) Linked representation.
Sequential representation uses arrays and linked representation uses Pointers.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

39

SEERLOGICA INFOTECH
SEQUENTIAL [ARRAY] REPRESENTATION:The simplest way to represent binary trees in memory is the sequential representation uses
a one-dimensional array. The following methods are
(a) The root of binary tree is stored in the 1stlocation of array.
(b)If a node is in the jth location of array, then it left child is stored in location (2J) and the
right child is location (2J+);
The maximum size that is required for an array to store tree is 2 d+1-1,
Where d is the depth of the tree.

Here the node C at location 3 has left child F at 6th(=2*3) location at the right child at
7 =(2*3+1) location. Since the depth of examples tree is 4.24+1-1=31.
th

LINKED [POINTER REPRESENTATION]:Linked representation of trees in memory is implemented using pointers. Since each node
in a binary tree can have maximum two children. A node linked representation has two pointer
fields for both left and right child or not information field. If a node does not have any child node
then
that
field
is
the
NULL
node.
That
is
the
NULL
pointer.

In above fig the NULL pointer are shown as cross (x).A binary tree with N node contains
N+1 NULL pointers. Each node associated with the info field has the both leftptr, rightptr denote
pointers of both left child and right child. This type of linked representation is Nonlinear.
Binary tree T with the element from the set E is a list which is either empty or it consists of three
components.
1. A root of the tree T.
2. Right subtrees of the tree T.
3. Left subtrees of the tree T.
Each element of the tree is called a node. The most reasonable representation of the binary tree is a
graphical one,
Suppose that Tz is a tree which starts from arbitrary node z of the tree T if the left subtree of
Tz is not empty then the roots of the left subtree is called the left child of the node z, with each
node of the tree T we can associate a number which is called a node's level by default, the level of
the root of the tree T has a level 0, its children stand at the level1, etc. The height of a tree T( h(T))
is the maximum level for each node of the tree, for the figure shown above h(T) = 2.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

40

SEERLOGICA INFOTECH
Suppose that, tree T has a height of n, then the maximum number of nodes = 2n+1-1.
Potentially binary tree can be implemented by means of array and in the declaration part we have
to specify a set of indices 1....2n+1-1, keeping 1 arrays element for 1 element in the tree regardless
of presence of element (node) in the tree or its absence.
If we would like to implement a binary tree as a linked list structure .If we have a
collection of n objects, then these objects can be arranged in n! different ways, and it means that
there are n! ways to perform traversal of these objects, Some traversals seem to be more natural
than others. For example if objects are organized into linked list structure, it seems more logical to
perform traversing starting from the header visiting the elements one by one in the linked order. If
the structure under study is binary tree then the way traversal should be performed is not quite
clear, and there are three main approaches which are commonly used in computer science:
1. PREORDER traversal: Start with root and follow the left subtree till we reach the leaves,
then trace the right subtree till we reach the leaves. (root will be at the beginning).
2. INORDER traversal: Start with the leaves of the left subtree till root, then from leaves of
the right subtree till you reach the root. (root will be in the middle).
3. POSTORDER traversal: Start with the leaves of the left subtree till you reach the root, then
trace from the leaves of right subtree till root. (root will be at the end).
The prefixes used above indicate the moment when the root should be processed. All the
definitions specified here are recursive ones, for all of them we can easily find a base case (it is not
expressed in terms of traversing): traversing of empty tree is equivalent to do-nothing. Prefixes
used in the names of traversal approaches are the same as those used in the names of forms of
arithmetic expressions representations-PREFIX,INFIX and POSTFIX. A question that may arise is
how these forms are related to BINARY TREES TRAVERSAL?
h(T) = 3
The corresponding PREFIX and INFIX forms of the INFIX expression given above are: INFIX :
a^2 - 4 *b * c
PREFIX: - ^ a 2 * * 4 b c
POSTFIX: a 2 ^ 4 b * c * Traversal of binary tree;

PREORDER traversal: - ^ a 2 * * 4 b c
INORDER traversal: a ^ 2 - 4 * b * c
POSTORDER traversal: a 2 ^ 4 b * c * -

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

41

SEERLOGICA INFOTECH
PRE-ORDER:
Pre-order is traversing a tree n the order: root left right
the following is the procedure for pre-order:
1. Visit the root.
2. Traverse the left sub-tree In pre-order.
3. Traverse the right sub-tree n pre-order.
The following diagram represents the procedure of pre-order.
ALGORITHM: Pre-order Traversal (Recursive):
Procedure Pre-order(T)
1. If T=NULL then
begin
Print 'Tree is empty'
Return
end
2. Print info(T)
3. If leftptr(T) != NULL then
Call Pre-oredr(leftptr(T))
4. If rightptr(T) != NULL then
Call Pre-order(rightptr(T))
5. Return

ALGORTHM: PRE-ORDER TRAVERSAL (ITERATIVE):


Procedure IterPre-order(T)
1. If T = NULL then
begin
Print 'Tree is empty'
Return
end
2. P<-T
Top<-0
3. while P!=NULL do
begin
Print info(P)
if rptr(P)!=NULL then
Call PUSH(S,Top,rptr(P))
P<-Iptr(P)
if (P=NULL) && (top>0) then
P<-POP(S,Top)
end
4. Return

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

42

SEERLOGICA INFOTECH
IN-ORDER:
In-order is traversing a tree In the order: left root right
The following is the procedure for In-order:
1. Traverse the left sub-tree In In-order.
2. Visit the root.
3. Traverse the right sub-tree In In-order.
ALGORITHM: In-order Traversal (Recursive):
Procedure In-order(T)
1. If T=NULL then
begin
Print 'Tree is empty'
Return
end
2. If leftptr(T) != NULL then
Call In-order(leftptr(T))
3. Print info(T)
4. If rightptr(T) != NULL then
Call In-order(rightptr(T))
5. Return

ALGORTHM: IN-ORDER TRAVERSAL (ITERATIVE):


Procedure IterIn-order(T)
1. If T = NULL then
begin
Print 'Tree is empty'
Return
end
2. P<-T
Top<-0
3. Repeat
while P!=NULL do
begin
Call PUSH(S,Top,P)
P<-Iptr(P)
end
if (Top>0) then
begin
P<-POP(S,Top)
Info(P)
P<-rptr(P)
end
until(top=0 && p=NULL)
4. Return

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

43

SEERLOGICA INFOTECH
POST-ORDER:
Post-order is traversing a tree in the order: left right root
the following is the procedure for Post-order:
1. Traverse the left sub-tree in Post-order.
2. Visit the root.
3.Traverse the right sub-tree in Post-order.
ALGORITHM : Post-order Traversal (Recursive):
Procedure Post-order(T)
1. If T=NULL then
begin
Print 'Tree is empty'
Return
end
2. If leftptr(T) != NULL then
Call Post-order(leftptr(T))
3. If rightptr(T) != NULL then
Call Post-order(rightptr(T))
4. Print info(T)
5. Return

ALGORTHM: POST-ORDER TRAVERSAL (ITERATIVE):


Procedure IterPost-order(T)
1. If T = NULL then
begin
Print 'Tree is empty'
Return
end
2. P<-T
Top<-0
3. while(true) do
begin
while P!=NULL do
begin
Call PUSH(S,Top,P)
if rptr(P)!=NULL then
Call Push(S,Top,-rptr(P))
P<-lptr(P)
end
P<-POP(S,Top)
while(P>0) do
begin
Print info(P)
if (Top=0) then
begin
Return
P<-POP(S,Top)
end
if p<0 then
P=-P
end
4. Return

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

44

SEERLOGICA INFOTECH
Binary Search Tree:
According to the definition of the binary tree structure, its elements are taken from a set E
which can be associated with some particular type at the stage of structure's implementation. In
practical cases it is required that set E is ORDERED (in other words, type which corresponds to
the set E is ordered). A binary tree with the elements of the type E is called a binary search tree, if
for every node in the tree the key field of its informational part is greater than that for every node
in the left sub tree, and less than that in every node in the right sub tree of the binary tree T. By key
field we mean one of the fields in the nodes structure (struct) which is used for the search.
Ordering of the elements of the binary tree becomes essential while performing operations
insert / delete. Informational part of each node may include several fields (name , surname,
student's ID number, ......) and among them we have to choose one key field (for example it can be
student's ID number) and using it, whole structure of binary tree can be constructed.
In order to implement binary search tree and its standard operations insert / delete, we have
to make the corresponding declarations. Within the last example, in the declaration, the info field
of the node has a struct. Structure and one of the fields is chosen as a key the procedure insert
becomes a recursive one because the insertion of the new node is expressed in terms of insertion of
the node into a sub Tree and for sub tree insertion is done on its sub tree etc...
The variant of function insert does not give us a chance to move through the levels of the
tree, so some slight changes should be done.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

45

SEERLOGICA INFOTECH
Graphs
Graphs are mathematically structures and are found very useful in problem solving.
Graphs provide an excellent way to describe the essential features of many applications.
Graph is a set of nodes (or vertices) and edges (or arcs) which connect them.
G= (V,E)
Where V is the set of nodes and E is the set of edges.
A set of edges E are such that E={(vi,vj)} where vi,vj V. That is each edge in a graph is
specified
by
a
pair
of
nodes.
Example: A Graph could be viewed as a map of what cities are connected by train routes.
Viewing in this way, each vertex represents a particular city and each edge represents whether
there
is
a
train
route
for
one
city
to
another.
If two nodes are connected by an edge those two nodes are said to be adjacent (or
neighbours). That is, nodes v1 and v2 are adjacent if there is an edge (v1,v2) or (v2,v1).

In the above fig Vertices adjacent to node 3 are 1,5,6 and 4 and that to node 2 are 1 and 4.
An edge which has direction is called "directed edge". That means , directed edge is
"unidirectional".It
goes
from
one
node
to
another.

In the above fig there is a edge from B to C but there is no edge representing reverse
relationship (from C to B).The edge which has no specific direction is called "undirected edge".
If a node doesn't have any adjacent nodes, then it is said to be "isolated".node 8 in the above fig is
isolated node .A graph which contains only isolated nodes is called a "null graph".
A directed graph(or digraph) is a graph in which all edges are directed edges. An
undirected graph is a graph in which all edges are "undirected edges".A graph which contain both
directed and undirected edges is said to be mixed graph. An edge in a graph which starts and ends
on the same node is called a "loop". A loop can be considered either a directed or undirected since
there is no significance. A pair of nodes may be connected by more than one edge .Such edges are
referred to a parallel. A "Multi Graph" is a graph in which there are some parallel edges .A simple
graph is a graph in which there are no parallel edges. The "Degree" of a node is the number of
edges connected directly to that node, i.e., the number of edges incident on it.
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

46

SEERLOGICA INFOTECH

In a directed graph, the "out degree" of a node is the number of edges beginning from the
node.The "in degree" of a node is the number of edges terminating at that node.
In the above fig the in degree of a node B is 2 and out degree of a node B is 1.The sum of
in degree and out degree of a node is the total degree of that node. In case of undirected graphs,
total degree is nothing but degree itself. The concept of in degree and out degree can not apply to
undirected graph. A node whose in degree os 0 is called a "source node" and a node whose out
degree is 0 is called "sink node. for isolate nodes, the degree is 0.
A "weighted graph" is a graph that has a number (weight) associated with each edge.
Examples of Weighted graphs are:1) Airline flight information in which the nodes are airports (cites) and the edges are flights
.The weights could be ticket prices, or distances.
2) A computer network in which the nodes are computers and the edges are
communication lines .The weights could be line bandwidth.
3) A natural gas distribution system in which nodes are storage tanks and edges are pipes.
Weights could be pipe capacity or distance.
A path P of length k,in a graph is a sequence of connected vertices v1,v2,v3,........vk such that
(vi,vi+1) E for 1<=i<k.
The number of edges in a path is the length of that path.
A simple path in a graph is a path such that all nodes are distinct, except that the first and
last could be same .A "cycle" in a graph is a path of length atleast 3 which has the first and last
nodes are same. i.e., the path begins and ends on the same node. A directed graph is a cyclic if it
has no cycles.
A graph is said to be connected, if a path exists from any node to any other node. A digraph
with this property is said to be strongly connected, i.e., a directed path exists from any node to any
other node. If a digraph is not strongly connected then it is said to be weakly connected .A graph is
said to be complete graph if there is an edge between every pair of nodes. A tree is nothing but a
complete graph without any cycles.

Directed Graph:There is an edge from one node to another node then that is called Directed graph.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

47

SEERLOGICA INFOTECH

Undirected Graph:There is no edge between from one to any other node then that is called Undirected graph.
Isolated Graph:There is no path from one node to another node then that is called isolated graph.
Null Graph:A graph which contains the only isolated nodes then that graph is said to be the Null graph.
Mixed Graph:A graph which contains the both directed and undirected graph then that is said to be the
Mixed graph.
Cyclic Graph:In directed graph which starts from source node to destination node. The source and destination
nodes are the same. There is a loop can be formed. That is the Cyclic graph.
Multi Graph:Which graph has some parallel edges then that graph is said to be Multi graph.
Simple Graph:A graph which has no parallel edges then that graph is said to be Simple graph.
Graphs Representation:To represent a graph we have to represent two things: nodes and edges. Graphs are
generally represented either in "sequential representation" or "linked representation".
Sequential representation uses a two-dimensional array where as linked representation uses
a linked list. We refer graph means directed graphs unless specified otherwise.
Sequential Representation:A graph is conveniently represented by a matrix ( two-dimensional array) called adjacency
matrix ( or incidence matrix).A graph containing n nodes can be represented by a matrix
containing n rows and n columns.
Adjacency matrix:The Adjacency matrix A of a graph G=(V,E) with n nodes is an n*n matrix such that:
Aij={1 if there is an edge between vi and vj.
0 otherwise
essentially, adjacency matrix represents which vertices are adjacent, or rather, which two vertices
have an edge.

Directed Graph
Adjacency matrix for the above fig is:
ABCD
A0010
B1001
C0101
D1010
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

48

SEERLOGICA INFOTECH
Each position of adjacency matrix represents whether one node is connected to another
(value 1 or true) or not (value 0 or false).Note that it encodes the direction of the edges. For
example, since there is a 1 row B, column A, there is an edge from B to A.
Since there is no edge in the reverse direction (from A to B), row A, column B has a 0.
If a matrix contains only 0's and 1's then it is called bit matrix or Boolean matrix. The total
number of 1s in the matrix represents the number of edges in that directed graph.
The adjacency matrix for a undirected graph is a symmetric matrix. Because an edge (A, B)
means that both (A, B) and (B, A).

Fig: Undirected Graph


Adjacency matrix for the above fig is
ABCD
A0110
B1010
C1101
D0010
In Undirected graph ,the sum of a ith row elements gives the degree if ith node .In case of directed
graph, the sum of ith row elements give the out degree of the ith node and the sum of jth column
elements gives the in degree of the jth node.
The adjacency matrix for a null graph is null matrix.
i.e., all elements are zero. The adjacency matrix representation has a special importance if it was
multiples repetitively by itself. A non-zero for Aij element in the matrix. A^k represents that the
number of paths length k between vi and vj.

ABCD
A0010
Adjacency Matrix= A= B 1 0 0 1
C0101
D1010

Then A=

ABCD
A0101
B1020
C2011
D0111

ABCD
A2011
Then A=
B0212
C1131
D2112
Observe from the matrix A there are two paths of length 2 from B to C and C to A; and from
the matrix A,there are two paths of length 3 from A to A,B to B,B to D,D to A and D to D, and
three paths of length 3 from C to C. Sometimes for weighted graph, the presence of an edge in
adjacency matrix is represented by its weight instead of simply one.
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

49

SEERLOGICA INFOTECH
A small variation to adjacency matrix is "path matrix" which is useful to determine whether there
is a path between any two nodes in a graph; if there is a path between any vi and vj then the
corresponding element of path matrix contains 1 otherwise 0.
The path matrix for the above directed graph is
ABCD
A1011
B1011
C1011
D1011
Disadvantages of Adjacency Matrix:1) Graphs with few edges would have a lot of wasteful zeros in the adjacency matrix. That
is, the corresponding adjacency matrix is sparse.
2) Insertion and deletion of nodes is difficult.
Linked Representation:In this representation we maintain an adjacency list. In adjacency list, for each node, we keep a list
of all adjacent nodes.
AB
BD
CA
DA
Directed Graph

D
B

The adjacency list for the directed graph

Adjacing list structures using two dimensional array and single linked lists.

fig: Adjacency list structure using single linked list and double linked list
The linked representation, using linked list, maintain two kinds of lists; a node list
NODE and an edge list EDGE.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

50

SEERLOGICA INFOTECH
In node list, each node corresponding to a node in Graph G, and it contains the following
three fields:
a) NODE:-- contains the value of the node in the graph.
b) NEXT:-- contains a pointer that points to next node in the node list and
c) ADJACENT:-- contains pointer that points to the first node of adjacency list of the node
NODE NEXT ADJACENT
Each node in the node list can have other fields which may contain the information
associated with the node.
In edge list, each node corresponds to an edge of graph G.A node in the edge list contain
two fields.
a) TERMINAL- contains a pointer that points to node in the list which is terminal node
of the edge in the graph
b) PTR- contains a pointer that points to next node in the adjacency list which are all
initiated from same node in the graph.
TERMINAL PTR
Like node list, edge list also may have any other information, One such important field is
the weight field, if an edge is associated with weight.
In the adjacency list representation, each edge appears in two lists and thus the space usage
essentially doubles.
Graph Traversal:Traversal of a graph means that systematically visiting all nodes exactly once in the graph.
The two important traversal methods are "Breadth-first Search" and Depth-first Search
.The graph traversal start at an arbitrary vertex since there is no node as special.
Assume that each node in a graph will be in one of three states while traversing the graph:
ready state,
waiting state,
visited state.
Breadth-first Traversal:This strategy is much similar to level-by-level traversal of an ordered tree. Breadth-first
search operates by processing nodes in layers. The breadth-first search can begin at any arbitrary
node. The nodes which are adjacent to start node are processed first, and proceeds to adjacent
nodes of that nodes just visited. This process starts until all nodes are visited. If the traversal just
visited a node A, then it next visits all the nodes adjacent to A, keeping the node adjacent to these
in waiting list to be traversed after all nodes adjacent to A have been visited.
A data structure queue is used to place all waiting nodes. This queue is also convenient to
keep the track of nodes that are already visited, so that, a node is visited only once.
The general Breadth-first traversal algorithm is as follows:
1) All nodes are initialized as ready states and initialize queue to empty.
2) Begin with any node which is in ready state and put into queue. mark the status of that
node to waiting.
3) While queue is not empty do
Begin
4) Delete the first node k from queue and process it. Mark the status of that node to visited.
5) Add all the adjacent nodes of K which are in ready state to the rear side of the queue
and mark the status of those nodes to waiting.
End
6) If the graph still contains nodes which are in ready state then goto step2.
7) Return.
The step6 in the above algorithm handle those nodes which does not have a path from starting
node to them.
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

51

SEERLOGICA INFOTECH

The above fig shows the visiting nodes in breadth-first traversal. Numbers on the nodes
indicate the sequence of nodes visited in Breadth-first traversal.
Depth-first traversal:The depth-first traversal of a graph is much similar to preorder traversal of an ordered tree.
The traversal of a graph start at any arbitrary node, say A. Suppose b, C, D and E be the nodes
adjacent to A. Then we will next visit b and keep C,D, and E waiting. After visiting B we traverse
all the vertices to which it is adjacent before returning to traverse C,D and E.
In the depth-first traversal, we backtrack on a path once it reached the end of that path. We
consider the data structure stack instead of a queue as in breadth-first traversal.

The above fig shows the visiting nodes in depth-first traversal. Number on the nodes indicates the
sequence of nodes visited in depth-first traversal.
Algorithm:1) All nodes are initialized to ready state and initialize stack to empty.
2) Begin with any node which is in ready state and push into stack. Mark the status of that
node to waiting.
3) While stack is not empty do
Begin
4) pop the top node k of stack and process it. Mark the status of that node to visited.
5) Push all the adjacent nodes of k which are in ready state into stack and mark the status of
those nodes to waiting.
End.
6) If the graph still contains nodes which are in ready state then
goto step2
7) Return.
The depth-first traversal continues progressively deeper in a recursive manner.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

52

SEERLOGICA INFOTECH
Spanning Tree:There is a common problem associated with weighted graphs that of finding a minimal spanning
tree for each connected component.
A spanning tree for an undirected graph G is a graph T consisting of the nodes of G together with
enough edges from G such that:
1) There is a path between each pair of nodes in T.
2) There are no simple cycle in T.
It should be clear that if G is connected if and only if there is a spanning tree for G. Thus,
there is a spanning tree for every connected component of a graph.
If a graph G=(V,E) contain N nodes, then the spanning tree for that graph contains N-1
edges. The edges of spanning tree are subset of E.
In general, it is possible to construct different spanning trees for a graph, G.
For any spanning tree, we could pick any node as root and that would provide a parentchild relationship for the nodes connected by each node.
A minimal spanning tree for a weighted graph G is a spanning tree such that the
sum of its weights is less than or equal to the sum of its weights of every other spanning tree for G.
That is in a minimal spanning tree the sum of weights of the edges is as small as possible.

All these are the spanning trees for the above graph G.
Suppose wij is weight associated to each edge eij of spanning tree Tspan ,then the
minimum spanning tree is created such that
Tmin-span =sum{wij\all eij Espan}is a minimum.
There are several algorithms for creating minimum spanning tree for a weighted graph.
The number of edges in the minimum spanning tree of a graph is |V|-1.
Where V is the number of vertices.
The minimum spanning tree is a tree because it is acyclic,it is spanning because it covers every
edge, and it is minimum .Example for minimum spanning tree is wire a house with a minimum
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

53

SEERLOGICA INFOTECH
spanning tree of a weighted Graphs.
1)Prims Algorithm
2)krushkals Algorithm
Prims Algorithm (Prims Algorithm):One way to compute a minimum spanning tree is to grow the tree in successive stages. In
each stage, one node is picked as a root, and we add an edge, and thus an associated vertex, to the
tree.
At any point, we can see that we have a set of vertices that have already been included in
the tree; the rest of vertices have not. The algorithm then finds, at the edge (u,v) such that the cost
of (u,v) is the smallest among all edges where u is in the tree and v is not.
In this we keep two values dv and pv and an indication of whether it is known or unknown.
dv is the weight of the shortest arc connecting v to know vertex. pv is the last vertex to
cause a change in dv. After a vertex v is selected, for each unknown w adjacent to
v,dv=min(dw,cw,v).

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

54

SEERLOGICA INFOTECH
For the above graph initially v1 is in the tree as a root with no edges. Each step add one
edge and one vertex to the tree. The initial configuration of the table is shown v1 is selected, and
v2,v3 and v4 are updated. The next vertex selected is v4.Every vertex is adjacent to v4.v1 is not
examined because it is known to.V2 is unchanged, because it has dv=2 and the edge cost from v4
to v2is 3 all the rest are updated. The next vertex chosen is v2.This does not affect any distances.
Then v3 is chosen, which affects the distance in v6. The edges in the spanning tree can be read
from the table:(v2,v1), (v3,v4),(v4,v1),(v5,v7),(v6,v7),(v7,v4). The total cost is 16.
kruskals Algorithm:It is continually selects the edges in order of smallest weight and accept an edge if it does
not cause a cycle. Formally, kruskals algorithm maintains a forest a collection of trees.
Initially, there are |v| single-node trees. Adding an edge merges two trees into one. When the
algorithm terminates, there is only one tree , and this in the minimum spanning tree.
The algorithm terminates when enough edges are accepted. It turns out to be simple to decide
whether edge (u,v) should be accepted or rejected.
The invariant we will use is that at any point in the process, two vertices belong to the
same set if and only if they are connected in the current spanning forest. Thus, each vertex is
initially in its own set. If u and v are in the same set, the edge is rejected, because since they are
already connected, adding (u,v) would form a cycle. Otherwise, the edge is accepted,and a union is
performed on the two sets containing u and v.
The worst-case running time of this algorithm is O(|E|log|E|).

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

55

SEERLOGICA INFOTECH
We can start looking for all vertices that are a distance 1 away from s. These can be found by
looking at the vertices that are adjacent to S. Like this v1 and v6 are one edge from S.

Shortest-Path Algorithms:The input is a weight graph. Associated with each edge (vi,vj) is a
n-1
cost Ci,j to traverse the arc. The cost of a path v1,v2..........vn is Ci,i+1.
I=1
This is referred to as the weighted path lenght .The unweighted path length is
merely the number of edges on the path, namely n-1.
Unweighted Shortest Paths:In unweighted graph g using some vertexs. Which is an input parameter, we would
like to find the shortest path from s to all other vertices. We are only interested in the number of
edges contained on the path, so there are no weights on the edges.

Suppose we choose 's' to be v3.Immediately,we can tell that the shortest path from s to v3 is then a
path of length 0.We can mark this information, obtaining the graph vertices v2 and v4 having
shortest path 2 from s. and finally vertices v5 and v7 having shortest path 3 from s.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

56

SEERLOGICA INFOTECH
This strategy for searching a graph is known as breadth-first search. It operates by
processing vertices in layers: the vertices closest to the start are evaluated first, and the most
distant vertices are evaluated last. This is much the same as a level-order traversal for trees.
For each vertex, we will keep track of 3 pieces of information. First, we will keep its distance
from 's' in the entry dv. Initially al vertices are unreachable except for s, whose path length is 0.The
entry in pv is the bookkeeping variable, which will allow us to print the actual paths. The entry
'known' is set to 1 after a vertex is processed. Initially, all entries are unknown, including the start
vertex. when a vertex is known, we have a guarantee that no cheaper path will ever be found, so
processing for that vertex is essentially complete.
Dijkstra'as Algorithm:This is for finding the shortest path between two nodes in a weighted graph represented by a
weight matrix. That implementation was O(n2),where n is the number of nodes in the graph.
for (all nodes i)
{
distance[i]=INFINITY;
perm[i]=NONMEMBER;
}
perm[s]=MEMBER;
distance[s]=0;
current=s;
while(current!=t)
{
dc=distance[current];
for(all nodes i that are successors of current)
{
newdist=dc+weight[current][i];
if(newdist<distance[i])
{
distance[i]=newdist;
precede[i]=current;
}
}
k=the node k such that perm[k]==NONMEMBER and such that distance[k]is smallest;
current=k;
perm[k]=MEMBER;
}
*pd=distance[t];
At each stage Dijkstra's algorithm selects a vertex v, which has the smallest d v among all the
unknown vertices, and declares that the shortest path from s to v is known. The remainder of a
stage consists of updating the values of dw.
d w = d v+cv,w.

In the above graph G the initial configuration, assuming that the start node s is
v1.The selected is v1 with path length 0. This vertex is marked known. Now that v1 is known, some
entries need to be adjusted. The vertices adjacent to v1 and v4.
57
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

SEERLOGICA INFOTECH
Next v4 is selected and marked known. Vertices v6,v7 are adjacent, and it turns out that all require
adjusting.
v Known dv pv
v Known dv pv
v1
1
0 0
v1
1
0 0
v2
1
2 v1
v2
0
2 v1
v3
0
3 v4
v3
0
3 v4
v4
1
1 v1
v4
1
1 v1
v5
0
3 v4
v5
0
3 v4
v6
0
9 v4
v6
0
9 v4
v7
0
5 v4
v7
0
5 v4
After v4 is declared known
After v2 is declared known
v Known dv pv
v1
1
0 0
v2
1
2 v1
v3
1
3 v4
v4
1
1 v1
v5
1
3 v4
v6
0
8 v3
v7
0
5 v4
After v5 is declared known

v Known dv pv
v1
1
0 0
v2
1
2 v1
v3
1
3 v4
v4
1
1 v1
v5
1
3 v4
v6
0
6 v7
v7
1
5 v4
After v7 is declared known

v Known dv pv
v1
1
0 0
v2
1
2 v1
v3
1
3 v4
v4
1
1 v1
v5
1
3 v4
v6
1
6 v7
v7
1
5 v4
After v6 is declared known and algorithm terminates

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

58

SEERLOGICA INFOTECH
HASHING
Hashing is another important search technique that available for searching which is
virtually independent of the size of the space being searched. Frequently, an application will need
to search a key item for a collection of items (or records).
Mainly This hashing technique transforms the search key item into an address of that item
in a table called LOOK_UP_TABLE or HASHTABLE or DIRECTADDRESSTABLE. The
transformation is generally carried out by Hash function. The maintenance of hash function is
called HASHTABLE.
HASH TABLE
This is also called as direct address table. If we have a collection of n elements, whose Keys
are Unique integers in the range 1 to m. Where m>=n, then we can store the items in a DAT, T
where Ti is either empty or contains one of the elements of our collection.
The range of the key determines the size of hash table. Actually in addition to the Key, may
also contain other information. Whenever an element is placed in the DAT, that key is used to
determine its position. Whenever a search for a given element is performed. To, search for a key,
say K in a hash table. We can access it directly as the Kth element (tk). If hash table contains this
element, it returns it, otherwise it return NULL Value.
Clearly, it can be viewed that searching a direct address table is an 0(1) operation. The two
requirements of a Direct address table are;
(a) The Keys must be Unique and,
(b) The range of key must be severely bounded.
Direct addressing can be generalized to a situation where a function H(k) maps to K to
a value in the range 10 to m. That is ,
H(K)==>[1,m]
WE place the elements in T[H[k]] rather than T[K] and we can search in 0(1) time as before .This
indicates that keys need not in the range 1 to m.
Hashing Techniques
HASHING FUNCTIONS
The direct address approach requires that the function ,H(K) is a one-one mapping
from each K to integers in (1,m).Such a function is known as PERFECT HASHING FUNCTION.
It maps each key to a distinct integer within same manageable range and enables us to
trivially build on O(1) search time table.
Hash function produces a nearly randomly distributed integer code for every element
to be searched.
KEY-------------->HASHFUNCTION------------>ADDRESS
There are many different hashing functions which can be devised.
The following some methods are used for hashing functions.
DIVISION-REMINDER METHOD: Mainly this method is used for the founding the key value of or the location of the hash
function. For this we remember the some formula i.e.
==> HASH (KEY)=KEY mod P
WHERE;
Hash (key) is the hash function. KEY' is the target element to be searched and 'P' is
some integer preferably a PRIME NUMBER.
The Operator mod gives the remainder value after division. This gives the address of
the elements in the look-up-table in the range 0 to p-1. And that size of hash table is atleast 'P'.
For Example: If P=11 and key =4536
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

59

SEERLOGICA INFOTECH
then
HAS(4536)=4536 mod 11
=4
Thus;
The element with the key 4536 is mapped to the table, location address(index) is '4'.
In this division -Reminder method, we find the index value (or) key of Hash table by
using the range of Prime factors. That gives the index or key value of hash function.
MIDDLE SQUARE METHOD:In this middle square method, the address is computerized by squaring the key element and
selecting an appropriate number of bits from the middle of squared number.
The number of bits selected to obtain the address depends on the table size. For all
elements the same bit positions must be used.
Example:Suppose the key is 352,
And squaring it we get 123904.
The meaning of Hash is independent of the size of the space being searched. Frequently, an
application will need to search a key item for a Collection of items or records. Hashing techniques
transform the search key item into address of that item in the table.
If the hash table requires four digits address then select bits from 2nd digits to 5th digits
resulting 2390.
In this method, we find the key element 'x' then squaring it and left the places one digit
from left end and other digit from right end. This gives the resulting of the kth element of hashing.
This method takes the lot of computations and time taking process. This is the disadvantage
of Middle square method. So, we will go for another method.
FOLDING METHOD:This, method divides the given key into parts based on the number of bits required for the
address.
Summing all the parts, omitting the carry, if any will result the address.
Suppose, the key element is 5647832 and the number of address digits required is '3'.The '3'
digit parts of the key namely 564,783, and 2 are added.
Then, give the result is;
Which results the address is 344.
One, of the main problems, in Hashing is that for many keys the hash function may
produce same address. Finding a PERFECT HASH FUNCTION is always is not correct.
For Example:Suppose, we can find a hash function H(K),which maps most of the Keys onto unique integers, but
maps a small number of keys as same integer. This situation is said to be COLLISION.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

60

SEERLOGICA INFOTECH
Analysis of Algorithms
Definition: The method of solving a problem is known as an algorithm. It is a sequence of instructions
that act on some input data to produce some output in a finite number of steps.
Properties:a) Input: An algorithm must receive some input data supplied externally.
b) Output: An algorithm must produce atleast one output as the result.
c) Finiteness: The algorithm must terminate after a finite number of steps.
d) Definiteness: The steps to be performed in the algorithm must be clear and unambiguous.
e) Effectiveness: One must be able to perform the steps in the algorithm without applying any
intelligence.
All algorithms basically fall under two broad categories-Iterative and Recursive algorithms.
Iterative Algorithms typically use loops and conditional statements.
Recursive Algorithms use a divide and Conquer strategy. As per this, the recursive algorithm
breaks down a large problem into small pieces and then applies the algorithm to each of these
small pieces. Determining which algorithm is efficient than the other involves analysis of
algorithms. While analyzing, time required to execute it determined .time represents the
number of operations that are carried out while executing the algorithm.
While analyzing iterative algorithms we need to determine how many times the loop is
executed. To analyze a recursive algorithm one needs to determine amount of work done for three
things:
i. breaking down the large problem to smaller pieces.
ii. Getting solution for each piece and combining the individual solutions to get the solution to the
whole problem.
iii. Combining this information and the number of the smaller pieces and their sizes, we then need
to create a recurrence relation for the algorithm.
Analysis:The analysis of an algorithm provides information that gives us a general idea of how long
an algorithm will take for solving a problem. For comparing the performance of two algorithms we
have to estimate the time taken to solve a problem using each algorithm for a set of N input values.
Analysis of algorithms gives us the scientific reason to determine which algorithm should be
chosen to solve the problem. The purpose of determining the number of comparisons is to then use
them to figure out which of the algorithms under consideration can solve the problem more
efficiently.
What Analysis Does nt Do:The analysis of algorithms does not give a formula that helps us determine how many
seconds or computer cycles a particular algorithm will take to solve a problem. The analysis of
algorithm should be done regardless of the computer on which the program that implements the
algorithm is going to get executed.
Things to Count and Consider:i. The significant operation or operations in the algorithm must be identified first.
ii. Operations integral to the algorithm and which merely contribute to the overheads should be
determined next.
Comparison or arithmetic are two classes of operations that typically chosen for the
significant operation.
Cases To Consider During Analysis:Multiple input sets must be considered while analyzing an algorithm.
a) Best Case Input:This represents the input set that allows an algorithm to perform most quickly with this input
the algorithm takes shortest time to execute, as it causes the algorithms to do the least amount of
work. No matter how large is the input, searching in a best case will result in a constant time of 1.
Since the best case for an algorithm would usually be very small and frequently constant value, a
best case analysis is often not done.
61
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

SEERLOGICA INFOTECH
b) Worst Case Input:
This represents the input set that allows an algorithm to perform more slowly.Worst case is
an important analysis because it gives us an idea of the most time an algorithm will ever take.
Worst case analysis requires that we identify the input values that cause an algorithm to de the
most work.
c) Average Case Input:
This represents the input ser that allows an algorithm to deliver an average performance.
Doing average case analysis is a four step process.
These steps are as follows:
i. Determine the number of different groups into which all possible input sets can be divided.
ii. Determine the probability that the input will come from each of these groups.
iii. Determine how long the algorithm will run for each of these groups. All of the input in
each group should take the same amount of time, and if they do not, the group must be split into
separate groups.
Calculate average case time using the formula:
m
A(n)=pi*ti where
i=1
n=size of input
m=number of groups
pi=probability that the input will be from group i
ti= time that the algorithm takes for input from group i.

Rates Of Growth:While doing analysis of algorithm we must consider what happens when the size of the
input is large, because small input sets can hide rather dramatic differences.
Algorithms can be grouped into three categories based on the order of the function or
related algorithm.
a) Algorithm that grow atleast as fast as same function.
b) Algorithms that grow at the same rate.
c) Algorithms that grow no faster.
The categories mentioned above are commonly known as Big Omega (f),Big oh O(f)
and Big Theta (f) respectively.
Of these, the Big Omega category of functions is not of much interest o us since for all
values of n greater than same threshold value no all the functions in (f) have values that
are at least as large as f(i.e.) all functions in this category grow as fast as f or even faster. Big Oh
O(f) category represents the class of functions that grow no faster than f. This means that for al
values of n greater than same threshold number all the functions in O(f) have values that are no
greater than f.
Worst Case Analysis:
These are two worst case for the sequential search algorithm:
-The value being searched matches the last element in the list
-The value being searched is not present in the list.
Average Case Analysis:
There are two average case analyzes that can be done for a search algorithm. The first
assumes that the search is always successful and the other assumes that the value being searched
will sometimes not be found
Performance Analysis:
Criteria upon which can judge an algorithm includes.
1. Does it do what we want it to do
2. Does it work correctly according to the original specifications of the task?
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

62

SEERLOGICA INFOTECH
3. Is there documentation that describes how to use it and how it works?
4. Are procedures created in such a way that they perform logical sub functions?
5. Is the code readable?
These are other criteria for judging algorithms that have a more direct relationship to performance.
These have to do with their computing times and storage requirements.
Space Complexity:
The space complexity of an algorithm is the amount of memory it needs to run to completion.
1)Example: Algorithm abc(a,b,c)
{
return a+b+b*c+(a+b-c)/(a+b)+4.0;
}
Algorithm abc computes a+b+b*c+(a+b-c)/(a+b)+4.0;
2)Example: Algorithm sum(a,n)
[ s:=0.0;
for i:=1 to n do
s:=s+a[i];
return s;
}
n
Algorithm sum computes a[i] iteratively where the a[i] s are real numbers.
I=1

3)Example: Algorithm Rsum(a,n)


{
if(n<=0) then return 0.0;
else return Rsum(a,n-1)+a[n];
}
n
Algorithm Rsum is a recursive algorithm that computes a[i];
i=1

The space needed by each of these algorithms is seen to be the sum of the following components
1. A fixed part that is independent of the characteristics of the input and outputs this part typically
includes the instruction space (that is space for the code) space for simple variables and fixed size
component variables (also called aggregate) space for constants and so on.
2. A variable part that consists of the space needed by component variables whose size is
dependent on the particular problem instance being solved, the space needed by referenced
variables and recursion stack space
. * the space required s(p) of any algorithm p may therefore be written as
s(p)=c+sp(instance characteristics) where c is a constant.
When analyzing the space complexity of an algorithm, we concentrate solely on estimating sp.
Time Complexity:The time complexity of an algorithm is the amount of computer time it needs to run to
completion. The time T(p) taken by a program P is the sum of compile time and the run time. The
compile time does not depend on instance characteristic consequently we concern ourselves with
just the runtime of the program.
This runtime is denoted by (instance characteristics) tp.
tp(n)=CaADD(n)+Cm MUL(n)+cd DIV(n)+-----------where n denotes the instance characteristics, and Ca, Cs, Cm, Cd and so on respectively,
denote the time needed for an addition subtraction, multiplication, division and so on and ADD,
SUB, MUL, DIV and so on are functions whose values are the number of additions, subtractions,
multiplications, divisions and so on that are performed when the code for p is used on an instance
with characteristic n.
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

63

SEERLOGICA INFOTECH
Obtaining such an exact formula is in itself an impossible task since the time needed for an
addition, subtraction and depends on the numbers being added, subtracted and so on.
The value of tp(n) for any given n can be obtained experimentally . The execution time is
physically clocked and tp(n) obtained. We can go one step further and count only the number of
program steps.
A program step is loosely defined as a syntactically or semantically meaningful segment of
a program that has an execution time that is independent of the instance characteristics.
The number of steps any program statement is assigned depends on the kind of statement. For
example, comments count as zero steps, in an iterative statement such as the for, while and repeat
until statements, we consider the step count only for the control part of the statement.
The control parts for for and while statements have the following forms:
for i:=[expr] to [expr1] do
while[(expr)] do
Each execution of the control part of a while statement given a step count equal to
the number of step counts assignable (expr).
The step count for each execution of the control part of a for statement is one, unless the
counts attributable to and are functions of the instance characteristics. In this latter case, the first
execution of the control part of the for has a step count equal to the sum of the counts for and.
Methods to determine the step count:1. We introduce a new variable, count into the program.
This is a global variable with initial value 0.
when the statement s to increment count are introduced into Algorithm sum, the result is
1.Algorithm sum(a,n)
2.{
3.s:=0.0;
4.count:=count+1://count is global; it is initially zero
5.for i:=1 to n do
6.{
7.count:count+1;//for for
8.s:=s+a[i];count:=count+1;//for assignment
9.}
10.count:=count+1;//for last time of for
11.count:=count+1;//for the return
12.return s;
13.}
A simplified version of the above algorithm is
1.Algorithm Sum(a,n)
2.{
3.for i:=1 to n do count:=count+2;
4.count:=count+3;
5.}
Both the algorithms compute the same final value for count. In the for loop, the value of
count will increase by a total of 2n. If count is zero to start with, then it will be 2n+3 steps.
Asymptotic Notation(O,,):The functions f and g are nonnegative functions.
1) Definition:-[Big oh]
The function f(n)=O(g(n)) iff there exists positive constants c and n0 such that f(n)<=c*g(n) for all
n, n>= n0
Ex:3n +3<=4n for all n>=3
2) Definition:-[omega]
The function f(n)=(g(n)) iff there exists positive constants c and n0 such that f(n)<=c*g(n) for
all n, n>= n0
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

64

SEERLOGICA INFOTECH
Ex:100n +6= (n) as 100n+6>=100n for n>=1
3) Definition:-[Theta]
The function f(n)= (g(n)) iff there exists positive constants c1, c2 and n0 such that
c1g(n)<=f(n)<=c2g(n) for all n,n>= n0
Ex: 3n+2= (n) as 3n+2>=3n for all n>=2 and 3n+2<=4n for all n>=2,so c1=3,c2=4 and n0 =2.
The theta notation is more precise than both big oh and omega notations.
4) Definition:-[little oh] The function f(n)= o(g(n)) iff
lim f(n)/g(n) =0
n->
Ex:3n+2=o(n) since lim 3n+2/n2 =0
n->
5) Definition:-[little omega] The function f(n)= w(g(n)) iff
lim g(n)/f(n) =0
n->

The Big OH Notation:


If f(n) and g(n) are functions defined for positive integers, then to write f(n) is O(g(n))
which means that there exists a constant C such that |f(n)|<=C|g(n)| for all sufficiently large
positive integers n.
Here f(n) will normally be the operation count or time for some algorithm then O(n) means
that the time is bounded by a constant; O(n) means that the time is directly proportional to n and is
called linear time. O(2^n ) is exponential time and O(log n) and O(n log n) are logarithmic time.
Big O and its utility. Big O->f(n)-O(g(n)) if there exists two constants C and no such that
|f(n)|<=c|g(n)| for all n>= no.
Utility:
f(n) will normally represent the computing time of some algorithm. When we say that the
computing time of an algorithm is O(g(n)) we mean that its execution takes no more than a
constant times g(n).n is a parameter which characterizes the input and/or output.
i) Big O is transitive:It is easy to show that if f(n) is O(g(n)) is O(h(n)),f(n) s O(h(n)).
e.g:n+100n is O(n),n is and O( n ) consequently n +100n is O( n ). This is called
transitive property.
ii) Big O is multiplicative:
A constant computing time is referred to as O(1),O(1) is better than O(n),which in tern is
better than O(n).O(n)is worse and O(2^n) is awful.
One other frequently seen computing time is O(log n base 2)which is better than O(n).
Its complexity increases in multiple as n increases, hence it is multiplicative. Total number
of key comparisons by Quick Sort algorithm for an unordered array is O(nlog n) and for ordered
array is O(n).
For an unsorted array if we are lucky then each time a record is correctly positioned the sub
file to its left will be of the same size as that to its right. This would leave us with the sorting of
two sub files each of size roughly n/2. The time required to position a record in the file of size n is
O(n). If T(n) is the time taken to sort a file of n records then when the file splits roughly into two
equal parts each time a record is positioned correctly we have
T(n)<=Cn+2T(n/2) for some constant c
<=Cn+2(Cn/2+2T(n/4))
<=2Cn+4T(n/4)
<=Cnlogn+nT(1)
=O(nlogn)
Sorted List:
If the list sorted then the first element will require n comparisons to recognize that it
remains in final position. The sub list will be empty and second one will have n-1 elements. Thus
the second element require n-1 comparisons to recognize that it remain in second position and so
on. Thus there will be a total of
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

65

SEERLOGICA INFOTECH
f(n)=n+(n-1)+........2+1
=n(n+1)/2= n /2+O(n)
= O( n )
*The average number of key comparisons by quick sort algorithm is O(nlogn).
The running time of a sorting algorithm is usually measured by the number f(n) of
comparisons required to sort n elements. The quick sort algorithm has a worst case running time of
order n/2, but an average case running time of order nlogn.
The worst case occurs when the list is already sorted. Then the element will require n
comparisons to recognize that it remain in the first position. Furthermore, the first sub list will be
empty, but the second sub list will have n-1 elements. Accordingly, second element will require n1 comparisons to recognize that it remains in the second position and so on. Consequently there
will be total of
f(n)=n+(n+1)+.....2+1
=n(n+1)/2= n /2+O(n)
=O( n )comparisons.
The complexity f(n)=O(nlogn) of the average case comes from the fact that, on the average,
each reduction step of the algorithm produces two sub lists.
Accordingly:
1) Reducing the initial list places 1 element and produces 2 sub lists.
2) Reducing the 2 sub list places 2 elements and produce 4 sub lists and so in.
The reduction step in the k th level finds the location of 2^k-1 elements; hence there will be
approximately logn level of reduction steps.
Futher more, each level uses at most n comparisons, so
f(n)=O(nlogn)
In fact, mathematical analysis and empirical evidence hence both shown that
f(n)~1.4[nlogn]
is the expected number of comparisons for the quick sort algorithm.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

66

SEERLOGICA INFOTECH
1. _________ symbol is used to represent decision making in flowcharts?
2. C follows ___________________approach?
3. _________ is used to convert the code of high level language to Assembly language?
4. What are the C Tokens?
5. ________________ used to refer the names of variables, functions and arrays?
6. What is the range of values for int data type?
7. Values can be assigned to variables by using which operator?
8. What is the another name for conditional operator?
9. What is a bi directional control statement?
10. If the label: is placed after the go to label; it is called _________________
11. Which operator is used to increment the value of the variable by 1?
12. sizeof (long int) is __________
13. a=15, b=10, c= - - a b, d=b--+++a printf(%d,(c>d)? 1:0
14. printf(%06d,9876) = ____________
15. Which symbol is used to give the process in flowcharts
16. name [20] = NEWDELHI 110001 printf(%7s,name)_____________________
17. name [20] = NEWDELHI 110001 printf(%.7s,name)_____________________
18. a=5, printf(%d%d%d,a++,a,++a); _____________________
19. 14 % -3 =________________________
20. \b used for _______________
21. Each case statement in switch () is separated by which statement?
22. #define N 5 m 10 is this a valid statement?
23. Which bit wise operator is suitable for checking whether a particular bit is on or off?
24. Which bit wise operator is suitable for turning off a particular bit in a number?
25. Which bit wise operator is suitable for putting on a particular bit in a number?

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

67

SEERLOGICA INFOTECH
1.

(Rhombus)

2. Top Down
3. Compiler

/ Interpreter

4. Keywords, Identifiers, Constants, Operators, Strings, Special Symbols


5. Identifier
6. -32,768 to 32,767
7. Assignment Operator (=)
8. Ternary Operator
9. Goto
10. Forward Jump
11. Increment Operator
12. 4 Bytes
13. 0 (a=15, b=9, c=4, d= 35)
14. 009876
15.

(Rectangle)

16. NEWDELHI 110001


17. NEWDELH
18. 6 6 6
19. 2
20. Backspace
21. Break
22. Not Valid ( , (comma) between 5 and m)
23. Bitwise OR (|)
24. Bitwise And (&)
25. Bitwise OR (|)

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

68

SEERLOGICA INFOTECH
1. Where are the auto variables stored
2. Are the expressions arr and &arr same for an array of integers?
3. Can a Structure contain a Pointer to itself?
4. What are register variables? What is the advantage of using register variables?
5. What is the use of typedef?
6. What is a pointer?
7. What is a structure?
8. Array is collection of____________
9. Array elements are stored in _________________memory locations
10. A character array always ends with ________________
11. If you declare array without static, the elements it will be set to ___________
12. All array subscripts begin with __________________
13. An array having more than one subscript is called _________________
14. s1 = Welcome to , s2 = SeerLogica , strcat(s1,s2) is _________________
15. The main( ) _________________ function
16. the string will always terminate with _________
17. x = z-1, then x = _______________
18. Recursion is a process in which the function calls_______________
19. s1[10]=welcome l = strlen(s1) then l = ___________________
20. s1[10] = their,s2[10] = there ,x=strcmp(s1,s2) then x = _______________
21. call by value method refers to _____________________
22. Call by reference method used to __________________
23. Difference between strdup and strcpy
24. What do the 'c' and 'v' in argc and argv stand for?
25. What the advantages of using Unions

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

69

SEERLOGICA INFOTECH
1. RAM
2. Same (this is for only arrays but not normal variable)
3. Yes
4. Variables which stores in register are register variable. They faster than others.
5. For creating our own data types
6. Pointer is a variable which stores the address of another variable.
7. Structure is a collection different types.
8. Same data types.
9. Continues or Sequential
10. \0 ( Null Character)
11. Garbage Values
12. 0 (Zero)
13. Multi dimensional array
14. Welcome to SeerLogica
15. User defined function
16. \0 ( Null Character)
17. 121 ( ASCII value of z -1)
18. Itself
19. 7 (wont take Null character)
20. -9

( ASCI I i- ASCII r (105-114))

21. Value of the variable


22. Passing the address of the variable
23. strcpy will not allocate the memory for the copy for you, which means you have to give it
not only the pointer to the string to copy, but also a pointer to the place to copy it to, which
you have set up yourself. strdup will grab itself a place to copy the string to, which you will
have to free up later when you don't need the copy anymore.
24. Counter and Vector (Argc Argument Counter & Argv- Argument Vector)
25. Unions conserve memory space. The amount of space allocated for union is based on the
member which requires largest memory space...so unions are useful for applications
involving number of variables, where values need not be assigned to all elements at one
time..

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

70

SEERLOGICA INFOTECH

1.

Linked list _________________________ Data Structure.

2.

Calloc allocates __________________________________

3.

Construct a tree with nodes 15, 25,10, 45, 26.

4.

What is the default value of pointer __________________.

5.

__________ is preprocessor statements in C.

6.

int I=10; printf(%d%d%d%d,I++, ++I,I, I--); what is the out put?

7.

___________ measure accommodates applications in which algorithmic complexity is


high.

8.

What is meant by performance measurements in algorithms?

9.

The Instance of a class is _______________.

10.

Which sort show the best average behavior?

11.

What is Garbage Collection?

12.

How can you convert an SR Flip-flop to a JK Flip-flop?

13.

What is meant by dangling pointer?

14.

Linked list _________________________ Data Structure.

15.

We can initialize an array using________________ Keyword.

16.

By default function returns __________________

17.

The keyword void before the function name means_______________

18.

The default storage class is ________

19.

Actual parameters are _________________

20.

The keyword return is used in __________________

21.

Recursive function is ____________________

22.

which function is to convert float to string ____________

23.

Global Variables stores in ___________________

24.

____________ symbol is used to calling Macros

25.

Debugging means ___________________________


SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

71

SEERLOGICA INFOTECH

1. Non linear /dynamic


2. Multiple blocks of memory
3. 15
25
10
45
26
4. Garbage
5. #include
6. 10, 10, 9, 10
7. Theta
8. Time & space complexity
9. Object
10. Quick sort
11. Garbage Collection is performed by a garbage collector which recycles memory that it can
prove will never be used again
12. Place not between inputs
13. The pointer which points to empty space
14. Non linear /dynamic
15. Static
16. Integer
17. It wont return any value
18. Auto
19. Arguments in calling function
20. called function
21. function calling itself
22. fcvt()
23. Hard Disk
24.
25. The process of removing a bug from an algorithm is called as debugging.
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

72

SEERLOGICA INFOTECH

1. int a,b,*ptr; ptr=&a; a=9;

b=*ptr; a++;

Value of b is _____________

2. int a,b,*ptr; a=9; ptr=&a; b= *ptr; *ptr += 2; Value of a is _____________


3. What is the need of malloc() function.
4. What is the need of void pointer.
5. What is the need of & operator.
6. char *b=BOMBAY; sizeof (b) __________________
7. int i=3;

printf(%d,*(&i));

_______________

8. structure tag means _____________


9. Is it pointer can also store the address of the heterogeneous types of elements ? true /false
10. what is similar to structure with a difference in the way data is stored and retrieved?
11. What is the use of structures with pointers?
12. What is a collection of related variables under one name?
13. Which operator used to access the structure?
14. bit fields used for ___________data types
15. Which function reads characters from a file opened in read mode?
16. Which function erases the specified file
17. What is function proto type?
18. Which operator is for pointer structure members?
19. Default value of Register variable _________
20. What is type casting?
21. a =5 ; b= 15; c=a^b;

c=____________

22. a=5 b= a++ + a + a++ + ++a ;

b =___________

23. Which function is used to convert sting to float _______________


24. The function strcmp(str1,str2) returns
25. what is the purpose of realloc()

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

73

SEERLOGICA INFOTECH

1. What are basic operations of stack?


2. The time complexity of algorithm represented, in which notation?
3. What are applications of stacks?
4. What is the function used to release dynamically allocated memory?
5. Which operator has highest precedence in notation conversions?
6. Convert infix to prefix a+(b+c(c*d)+e)+f/g
7. Which is non primitive linear structure?
8. In empty queue what are the values of rear and front?
9. How many locations are used when a circular queue of size n?
10. The infix evaluation of postfix expression A*(B+C)
11. Which data structure follows first in first out
12. What is linked list?
13. Can we implement linked list by using stack? (T/F)
14. What function is used to resize the size of memory block?
15. In Stack insertions and deletions are made at one end i.e.?
16. What are the basic functions performed in stack?
17. Evaluate the postfix expression (ab+c*d)?
18. When do you say stack is empty and stack is full?
19. What is the significance of top in a stack?
20. How is queue different from stack?
21. What is the need of dequeue in queue?
22. What is circular queue?
23. Transfer infixes expression to postfix? (A-B)/(C*(C-D/C+D))
24. Convert into infix -/*A+BC-DE
25. What are applications of Queue?

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

74

SEERLOGICA INFOTECH

1. What is called each element in linked list?


2. Which field contains the actual values in linked list?
3. If the nodes are not present in linked list then it is called as?
4. What are the types in linked list?
5. In which directions the doubly linked list is traveled?
6. Which linked list is traveled in uni-directional?
7. How many linked fields are there in doubly linked list?
8. In doubly linked list the node contains?
9. Which are widely used to represent and manipulate polynomials?
10. What are the fields in the polynomial?
11. What are used to manipulate the sparse matrix?
12. What is a Sparse Matrix?
13. In a linked list what is the next field of the last node pointer?
14. What s a binary tree?
15. What is a tree?
16. What is a complete binary tree?
17. What are the types of tree traversals?
18. Define the graph?
19. What is the difference between tree and graph?
20. What is a null graph?
21. What are the maximum numbers of edges in an undirected graph?
22. Construct a binary tree of A+ (B + C * D + E) + F / G.
23. What is a complexity of a adjacency matrix graph?
24. What are the types of graph traversal?
25. What is a spanning tree?

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

75

SEERLOGICA INFOTECH

1. What is the basic operation in computer science?


2. What are the total comparisons in bubble sort?
3. What is sorting
4.

What is searching?

5. In which sort the sorting list is divided into two sub lists?
6. What is the other name of exchange sort?
7. What is the time complexity of linear search?
8. What is the time complexity of binary search?
9. What is the time complexity of bubble sort?
10. What is the time complexity of quick sort?
11. The number of swaps in the bubble sort is far less then that of a selection sort? T/F
12. In merge sort the merging operation is done using an auxiliary array? T/F
13. Binary search can be used on an unsorted list? True/False
14. What is the average time complexity of the Quick sort?
15. Which sorting technique not having swapping?
16. What is the advantage of the binary search?
17. What is heap?
18. What is quick sort?
19. What is the need for an ordered table searching?
20. What is Radix sort?
21. What is another name of Radix sort?
22. What the time complexity of the shell sort?
23. In how many categories the sorting algorithms are classified?
24. How many types of heaps are there?
25. In Which sort the numbers are converted in to binary number system?

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

76

SEERLOGICA INFOTECH
1. What does static variable mean?
2. What are the differences between structures and arrays?
3. In header files whether functions are declared or defined?
4. What are the differences between malloc() and calloc()?
5. What are macros? What are its advantages and disadvantages?
6. Difference between pass by reference and pass by value?
7. What is static identifier?
8. Where does global, static, local, register variables, free memory and C Program
instructions get stored?
9. Difference between arrays and linked list?
10. What are enumerations?
11. Describe about storage allocation and scope of global, extern, static, local and register
variables?
12. Can we specify variable field width in a scanf() format string? If possible how?
13. Out of fgets() and gets() which function is safe to use and why?
14. Differentiate between a for loop and a while loop? What are it uses?
15. What are the different storage classes in C?
16. Write down the equivalent pointer expression for referring the same element a[i][j][k][l]?
17. What is difference between Structure and Unions?
18. What are the advantages of using pointers in a program?
19. What is the difference between Strings and Arrays?
20. In a header file whether functions are declared or defined?
21. What is a far pointer? where we use it?
22. How will you declare an array of three function pointers where each function receives two
ints and returns a float?
23. what is a NULL Pointer? Whether it is same as an uninitialized pointer?

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

77

SEERLOGICA INFOTECH
24. What is a NULL Macro? What is the difference between a NULL Pointer and a NULL
Macro?
25. What does the error 'Null Pointer Assignment' mean and what causes this error?
26. What is near, far and huge pointers? How many bytes are occupied by them?
27. How would you obtain segment and offset addresses from a far address of a memory
location?
28. Does mentioning the array name gives the base address in all the contexts?
29. Explain one method to process an entire string as one unit?
30. What is the similarity between a Structure, Union and enumeration?
31. Can a Structure contain a Pointer to itself?
32. How can we check whether the contents of two structure variables are same or not?
33. How are Structure passing and returning implemented by the complier?
34. How can we read/write Structures from/to data files?
35. What is the difference between an enumeration and a set of pre-processor # defines?
36. Are the variables argc and argv are local to main?
37. What is the maximum combined length of command line arguments including the space
between adjacent arguments?
38. If we want that any wildcard characters in the command line arguments should be
appropriately expanded, are we required to make any special provision? If yes, which?
39. Does there exist any way to make the command line arguments available to other functions
without passing them as arguments to the function?
40. What are bit fields? What is the use of bit fields in a Structure declaration?
41. To which numbering system can the binary number 1101100100111100 be easily
converted to?
42. Which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an
unsigned int or char by 1?
43. Write a program to compare two strings without using the strcmp() function.
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

78

SEERLOGICA INFOTECH
44. Write a program to concatenate two strings.
45. Write a program to interchange 2 variables without using the third one.
46. Write programs for String Reversal & Palindrome check
47. Write a program to find the Factorial of a number
48. Write a program to generate the Fibinocci Series
49. Write a program which employs Recursion
50. Write a program which uses Command Line Arguments
51. Write a program which uses functions like strcmp(), strcpy()? etc
52. What are the advantages of using typedef in a program?
53. How would you dynamically allocate a one-dimensional and two-dimensional array of
integers?
54. How can you increase the size of a dynamically allocated array?
55. How can you increase the size of a statically allocated array?
56. When reallocating memory if any other pointers point into the same piece of memory do
you have to readjust these other pointers or do they get readjusted automatically?
57. Which function should be used to free the memory allocated by calloc()?
58. How much maximum can you allocate in a single call to malloc()?
59. Can you dynamically allocate arrays in expanded memory?
60. What is object file? How can you access object file?
61. Which header file should you include if you are to develop a function which can accept
variable number of arguments?
62. Can you write a function similar to printf()?
63. How can a called function determine the number of arguments that have been passed to it?
64. Can there be at least some solution to determine the number of arguments passed to a
variable argument list function?
65. How do you declare the following:
An array of three pointers to chars
An array of three char pointers
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

79

SEERLOGICA INFOTECH
A pointer to array of three chars
A pointer to function which receives an int pointer and returns a float pointer
A pointer to a function which receives nothing and returns nothing
66. What do the functions atoi(), itoa() and gcvt() do?
67. Does there exist any other function which can be used to convert an integer or a float to a
string?
68. How would you use qsort() function to sort an array of structures?
69. How would you use qsort() function to sort the name stored in an array of pointers to
string?
70. How would you use bsearch() function to search a name stored in array of pointers to
string?
71. How would you use the functions sin(), pow(), sqrt()?
72. How would you use the functions memcpy(), memset(), memmove()?
73. How would you use the functions fseek(), freed(), fwrite() and ftell()?
74. How would you obtain the current time and difference between two times?
75. How would you use the functions randomize() and random()?
76. How would you implement a substr() function that extracts a sub string from a given
string?
77. What is the difference between the functions rand(), random(), srand() and randomize()?
78. What is the difference between the functions memmove() and memcpy()?
79. How do you print a string on the printer?
80. Can you use the function fprintf() to display the output on the screen?
81. What is a data structure?
82. What does abstract data type means?
83. Evaluate the following prefix expression " ++ 26 + - 1324"
84. Convert the following infix expression to post fix notation ((a+2)*(b+4)) -1
85. How is it possible to insert different type of elements in stack?

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

80

SEERLOGICA INFOTECH
86. Stack can be described as a pointer. Explain.
87. Write a Binary Search program
88. Write programs for Bubble Sort, Quick sort
89. Explain about the types of linked lists
90. How would you sort a linked list?
91. Write the programs for Linked List (Insertion and Deletion) operations
92. What data structure would you mostly likely see in a non recursive implementation of a
recursive algorithm?
93. What do you mean by Base case, Recursive case, Binding Time, Run-Time Stack and Tail
Recursion?
94. Explain quick sort and merge sort algorithms and derive the time-constraint relation for
these.
95. Explain binary searching, Fibonacci search.
96. What is the maximum total number of nodes in a tree that has N levels? Note that the root
is level (zero)
97. How many different binary trees and binary search trees can be made from three nodes that
contain the key values 1, 2 & 3?
98. A list is ordered from smaller to largest when a sort is called. Which sort would take the
longest time to execute?
99. A list is ordered from smaller to largest when a sort is called. Which sort would take the
shortest time to execute?
100. When will you sort an array of pointers to list elements, rather than sorting the elements
themselves?

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

81

SEERLOGICA INFOTECH
101. The element being searched for is not found in an array of 100 elements. What is the
average number of comparisons needed in a sequential search to determine that the element
is not there, if the elements are completely unordered?
102. What is the average number of comparisons needed in a sequential search to determine
the position of an element in an array of 100 elements, if the elements are ordered from
largest to smallest?
103. Which sort show the best average behavior?
104. What is the average number of comparisons in a sequential search?
105. Which data structure is needed to convert infix notations to post fix notations?
106. What do you mean by:
Syntax Error
Logical Error
Runtime Error

How can you correct these errors?

107. In which data structure, elements can be added or removed at either end, but not in the
middle?
108. How will inorder, preorder and postorder traversals print the elements of a tree?
109. Parenthesis are never needed in prefix or postfix expressions. Why?
110. Which one is faster? A binary search of an ordered set of elements in an array or a
sequential search of the elements.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

82

SEERLOGICA INFOTECH
main()
{
int x=10,y=15;
x=x++;
y=++y;
printf("%d %d\n",x,y);
}
---------------------------------------------------------------------int x;
main()
{
int x=0;
{
int x=10;
x++;
change_value(x);
x++;
Modify_value();
printf("First output: %d\n",x);
}
x++;
change_value(x);
printf("Second Output : %d\n",x);
Modify_value();
printf("Third Output : %d\n",x);
}
Modify_value() { return (x+=10); }
change_value() { return(x+=1); }
--------------------------------------------------------------------------main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}

main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x2);
}
-------------------------------------------------------------------SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

83

SEERLOGICA INFOTECH
#define swap1(a,b) a=a+b;b=a-b;a=a-b;
main()
{
int x=5,y=10;
swap1(x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d\n",x,y);
}
int swap2(int a,int b)
{
int temp;
temp=a;
b=a;
a=temp;
return;
}
---------------------------------------------------------------------main()
{
char *ptr = "Ramco Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
--------------------------------------------------------------------#include<stdio.h
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
----------------------------------------------------------------#include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

84

SEERLOGICA INFOTECH
1. What is the error in the following sequence of program?
int i1;
switch(i1)
{
printf("The value of I1 is :");
case 1: printf("%d",i1);
break;
case 2: printf("%d",i1);
break;
default : printf("Invalid entry");
}
2. What is an error in the following sequence of a program?
int i1;
switch(i1)
{
case 1: goto lure;
break;
case 2: printf("This is second choice");
break;
default: printf("This is default choice");
}
void fun(void)
{
lure: printf("This is unconditional jump");
}
3. What is an error in the following sequence of a program?
int i;
switch(i)
{
case 1: printf("This is first choice");
break;
case j: printf("This is second choice");
break;
case 1+2+4: printf("This is the third and last choice");
break;
}
4. What is an error in the following sequence of a program?
int i;
switch(i)
{
default: printf("This is default value");
break;
case 1: printf("This is first choice");
break;
case 2: printf("This is the second choice");
}

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

85

SEERLOGICA INFOTECH
1. typedef struct{
char *;
nodeptr next;
} * nodeptr;
what does nodeptr stand for?
2. supposing thaty each integer occupies 4 bytes and each charactrer 1 byte,
what is the output of the following programme?
#include<stdio.h
main()
{
int a[] ={ 1,2,3,4,5,6,7};
char c[] = {' a','x','h','o','k'};
printf("%d\t %d ", (&a[3]-&a[0]),(&c[3]-&c[0]));
}
ans : 3
3. what is the output of the program?
#include<stdio.h
main()
{
struct s1 {int i; };
struct s2 {int i; };
struct s1 st1;
struct s2 st2;
st1.i =5;
st2 = st1;
printf(" %d " , st2.i);
}
ans: error. expl: diff struct variables should not assigned using "=" operator.
4.what is the output of the program?
#include<stdio.h
main()
{
int i,j;
int mat[3][3] ={1,2,3,4,5,6,7,8,9};
for(i=2;i=0;i--)
for(j=2;j=0;j--)
printf("%d" , *(*(mat+j)+i));
}
ans : 9 6 3 8 5 2 7 4 1
5.int fun( int n)
{
int i;
for(i=0;i<=n;i++)
fun(n-i);
printf(" well done");
}
How many times is the printf statement executed for n=10?
ans: zero
exp: Before reaching to printf statement it will goes to infinite loop.
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

86

SEERLOGICA INFOTECH
6.what is the output of the program?
main()
{
struct emp{
char emp[];
int empno;
float sal;
};
struct emp member = { "TIGER"};
printf(" %d %f", member.empno,member.sal);
}
ans: error. In struct variable emp[], we have to give array size. If array size
given ans is 0, 0.00
7. output of the program?
# define infiniteloop while(1)
main()
{
infiniteloop;
printf("DONE");
}
ans: none
exp: infinite loop in main ends with ";" . so loop will not reach end; and the DONE also
will not print.
8. output of the program?
main()
{
int a=2, b=3;
printf(" %d ", a+++b);
}
ans:5
exp: here it evaluates as a++ + b.
9. output of the program?
#define prn(a) printf("%d",a)
#define print(a,b,c) prn(a), prn(b), prn(c)
#define max(a,b) (a<b)? b:a
main()
{
int x=1, y=2;
print(max(x++,y),x,y);
print(max(x++,y),x,y);
}

ans: 3 4 2

10. which of the following is the correct declaration for the function main() ?
ans: main( int , char *[])
11. if ptr is defined as
int *ptr[][100];
which of the following correctly allocates memory for ptr?
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

87

SEERLOGICA INFOTECH
ans: ptr = (int *)(malloc(100* sizeof(int));

1.while((*p++=*q++)!=0){}
is equal to
expl: while((*p++=*q++)!='\0'){}
a) b) c) d)
2.the function strcmp(str1,str2) returns
3. int *x[](); means

ans: int

expl: Elments of an array can't be functions.

4.#define PRINT(int) printf("int=%d",int);


main()
{
int x,y,z;
x=03;y=-1;z=01;
PRINT(x^x);
z<<=3;PRINT(x); ---- I think here may be (z). for this ans=8.
if (x) ans ix =3.
y=3;PRINT(y);
}
expl: 0,8,-1 (if second is z)
5. struct list
{
int x;
struct list *next;
}*head;
the struct head.x =100
above is correct / wrong
expl: Before using the ptr type struct variable we have to give memory
to that. And also when ever the struct variable is ptr then we access the
members by "-" operator.
6. '-'=45 '/'=47
printfr(%d/n,'-','-','-','-','/','/','/');
o/p =?
ans: 45 ( i.e it takes first argument in printf function.
12.o/p=?
int i;
i=1;
i=i+2*i++;
printf(%d,i);
ans: 4
8.{
ch='A';
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

88

SEERLOGICA INFOTECH
while(ch<='F'){
switch(ch){
case'A':case'B':case'C':case'D':ch++;continue;
case'E':case'F':ch++;
}
putchar(ch);
}
} a)ABCDEF b.EFG c.FG d.error
ans: c
9. FILE *fp1,*fp2;
fp1=fopen("one","w")
fp2=fopen("one","w")
fputc('A',fp1)
fputc('B',fp2)
fclose(fp1)
fclose(fp2)}
a.error b. c. d.
ans: no error. But It will over writes on same file.
10. int a=1, b=2, c=3, *pointer;
pointer=&c;
a=c/*pointer;
b=c;
printf("a=%d b=%d",a,b);
a. a=1 b=3
b a=3 b=3
c3 2
d. error
ans: d . Because ";" indicates competion of that statement. so It give
error.
* Imp: And in above program " a=c/*pointer " statement it considering as
starting of comment statement. So , It also causing for syntax error.
11.#include<malloc.h
char *f()
{char *s=malloc(8);
strcpy(s,"goodbye")}
main()
{
char *f();
printf("%c",*f()='A');
o/p=?
ans: prints " A "

13. int sum(n)


int n;
if(n<1)return n;
else return(n+sum(n-1))
a 10 b 16 c 14 d 15
ans: If we take n=5 then ans is 15.
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

89

SEERLOGICA INFOTECH
14. when a function is recursively called all ,
automatic variables are a. stored in stack b . c. d
ans: (a)
15) #define MAN(x,y) (x)(y)?(x):(y)
{ int i=10;j=5;k=0;
k= MAX(i++,++j)
printf(%d %d %d %d,i,j,k)}
16) a=10;b=5; c=3;d=3;
if(a<b)&&(c=d++)
printf(%d %d %d %d a,b,c,d)
else printf("%d %d %d %d a,b,c,d);
19. what is o/p
#include<stdarg.h
show(int t,va_list ptr1)
{
int a,x,i;
a=va_arg(ptr1,int)
printf("\n %d",a)
}
display(char)
{int x;
listptr;
va_star(otr,s);
n=va_arg(ptr,int);
show(x,ptr);
}
main()
{
display("hello",4,12,13,14,44);
}
a) 13 b) 12 c) 44 d) 14
.............................................
17. if the following program (my prog)
main(int size of ,char *arg[])
{ while(size of arg) printf("%s",arg[--size of arg)
}
is run from the command line as myprog jan feb mar apr
what would be the o/p
a)myprog jan,feb,mar,apr
b)rev
c)jan,feb,mar,apr
d)error
.............................................
18.what is o/p
main()
{int i=3;
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

90

SEERLOGICA INFOTECH
while(i--)
{
int i=100
i--;
printf("%d..",i);
}
}
a) infinite loop
b) error
c) 99..99..99..99
d) 3..22..1..
.............................................
20)what is the o/p of the program
main()
{
int rows=3,colums=4;
int a[rows][colums]={1,2,3,4,5,6,7,8,9,10,11,12};
i=j=k=99;
for(i=0;i<rows;i++)
for(j=0;j<colums;j++)
if(a[k][j]<k) k=a[i][j];
printf("%d\n",k);

1) printf("%d%x\n",ox2,12);
2) int a=10;
int b=20;
a=a^b;
b=a^b;
a=a^b;
printf("%d%d\n",a,b);
3)enum {ELLIPSE, TRIANGLE, RECTANGLE, SQUARE=100, CIRCLE=5 }
printf{"%d%d%d%d\n",TRIANGLE-RECTANGLE,SQUARE*CIRCLE-RECTANGLE};
4) define the following...
a) pointer to a integer
b) pointer to a char
c) function pointer returning a pointer integer.
5) void a(void);
main() { a(); }
void a(void)
{
char a="HELLOW";
char *b="HELLOW";
char c[10]="HELLOW";
printf("%s%s%s\n",a,b,c);
printf("%d%d%d\n",sizeof(a),sizeof(b),sizeof(c)));
}
6) int a=15;
int b=16;
printf("%d %d \n",a&b,a/b);
(bitwise operators)
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

91

SEERLOGICA INFOTECH
7) int a[5],*p;
for(p=a;p<&a[5];p++)
{
*p=p-a;
printf("%d\n",*p);
}
8) scanf("xyz abc ABC 345" "% *[a-z A-Z]lf",&a);
printf("lf",a);
9) Not clear
fprintf(- - - - 10) main()
{
int i=10;
printf("%d",i);
{
int i=20;
printf("%d",i);
}
printf("%d",i);
}
11)struct class
{
int i;
float a;
string[12];
}
sizeof(class)=?
12) int *p;
i=10;
p=i;
printf("%d",*p);
13) fact(5)
int n;
fact(n)
{
sum=n*fact(n-1);
}

WHAT IS THE OUT PUT FOR FOLLOWING PROGRAMMS


1)main()
{
char a[2];
*a[0]=7;
*a[1]=5;
printf("%d",&a[1]-a)
ANS: may be 1.(illegal initialization)
2)
#include<stdio.h
main(){
char a[]="hellow";
char *b="hellow";
char c[5]="hellow";
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

92

SEERLOGICA INFOTECH
printf("%s %s %s ",a,b,c);
printf(" ",sizeof(a),sizeof(b),sizeof(c));
}
(ans is hellow,hellow,hellow 6,2,5 )
3)
#include<stdio.h
main(){
float value=10.00;
printf("%g %0.2g %0.4g %f",value,value,value,value)
}
(ans is 10,10,10,10.000000)
4)
#include<stdio.h
void function1;
int i-value=100;
main()
{
i-value=50;
function1;
printf("i-value in the function=",i-value);
printf("i-value after the function=",i-value);
}
printf("i-value at the end of main=",i-value);
functioni()
i-value=25;
THIS IS ROUGH IDEA OF THE PROGRAM
ANS ARE
1)i-value in the function=25;
2)i-value after the function=50;
3)i-value at the end of the main=100;
5)
main()
{
funct(int n);
{
switch(n)
case1:
m=2;
break;
case2:
m=5;
break;
case3:
m=7;
break;
default:
m=0;
}
1.Difference between arrays n pointers
2. what is the purpose of realloc()
3.what is static memory allocation and dynamic memory allocation?
4.how are pointer variables initialized?
SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

93

SEERLOGICA INFOTECH
5.how are pointer variables initialized?
6.are pointers integers?
7.what is a pointer variable?
8.What is a pointer value and address?
9.what is a method?
10.what are the advantages of the functions?
11.what is the purpose of main() function?
12.what is an argument? differentiate between formal arg's and actual arguments?
13.what is a function and built-in function?
14.what is modular programming?
15.when does compiler not implicitly generate the address of the first element of an array?
16.what are the characteristics of array in c?
17.differentiate between a linker and linkage?
18.what are advantages and disadvantages of external storage class?
19.differentiate between an internal static and external static variable?
20.what are the advs of auto variables?
21.what is storage class and what are storage variable?
22.what is the difference between far and near?
23.what is the purpose of realloc()?
1.3what is a static function?
1.4why should I prototype a function?
1.5how do u print an address?
1.6can math operations be performed on a void pointer?
1.7how can u determine the size of an allocated portion of memory?
1.8what is a "null pointer assignment" error? what are bus errors, memory faults, and core dumps?
1.9what is the diference between NULL and NUL?
1.10what is the heap?
1.11can the size of an array be declared at runtime?
1.12is using exit() the same as using return?
1.13when should be a far pointer be used?
1.14can the size of operator be used to tell the size of an array passed to a function?
1.15Is it better to use malloc() or calloc()?
1.16 when should a far pointer be used?
23.which expression always return true?which always return false?
..ans..expression if (a=0) always return false
expression if (a=1)always return true.
24.write the equivalent expression for x%8?
..ans..x&7
25.why n++ executes faster than n+1?
..ans..the expression n++ requires a single machine instruction such as INR to carry out the
increment operation
whereas,n+1 requires more instructions to carry this operation

1) abcD+abcd+aBCd+aBCD - then the simplified function is


(Capital letters are compliments of corresponding letters A=compliment of a)
[a] a [b] ab [c] abc [d] a(bc)* [e] none [(bc)*=compliment of bc]
Ans: e
------------------------------------2) A 12 address lines maps to the memory of
[a] 1k bytes [b] 0.5k bytes [c] 2k bytes [d] none
Ans: b
---------------------------------------SeerLogica Infotech Private Limited,
#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

94

SEERLOGICA INFOTECH
3) In a processor these are 120 instructions. Bits needed to implement
this instructions
[a] 6 [b] 7 [c] 10 [d] none
Ans: b
----------------------------------------4) In 8085 microprocessor READY signal does. which of the following
is incorrect statements
[a]It is input to the microprocessor [b] It sequences the instructions
Ans : b
---------------------------------------5) Return address will be returned by function to
[a] Pushes to the stack by call
Ans : a
-----------------------------------------6) n=7623
{
temp=n/10;
result=temp*10+ result;
n=n/10
}
Ans : 3267
---------------------------------------------7) If AB then
F=F(G);
else BC then
F=G(G);
in this , for 75% times AB and 25% times BC then,is 10000 instructions
are there ,then the ratio of F to G
[a] 7500:2500 [b] 7500:625 [c] 7500:625 if a=b=c else 7500:2500
-------------------------------------------------8) In a compiler there is 36 bit for a word and to store a character 8bits are
needed. IN this to store a character two words are appended .Then for storin
a K characters string, How many words are needed.
[a] 2k/9 [b] (2k+8)/9 [c] (k+8)/9 [d] 2*(k+8)/9 [e] none
Ans: a
--------------------------------------------------------9) int zap(int n)
{
if(n<=1)then zap=1;
else zap=zap(n-3)+zap(n-1);
}
then the call zap(6) gives the values of zap
[a] 8 [b] 9 [c] 6 [d] 12 [e] 15
Ans: b
--------------------------------------------------------PART-B
1) Virtual memory size depends on
[a] address lines [b] data bus [c] disc space [d] a & c [e] none
Ans : a
2) Critical section is
[a]--- [b] statements which are accessing shared resourses

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

95

SEERLOGICA INFOTECH
Ans : b
------------------------------------------------3) load a
mul a
store t1
load b
mul b
store t2
mul t2
add t1
then the content in accumulator is
Ans : a**2+b**4
1. Binary equivalent of 52
---- 110100
2. Hexadecimal equivalent of 3452 -----72A
3. Consider the Boolean table
4. Consider the circuit
Ans a) (A+B).(C+B)
5. JUST in time Concept address ---Ans : Elimination of waste by purchasing manufacturing exactly when needed
6. A better way of unit testing s/w program is
Ans : User test
7.A lowest level of security by most RDBMS are
Ans : a) field low
8. OOT uses
Ans : Encapsulated of detect methods
9.EDI useful in
Ans : Electronic Transmission
10. MRPII different from MRP
Ans : Modular version of man redundant initials
11. Hard disk time for R/W head to move to correct
And : a) Lactency
12. Percentage of times a page number bound in associate register
Ans : Bit ratio
13. MODEM --------Modulation and Demodulation
14. RDBMS file system
Ans : Interrelated
15. Super Key is ----- Primary key+ Attribute
16. Transmission is said to be ----committed
17. Windows 95 supports
a) Multiuser b) n tasks c) Both
- Ans : c
18. Difference between printf and fprintf ---19.To change permission r&w to owner group to no permission to others
a) Chmod 614 b) chmod 604 c) chmod 640 d) chmod 310
20. In batch process ------------better job

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

96

SEERLOGICA INFOTECH
1. Will the following be used as an identifier?
a. sum_of_credits
b. initial tree c. final_#
d. while
e. SECTION_6
f. bingo-square
g. 2_4_87
2. Are the identifiers name and NAME are same?
3. Is it right to type # of #define other than in first column?
4. Does C require expressions to be enclosed in parenthesis for while loop?
5. Will the preprocessor terminates with semicolon?
6. What is the return value of scanf statement?
7. What will happen, if there are two statements (without grouping) in if
Condition and an else is there for that if.
8. What will be the output of this program?
int no_fish;
no_fish=1;
if (no_fish==1)
printf("The water was to warm\n");
else ;
printf("The wates were all fished out\n");
9. Is parenthesis required for conditional expression in if condition?

19. What does chmod 654 stand for.


Ans : _rw_r_xr__
20. Which of following is used for back-up files?
(a) compress (b) Tar (c) make (d) all the above Ans : b
21 what does find command do ?
Ans : search a file
22. what does " calloc" do? Ans : A memory allocation and initialising to zero.
23 what does exit() do? Ans : come out of executing programme.
24. what is the value of 'i'?
i=strlen("Blue")+strlen("People")/strlen("Red")-strlen("green")
Ans : 1
25. i=2; printf("%old %old %old %old ",i, i++,i--,i++);
26. Using pointer, changing A to B and B to A is Swapping the function using two
address and one temperory variable. a,b are address, t is temporary
variable. How function look like?
Ans : swap(int *, int *, int )
27. In 'o' how are the arguments passed?
ans : by value.
28. Find the prototype of sine function.
Ans : extern double sin(double)
29. Scope of a global variable which is declared as static?
ans : File
30. ASCII problem :- I = ..
ans : 6
32. what is the o/p :- printf(" Hello \o is the world ");
33. Clarifying the concept addresses used over array ; ie changing the address of a base element
produces what error?
34. child process -- fork
child shell -- sh
35. Answer are lex 7 yacc & man read these things in UNIX
36. What is
int *p(char (*s)[])
Ans : p is a function which is returning a pointer to integer which
takes arguments as pointer to array of characters.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

97

SEERLOGICA INFOTECH
After pre-placement talk :;:
1.Could you tell me the growth plans and goals for the company?
2.What skills are important to be successful in this position?
4.What's the criteria your company uses for performance appraisal?
5.With whom will I be interacting most frequently and what are their
responsibilities and the nature of our interaction?
6.What is the time frame for making a decision at this position?
7.What made the previous persons in this position successful/unsuccessful?

Interview qts
Tell us about yourself.
What do you know about our company?
Why do you want to join our company?
What are your strengths and weaknesses?
Where do you see yourself in the next five years?
How have you improved the nature of your job in the past years of your working?
Why should we hire you?
What contributions to profits have you made in your present or former company?
Why are you looking for a change?

Answers to some difficult questions :


Tell me about yourself ?
Start from your education and give a brief coverage of previous experiences.
Emphasize more on your recent experience explaining your job profile.
What do you think of your boss?
Put across a positive image, but don't exaggerate.
Why should we hire you? Or why are you interested in this job?
Sum up your work experiences with your abilities and emphasize your strongest
qualities and achievements. Let your interviewer know that you will prove to be an
asset to the company.
How much money do you want?
Indicate your present salary and emphasize that the opportunity is the most
important consideration.
Do you prefer to work in a group?
Be honest and give examples how you've worked by yourself and also with others.
Prove your flexibility.

SeerLogica Infotech Private Limited,


#3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam,
Ameer Pet, Hyderabad-38. Http://www.seerlogica.com

98

Potrebbero piacerti anche