Professional Documents
Culture Documents
Data Structure Aptitude
Data Structure Aptitude
(d) Deletion.
Using insertion we can perform insertion sort,
using selection we can perform selection sort, using
exchange we can perform the bubble sort (and other
similar sorting methods). But no sorting method can be
done just using deletion.
Null Branches
i ii
iii iv v
In general:
If there are n nodes, there exist 2n-n different
trees.
B C
D E F G
H I J
Inorder : D H B E A F C I G J
Preorder: A B D H E C F G I J
Postorder: H D E B F I J G C A
5
At location 6
* RDBMS CONCEPTS *
1. What is database?
A database is a logically coherent collection of
data with some inherent meaning, representing some
aspect of real world and which is designed, built and
populated with data for a specific purpose.
2. What is DBMS?
It is a collection of programs that enables user to
create and maintain a database. In other words it is
general-purpose software that provides the users with
the processes of defining, constructing and
manipulating the database for various applications.
4. Advantages of DBMS?
Redundancy is controlled.
Unauthorised access is restricted.
Providing multiple user interfaces.
Enforcing integrity constraints.
Providing backup and recovery.
1. What is database?
A database is a logically coherent collection of
data with some inherent meaning, representing some
aspect of real world and which is designed, built and
populated with data for a specific purpose.
2. What is DBMS?
It is a collection of programs that enables user to
create and maintain a database. In other words it is
general-purpose software that provides the users with
the processes of defining, constructing and
manipulating the database for various applications.
4. Advantages of DBMS?
Redundancy is controlled.
Unauthorised access is restricted.
Providing multiple user interfaces.
Enforcing integrity constraints.
Providing backup and recovery.
71. Name the buffer in which all the commands that are
typed in are stored
‘Edit’ Buffer
84. What are database files, control files and log files.
How many of these files should a database have at
least? Why?
Database Files
The database files hold the actual data and
are typically the largest in size. Depending on their
sizes, the tables (and other objects) for all the user
accounts can go in one database file—but that's not an
ideal situation because it does not make the database
structure very flexible for controlling access to storage
for different users, putting the database on different disk
drives, or backing up and restoring just part of the
database.
You must have at least one database file but
usually, more than one files are used. In terms of
accessing and using the data in the tables and other
objects, the number (or location) of the files is
immaterial.
The database files are fixed in size and never
grow bigger than the size at which they were created
Control Files
The control files and redo logs support the
rest of the architecture. Any database must have at least
one control file, although you typically have more than
one to guard against loss. The control file records the
name of the database, the date and time it was created,
the location of the database and redo logs, and the
synchronization information to ensure that all three sets
of files are always in step. Every time you add a new
database or redo log file to the database, the
information is recorded in the control files.
Redo Logs
Any database must have at least two redo
logs. These are the journals for the database; the redo
logs record all changes to the user objects or system
objects. If any type of failure occurs, the changes
recorded in the redo logs can be used to bring the
database to a consistent state without losing any
committed transactions. In the case of non-data loss
failure, Oracle can apply the information in the redo
logs automatically without intervention from the DBA.
The redo log files are fixed in size and never
grow dynamically from the size at which they were
created.
The above is
a) Not an error
b) Error - the string in single quotes 'NORTH'
and 'SOUTH'
c) Error - the string should be in double quotes
d) Error - ORDER BY clause
more.......
1.#include <stdio.h>
void main()
{
int x = 5;
printf("%d,%d,%d",x,(x<<2),(x>>2));
}
Ans: 5,20,1
2.#include <stdio.h>
void main()
{
char a[]="hello";
char b[]="hai";
a=b;
printf("%s,%s",a,b);
}
ANs : since a is the base address of the array it is
a lValue(constant)
which can not be assigned with a value a=b is a
error.
3.#include <stdio.h>
void main()
{
char * p = "hello",ch;
ch = *++p;
printf("%c,%s",ch,p);
Ans e,ello
4.#include <stdio.h>
#include <string.h>
#define TOTAL 3
#define MAXNAMELEN 80
struct company
{
char organization[TOTAL][MAXNAMELEN];
};
int main()
{
void nameswap(struct company)
struct company x;
int i;
strcpy(x.organisation[0],"AATT India");
strcpy(x.organisation[1],"AATT Corporation");
strcpy(x.organisation[2],"AATT Limited");
nameswap(x);
for(i=0;i<TOTAL;i++)
printf("\n %s",x.organisation[i]);
return(1);
}
void nameswap(struct company x)
{
char tempname[MAXNAMELEN];
strcpy(tempname,x.organisation[0]);
strcpy(x.organisation[0],x.organisation[1]);
strcpy(x.organisation[1],tempname);
return;
}
5 #inlcude <stdio.h>
#define Stringizer(x) printf(#x)
void main()
{
Stringizer(hello);
}
6. #include <stdio.h>
#define Charizing(x) printf("%d",#@x)
void main()
{
Charizing(a);
}
Ans : 97
7.#include<stdio.h>
#include<string.h>
int main( )
{
char *ptr1,*ptr2;
ptr1 = "Hello AATT";
ptr2 = "Hai";
ptr1= strcat(ptr1,ptr2);
printf("\n Input string %s",ptr1);
return 1;
}
Ans : Enough memory not allocated for
concatenation
8.int main( )
{
int x=20,y=35;
x=y++ + x++;
y=++y + ++x;
printf("%d %d",x,y);
return 1;
}
Ans : 57,94
9.int main( )
{
int i,*p;
i=10;
p=&i;
printf("%d",10/*p);
return 1;
}
Ans:Since there is no space between / and * it is
taken to be a comment and the output will not be
10/10 =1 as expected
int main()
{
int a=0;
if(a= 0)
printf("hello");
printf("AATT");
return 0;
}
Ans :AATT
11.Write a function to swap two numbers without
using temp .
Ans :
Swap(a,b)
{
a= a+b;
b= a-b;
a= a-b;
}
12.O/p of Following
int main()
{
char a[2];
*a[0]=7;
*a[1]=5;
printf("%d",&a[1]-a);
}
Ans :5
int main()
{
Prime(56);
}
void Prime (int a)
{
int j;
for(j=1; j<=a; j++)
{
if(a% j == 0)
{
a/=j;
printf("%d,",j);
j= 1;
}
}
return ;
}
p =(char *) malloc(len+1);
while(i<= len)
{
}
p[len] = '\0';
return p;
}
17. Output of
int main()
{
printf("%d%x\n",0x2,12);
ans :2C
19.int main()
{
int a[5],*p;
for(p=a;p<&a[5];p++)
{
*p=p-a;
printf("%d\n",*p);
}
Ans : 0,1,2,3,4
}
void swap (char *x,char *y)
{
char *t;
t=x;
x=y;
y=t;
printf("(%s, %s)-",x,y);
}
a).(New,Dictionary)-(New,Dictionary)
b).(Dictionary,New)-(New,Dictionary)
c).(New,Dictionary)-(Dictionary,New)
d).(Dictionary,New)-(Dictionary,New)
e).None of the above
Ans :c
23.
main()
{
main();
printf("InMain \t");
}
24.
main()
{
printf("InMain \t");
main();
}
Ans ???
26.int x ;
int intg()
{
return x+=4;
}
int diff()
{
return x/=4;
}
main()
{
x = intg()+diff();
printf("%d",x);
}
Ans 5
27.
int x;
main()
{
int j =2;
printf("%d",fun(j));
}
fun(int x)
{
x++,++x;
return x++;
}
Ans 4
28.
main()
{
static char *s[] = {"ice","green","cone","please"};
static char **ptr[] = {s+3,s+2,s+1,s};
char ***p = ptr;
printf("%s",**++p);
printf("\n%s",*--*++p +3);
printf("\n%s",*p[-2] +3);
printf("\n%s" , p[-1][-1] +1);
}
Ans :
cone
ase
reen
29.
main()
{
float **a;
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%f",&a[i][j]);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
printf("%f",a[i][j]);
}
Ans :
Memory not allocated for a
30.
main()
{
printf("%d",sizeof("1234"));
printf("%d",sizeof(1));
printf("%d",sizeof(1.1));
}
Ans 548
31.
main()
{
int *x;
int y[3] = {10,20,30};
x=y;
printf("%d",++*x);
printf("\n%d",++*x++);
}
Ans 11,12
32.
int main()
{
char s[] = "Get organised";
printf("%s",&s[2]);
printf("\n %s",s);
printf("\n %s",&s);
printf("\n %c",s[2]);
}
Ans:
t organised
Get organised
Get organised
t
33.
34 .
main()
{
int const *f;
int x = 10;
f = & x;
*f = 15
printf("%d",x);
Ans :
f cannot change the value of the pointed memory.
35.
main()
{
int const *f;
int x = 10,y =15;
f = & x;
printf("%d",*f);
f = & y;
printf("%d",*f);
Ans :
f cannot be assigned different addresses because
it is a constant pointer.
36.
main()
{
int a[6]={0,1,2,3,4,5};
int (*p)[3];
p=a;
*p[1] = 5;
printf("%d",a[1]);
}
37.
main()
{
char i ;
for(i=0;i<256;i++)
printf("%d",i);
}
38.
main()
{
char s[]="Hello World";
s++;
printf("%s",s);
}
39.main()
{
char *s="Hello World";
s++;
printf("%s",s);
}
40.
main()
{
char *s;
s = "Hello World";
printf("%s",s);
}
42.
main()
{
char s[] = "Hello";
printf("%s" , s[3]);
}
43.
main()
{
extern int a;
printf("%d",a);
}
44.
main()
{
inti=-3,j=2,k=0,m;
m=++i&&++j||++k;
printf("\n %d %d %d %d",i,j,k,m);
}
Ans : 2 3 0 1
45.
main()
{
int a,b;
a=sumdig(123);
b=sumdig(123);
printf("%d %d",a,b);
}
sumdig(int n)
{
static int s=0;
int d;
if(n!=0)
{
d=n%10;
n=(n-d)/10;
s=s+d;
sumdig(n);
}
else return(s);
}
Ans :6,12
46.
Ans :27,6
47.
main()
{
char *p,*f();
p=f();
printf("f() returns:%s\n",p);
}
char *f()
{
char result[80];
strcpy(result,"anything will do");
return (result);
}
Ans : f() returns :
48.
main()
{
short int *p,*q;
p=(short int *)1000;
q=(short int *)2000;
printf("%d",(q-p));
}
49
main()
{
char a =0xAA ;
int b ;
b = (int) a ;
b = b >> 4 ;
printf("%x",b);
Ans : ffffffaa
50.
.main()
{
char *p = "hello world!";
p[0] = 'H';
printf("%s",p);
}
Ans : Run time error .
51.
main()
{
char *p ;
char s[20] = "Hello world!";
strcpy(p,s);
printf("%s",p);
}
52.
main()
{
char *p ;
char s[20] = "Hello world!";
p = (char *)malloc(20);
strcpy(p,s);
printf("%s",p);
}
53.
main()
{
int a=10,b;
a>= 5 ? b=100 : b=200;
printf("\n%d",b);
}
54.
main()
{
int a=10,b;
a>5 ? a++ : a++;
printf("\n%d",a);
}
Ans : 11
55.
Given a piece of code
int x[10];
int *ab;
ab=x;
To access the 6th element of the array which of
the following is incorrect?
(A) *(x+5) (B) x[5] (C) ab[5] (D) *(*ab+5} .
Ans : d
56.
Consider the following program
main()
{
int a[5]={1,3,6,7,0};
int *b;
b=&a[2];
}
The value of b[-1] is
(A) 1 (B) 3 (C) -6 (D) none
Ans : b
57.
What does the following program print?
#include <stio.h>
int sum,count;
void main(void)
{
for(count=5;sum+=--count;)
printf("%d",sum);
}
a. The pgm goes to an infinite loop b. Prints
4791010974 c. Prints 4791001974
d. Prints 5802112085 e. Not sure
Ans: a
58.
#include <stdio.h>
void main(void)
{
int i;
for(i=2;i<=7;i++)
printf("%5d",fno());
}
fno()
{
staticintf1=1,f2=1,f3;
return(f3=f1+f2,f1=f2,f2=f3);
}
a. produce syntax errors b. 2 3 5 8 13 21 will be
displayed c. 2 2 2 2 2 2 will be displayed
d. none of the above e. Not sure
Ans : b
59.
#include <stdio.h>
void main (void)
{
int x;
x = 0;
if (x=0)
printf ("Value of x is 0");
else
printf ("Value of x is not 0");
}
a. print value of x is 0 b. print value of x is not 0 c.
does not print anything on the screen
d. there is a syntax error in the if statement e. Not
sure
Ans : a
60.
void main (void)
{
char arr[100] = {"Welcome to Mistral"};
foo (arr);
}
foo (char *x)
{
printf ("%d\t",strlen (x));
printf ("%d\t",sizeof(x));
return0;
}
a. 100 100 b. 18 100 c. 18 18 d. 18 2 e. Not sure
Ans : 18,100
61.
#include <stdio.h>
display()
{
printf ("\n Hello World");
return 0;
}
void main (void)
{
int (* func_ptr) ();
func_ptr = display;
printf ("\n %u",func_ptr);
(* func_ptr) ();
}
Ans : it prints the address of the function display
and prints Hello World on the screen
62.
#include <stdio.h>
void main (void)
{
int i = 0;
char ch = 'A';
do
putchar (ch);
while(i++ < 5 || ++ch <= 'F');
}
Ans : AAAAAABCDEF
* C++ PROGRAMS *
Note: All the programs are tested under Turbo C++ 3.0, 4.5 and
Microsoft VC++ 6.0 compilers.
It is assumed that,
Programs run under Windows environment,
The underlying machine is an x86 based system,
Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on
this assumptions (for example sizeof(int) == 2 may be assumed).
1) class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout << "The value is " << *ptr;
}
};
void SomeFunc(Sample x)
{
cout << "Say i am in someFunc " << endl;
}
int main()
{
Sample s1= 10;
SomeFunc(s1);
s1.PrintVal();
}
Answer:
Say i am in someFunc
Null pointer assignment(Run-time error)
Explanation:
As the object is passed by value to SomeFunc the destructor
of the object is called when the control returns from the function.
So when PrintVal is called it meets up with ptr that has been
freed.The solution is to pass the Sample object by reference to
SomeFunc:
3) class base
{
public:
int bval;
base(){ bval=0;}
};
int main()
{
base BaseArr[5];
SomeFunc(BaseArr,5);
deri DeriArr[5];
SomeFunc(DeriArr,5);
}
Answer:
00000
01010
Explanation:
The function SomeFunc expects two arguments. The first one
is a pointer to an array of base class objects and the second one is
the sizeof the array. The first call of someFunc calls it with an
array of base objects, so it works correctly and prints the bval of all
the objects. When Somefunc is called the second time the
argument passed is the pointer to an array of derived class objects
and not the array of base class objects. But that is what the function
expects to be sent. So the derived class pointer is promoted to base
class pointer and the address is sent to the function. SomeFunc()
knows nothing about this and just treats the pointer as an array of
base class objects. So when arr++ is met, the size of base class
object is taken into consideration and is incremented by sizeof(int)
bytes for bval (the deri class objects have bval and dval as
members and so is of size >= sizeof(int)+sizeof(int) ).
4) class base
{
public:
void baseFun(){ cout<<"from base"<<endl;}
};
class deri:public base
{
public:
void baseFun(){ cout<< "from derived"<<endl;}
};
void SomeFunc(base *baseObj)
{
baseObj->baseFun();
}
int main()
{
base baseObject;
SomeFunc(&baseObject);
deri deriObject;
SomeFunc(&deriObject);
}
Answer:
from base
from base
Explanation:
As we have seen in the previous case, SomeFunc expects a
pointer to a base class. Since a pointer to a derived class object is
passed, it treats the argument only as a base class pointer and the
corresponding base function is called.
5) class base
{
public:
virtual void baseFun(){ cout<<"from base"<<endl;}
};
class deri:public base
{
public:
void baseFun(){ cout<< "from derived"<<endl;}
};
void SomeFunc(base *baseObj)
{
baseObj->baseFun();
}
int main()
{
base baseObject;
SomeFunc(&baseObject);
deri deriObject;
SomeFunc(&deriObject);
}
Answer:
from base
from derived
Explanation:
Remember that baseFunc is a virtual function. That means
that it supports run-time polymorphism. So the function
corresponding to the derived class object is called.
6) void main()
{
int a, *pa, &ra;
pa = &a;
ra = a;
cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;
}
/*
Answer:
Compiler Error: 'ra',reference must be initialized
Explanation:
Pointers are different from references. One of the main
differences is that the pointers can be both initialized and assigned,
whereas references can only be initialized. So this code issues an
error.
*/
Explanation:
Arrays cannot be passed to functions, only pointers (for
arrays, base addresses)
can be passed. So the arguments int *ptr and int prt[size] have no
difference
as function arguments. In other words, both the functions have the
same signature and
so cannot be overloaded.
*/
8.
class some{
public:
~some()
{
cout<<"some's destructor"<<endl;
}
};
void main()
{
some s;
s.~some();
}
/*
Answer:
some's destructor
some's destructor
Explanation:
Destructors can be called explicitly. Here 's.~some()'
explicitly calls the
destructor of 's'. When main() returns, destructor of s is called
again,
hence the result.
*/
9.
#include <iostream.h>
class fig2d
{
int dim1;
int dim2;
public:
fig2d() { dim1=5; dim2=6;}
void main()
{
fig2d obj1;
// fig3d obj2;
10.
class opOverload{
public:
bool operator==(opOverload temp);
};
void main(){
opOverload a1, a2;
a1= =a2;
}
Answer:
Runtime Error: Stack Overflow
Explanation:
Just like normal functions, operator functions can be called
recursively. This program just illustrates that point, by calling the
operator == function recursively, leading to an infinite loop.
11.
class complex{
double re;
double im;
public:
complex() : re(1),im(0.5) {}
bool operator==(complex &rhs);
operator int(){}
};
int main(){
complex c1;
cout<< c1;
}
Explanation:
The programmer wishes to print the complex object using
output
re-direction operator,which he has not defined for his lass.But the
compiler instead of giving an error sees the conversion function
and converts the user defined object to standard object and prints
some garbage value.
12.
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double n) { re=n,im=n;};
complex(int m,int n) { re=m,im=n;}
void print() { cout<<re; cout<<im;}
};
void main(){
complex c3;
double i=5;
c3 = i;
c3.print();
}
Answer:
5,5
Explanation:
Though no operator= function taking complex, double is
defined, the double on the rhs is converted into a temporary object
using the single argument constructor taking double and assigned
to the lvalue.
13.
void main()
{
int a, *pa, &ra;
pa = &a;
ra = a;
cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;
}
Answer :
Compiler Error: 'ra',reference must be initialized
Explanation :
Pointers are different from references. One of the main
differences is that the pointers can be both initialized and assigned,
whereas references can only be initialized. So this code issues an
error.