Delivered by FeedBurner

New Answers in your Inbox

CS-62 JUNE 2003 QNO 2(c)

Question 2.(c) List atleast 4 differences between Arrays and Pointers in 'C' Language.
Answer: (i) Array elemets are always stored in contiguous memory location irrespective of array size.
(ii) There is necessary to assign the size in array, ut not in Pointers.
(iii)Pointers are randomly location.
(iv) The size of the data type which pointer variable refers to is dependent on the data type pointed to by the pointer.
(v) A pointer whenever increameted, points to a location after skipping number of bytes required by the data type.

CS-62 JUNE 2003 QNO 2(b)

Q.2. (b) Consider the tree in the following figure:


Give the Postfix, Prefix and Infix expressions corresponding to the above tree.

Answer:
Infix expression = (a * b) x (c + d ) - e
Prefix expression= *ab* + cd - e = *ab* -+ cde
Postfix expression= (ab *) * (cd + ) -e =ab*cd + * .e -

CS-62 JUNE 2003 QNO 2(a)

QuestionDraw the internal memory representation of the following Binary Tree using Sequential Representation. Assume that nodes appear in the following physical sequence:


A, B, C, D, E, G, F, H


Answer

Index01234567891011
ValueABCDEGFH

CS-62 JUNE 2003 QNO 1(c)

Question: Write a function that takes only a pointer to the root of a binary tree T and computes the number of nodes in T.

Answer: When we traverse a binary tree then all the nodes of tree should traversed. Now if we put a pointer as a counter than it will print the total no of nodes. Any of the traversal schemes can be used to determine the number of elements in abinery tree. But we can use this mechanism also to count the total no. of neds of left subtree and right subtree.
The function is as follows:
int TotalNodes(bnodes*tree)
{
if(tree==(bnode*true)NULL)
return 0;
else
return (TotalNodes(tree->left)+TotalNodes(tree->right)+1);
}