Chetan Sakhardande wrote:

> )
> What is an AVL tree?

A binary tree where the two subtrees of any given mode differ in
height by at most one. If inserting an element into the tree would
violate this constraint, then the tree is re-balanced in order to
maintain the constraint.

The purpose of this is to ensure that searching such a tree is
O(log(n)).

> II)
> WHat is a reentrant function?

A function which can be called while it is still executing. This may
occur either through recursion, or through mechanisms such as
interrupt or signal handlers.

The simplest way to satisfy this requirement is to ensure that the
function doesn't modify any static variables (i.e. global variables,
or local variables which are declared `static'), and doesn't call any
non-reentrant functions.

> III)
> I have seen in many programmes the following code :
> 
> foo(int *iptr)
> {
>       int     j;
> 
>       j = ptr;
> }
> 
> ok, forget the cast for now, this is slightly tricky if sizeof(int) !=
> sizeof(*) on some architectures.
> 
> fine. but why doesn't the guy just say int *iptr2 = iptr1 in the above
> code.

Are you asking about

        j = iptr;
or
        j = *iptr;

Either is valid (although `j' may need to be a `long' instead of an
`int'), but they each do different things.

> Is it a performance eenhancement to equate it to int rahter then a pointr
> in th e fucnntion ?

Assigning to a variable may well be quicker than repeatedly
dereferencing a pointer, particularly if the program calls any
functions. A compiler cannot assume that the following are equivalent

        func1(j);
        somefunc();
        func2(j);
and
        func1(*iptr);
        somefunc();
        func2(*iptr);

if `iptr' is a parameter, as `somefunc()' may modify the data to which
`iptr' points. If you know that `*iptr' remains constant, then
assigning it to a variable will generally be more efficient.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to