1.data Structures Aptitude
1.data Structures Aptitude
1.data Structures Aptitude
3. What are the notations used in Evaluation of Arithmetic Expressions using prefix
and postfix forms?
Polish and Reverse Polish notations.
(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.
8. Traverse the given tree using Inorder, Preorder and Postorder traversals
Given tree:
A
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
9. Of the following tree structure, which is, efficient considering space and time
complexities?
(a) Incomplete Binary Tree
(b) Complete Binary Tree
(c) Full Binary Tree
A * B - (C + D) * (P / Q)
-
* *
A B + /
C D P Q
11.What are the major data structures used in the following areas : RDBMS, Network
data model & Hierarchical data model.
RDBMS – Array (i.e. Array of structures)
Network data model – Graph
Hierarchical data model – Trees
i ii iii iv v
In general:
If there are n nodes, there exist 2n-n different trees.
2.C Aptitude
1.main()
{
char *p;
int *q;
long *r;
p=q=r=0;
p++;
q++;
r++;
printf("%p...%p...%p",p,q,r);
}
Answer:
0001...0002...0004
Explanation:
++ operator when applied to pointers increments address according to their
corresponding data-types
2. main()
{
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
}
Answer:
1==1 is TRUE
Explanation:
When two strings are placed together (or separated by white-space) they
are concatenated (this is called as "stringization" operation). So the string
is as if it is given as "%d==1 is %s". The conditional operator( ?: )
evaluates to "TRUE".
3. main()
{
int y;
scanf("%d",&y); // input given is 2000
if( (y%4==0 && y%100 != 0) || y%100 == 0 )
printf("%d is a leap year");
else
printf("%d is not a leap year");
}
Answer:
2000 is a leap year
Explanation:
An ordinary program to check if leap year or not.
4.int i=10;
main()
{
extern int i;
{
int i=20;
{
const volatile unsigned i=30;
printf("%d",i);
}
printf("%d",i);
}
printf("%d",i);
}
Answer:
30,20,10
Explanation:
'{' introduces new block and thus new scope. In the innermost block i is
declared as,
const volatile unsigned
which is a valid declaration. i is assumed of type int. So printf prints 30. In
the next block, i has value 20 and so printf prints 20. In the outermost
block, i is declared as extern, so no storage space is allocated for it. After
compilation is over the linker resolves it to global variable i (since it is the
only variable visible there). So it prints i's value as 10.
5. main()
{
int *j;
{
int i=10;
j=&i;
}
printf("%d",*j);
}
Answer:
10
Explanation:
The variable i is a block level variable and the visibility is inside that
block only. But the lifetime of i is lifetime of the function so it lives upto
the exit of main function. Since the i is still allocated space, *j prints the
value stored in i since j points i.
6. #include<stdio.h>
main()
{
register i=5;
char j[]= "hello";
printf("%s %d",j,i);
}
Answer:
hello 5
Explanation:
if you declare i as register compiler will treat it as ordinary integer and it
will take integer value. i value may be stored either in register or in
memory.
7. main()
{
int i=5,j=6,z;
printf("%d",i+++j);
}
Answer:
11
Explanation:
the expression i+++j is treated as (i++ + j)
8. struct point
{
int x;
int y;
};
struct point origin,*pp;
main()
{
pp=&origin;
printf("origin is(%d%d)\n",(*pp).x,(*pp).y);
printf("origin is (%d%d)\n",pp->x,pp->y);
}
Answer:
origin is(0,0)
origin is(0,0)
Explanation:
pp is a pointer to structure. we can access the elements of the structure
either with arrow mark or with indirection operator.
Note:
Since structure point is globally declared x & y are initialized as zeroes
9. main()
{
int i=_l_abc(10);
printf("%d\n",--i);
}
int _l_abc(int i)
{
return(i++);
}
Answer:
9
Explanation:
return(i++) it will first return i and then increments. i.e. 10 will be
returned.
10.main()
{
char c=' ',x,convert(z);
getc(c);
if((c>='a') && (c<='z'))
x=convert(c);
printf("%c",x);
}
convert(z)
{
return z-32;
}
Answer:
Compiler error
Explanation:
declaration of convert and format of getc() are wrong.
3.C++ Aptitude and OOPS
Answer:
sizeof . .* .-> :: ?:
Answer:
A node class is a class that,
relies on the base class for services and implementation,
provides a wider interface to te users than its base class,
relies primarily on virtual functions in its public interface
depends on all its direct and indirect base class
can be understood only in the context of the base class
can be used as base for further derivation
can be used to create objects.
A node class is a class that has added new services or functionality beyond the services
inherited from its base class.
3. What are the conditions that have to be met for a condition to be an invariant of the
class?
Answer:
The condition should hold at the end of every constructor.
The condition should hold at the end of every mutator(non-const) operation.
Here data[3] yields an Array1D object and the operator [] invocation on that
object yields the float in position(3,6) of the original two dimensional array. Clients of
the Array2D class need not be aware of the presence of the Array1D class. Objects of this
latter class stand for one-dimensional array objects that, conceptually, do not exist for
clients of Array2D. Such clients program as if they were using real, live, two-dimensional
arrays. Each Array1D object stands for a one-dimensional array that is absent from a
conceptual model used by the clients of Array2D. In the above example, Array1D is a
proxy class. Its instances stand for one-dimensional arrays that, conceptually, do not
exist.
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.
7.What is a modifier?
Answer:
A modifier, also called a modifying function is a member function that changes the
value of at least one data member. In other words, an operation that modifies the state of
an object. Modifiers are also known as ‘mutators’.
8. What is an accessor?
Answer:
An accessor is a class operation that does not modify the state of an object. The
accessor functions need to be declared as const operations
representing some aspect of real world and which is designed, built and populated
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.
11.What is an Entity?
It is a 'thing' in the real world with an independent existence.
5.Computer Networks
1. What are the two types of transmission technology available?
(i) Broadcast and (ii) point-to-point
2. What is subnet?
A generic term for section of a large networks usually separated by a bridge or
router.
5. What is RAID?
A method for providing fault tolerance by using multiple hard disk drives.
7. What is Brouter?
Hybrid devices that combine the features of both bridges and routers.
8. What is cladding?
A layer of a glass surrounding the center fiber of glass inside a fiber-optic cable.
3. What is thrashing?
It is a phenomenon in virtual memory schemes when the processor spends most of
its time swapping pages, rather than executing instructions. This is due to an inordinate
number of page faults.
4. What are short-, long- and medium-term scheduling?
Long term scheduler determines which programs are admitted to the system for
processing. It controls the degree of multiprogramming. Once admitted, a job becomes a
process.
Medium term scheduling is part of the swapping function. This relates to
processes that are in a blocked or suspended state. They are swapped out of real-memory
until they are ready to execute. The swapping-in decision is based on memory-
management criteria.
Short term scheduler, also know as a dispatcher executes most frequently, and
makes the finest-grained decision of which process should execute next. This scheduler is
invoked whenever an event occurs. It may lead to interruption of one process by
preemption.
9. What is time-stamping?
It is a technique proposed by Lamport, used to order events in a distributed
system without the use of clocks. This scheme is intended to order events consisting of
the transmission of messages. Each system 'i' in the network maintains a counter Ci.
Every time a system transmits a message, it increments its counter by 1 and attaches the
time-stamp Ti to the message. When a message is received, the receiving system 'j' sets
its counter Cj to 1 more than the maximum of its current value and the incoming time-
stamp Ti. At each site, the ordering of messages is determined by the following rules: For
messages x from site i and y from site j, x precedes y if one of the following conditions
holds....(a) if Ti<Tj or (b) if Ti=Tj and i<j.
10. In the context of memory management, what are placement and replacement
algorithms?
Placement algorithms determine where in available real-memory to load a
program. Common methods are first-fit, next-fit, best-fit. Replacement algorithms are
used when memory is full, and one process (or part of a process) needs to be swapped out
to accommodate a new program. The replacement algorithm determines which are the
partitions to be swapped out.
11. What are demand- and pre-paging?
With demand paging, a page is brought into memory only when a location on that
page is actually referenced during execution. With pre-paging, pages other than the one
demanded by a page fault are brought in. The selection of such pages is done based on
common access patterns, especially for secondary memory devices.
12. What are the key object oriented concepts used by Windows NT?
Encapsulation
Object class and instance