Monday, September 12, 2005

Introduction to data structure

TWO MARK QUESTIONS:

1) What does data structure deal with?
Data structure deals with the study of
• Information organized in a computer,
• How it can be manipulated and
• How it can be utilized.

2) Define Bit.
The basic unit of information is Bit (Binary digit), whose values state one of two mutually exclusive possibilities.

3) What are the ways to express negative binary integers? How could they be obtained?
The two methods are
i) Ones complement method
ii) Twos complement method
Ones complement is obtained by changing each bit to opposite bit setting
Twos complement is obtained by adding 1 to the LSB of ones complement.

4) Represent –38 in ones complement and twos complement method.
Binary representation of 38 is 00100110
Ones complement is 11011001
Twos complement is 11011001+1=11011010

5) What is the general format of floating point number? Represent 3x10-3 in binary form. What are the advantages of floating point numbers?
The general format of floating point number is mantissa x base exponent
The floating point of 3x10-3 is 00000000000000000000001111111101
The advantage is even very small and very large numbers can be specified in 32 bits.

6) Define byte size and byte.
The number of bits necessary to represent a character in a particular computer is called byte size.
A group of bits used to represent character together form byte.

7) Define data type.
A method of interpreting bit pattern is data type.

8) Define bit, bit content, byte and word
The basic unit of information is bit, whose value asserts one of two mutually exclusive possibilities.
• The setting of a bit is called bit content
• Group of bits form larger units called byte.
• Several bytes group together to form words.

9) What are the uses of declaration?
i) For the programmer to specify how the contents of computer memory are to be interpreted by the program
ii) It specifies how much memory is required for the particular entity.

10) What is hardware implementation for data type specification?
If the data type implementation needs circuitry to perform necessary operations, and it is constructed as part of computer.

11) What is software implementation for data type specification?
A program consisting of already existing instructions is written to interpret bit strings in desired manner, to perform required operation.

12) Write the procedure to copy one string to another.
i=0;
while (source[i]!=’\0’)
{
MOVE ( Source[i],dest[i],1);
i++;
}
desat[i]=’\0’;

13) Write the procedure to concatenate two strings c1, c2 to c3.
i=0;
While (c1[i]!=’\0’)
{
MOVE (c1[i],c3[i],1);
i++;
}
j=0;
While (c2[j]!=’\0’)
{
MOVE (c2[j++],c3[i++],1);
}
c3[i]=’\0’;


14) What is abstract data type?
ADT is the tool for specifying logical properties of a data type. Abstract data types are data types created from existing data type and they adapt their operations too.

15) What are the two part of ADT? Explain.
i) Value definition – This defines collection of values for the ADT. It has two parts: The definition clause and the condition clause.
ii) Operator definition- Each operation is defined as a abstract function. The three parts of ADT function are: Header, Precondition and Post condition.

16) What is a header, precondition and postcondition in a ADT function.
i) Header – indicate this is a ADT operator definition. Declares variables.
ii) Precondition – Specify any restrictions that must be satisfied before the operation can be applied.
iii) Post condition – Specifies what the operation does.

17) Define sequence and subsequence.
Sequence is an ordered set of elements. A subsequence is a contiguous portion of a sequence.

18) Write short note on data types in C.
Basic data types in C are (i) int (ii) float (iii) char (iv) double.
Integer has three qualifiers- short, long and unsigned. short and long indicate the maximum size of variable’s vale. Unsigned integer is always possible.

19) Define pointer. How could it be declared?
Pointer is a variable that holds address of a data object or a function. Pointers allow the programmer to refer to the location of objects as well as the contents of the location.
The declaration is as, data type * pointer_name;
(eg) int *pi;

20) Explain pass by value and give example.
The values being passed from the function call are copied into the parameters of the called function at the time the function s invoked. The change in value of the parameter in called function will not affect the same variable in called function.
(eg) x=1;
printf(“%d\n”,x);
funct(x);
printf(“%d\n”,x);


funct(y)
int y;
{
++y;
printf(“%d\n”,y);
}

21) Explain pass by reference and give example.

If the calling function passes the address of the memory location, and the called function parameter values are changed, it also affects the calling function value. This is called pass by reference.
(eg) x=1;
printf(“%d\n”,x);
funct(&x);
printf(“%d\n”,x);


funct(py)
int *py;
{
++(*py);
printf(“%d\n”,*py);
}

22) What are the goals of data structure
i) To identify and develop mathematical entities and operations, that determine the way to solve problems.
ii)To determine representation for those abstract entities to implement abstract operations, with existing data types.


OTHER QUESTIONS
1) Explain ADT. (8)
2) Write the ADT for Rational numbers. (6 marks)
3) Write the ADT for varying length strings. (6 marks)
4) Explain Pointers. Give example of pass by value and pass by reference and explain. (16 marks).

Works for you….
1) Write an ADT specification for complex numbers a+bi where
Abs(a+bi) is sqrt(a*a+b*b)
(a+bi)+(c+di) is (a+c)+(b+d)i
(a+bi)*(c+di) is (a*c-b*d)+(a*d+b*c)i
-(a+bi) is (-a)+(-b)i

2) Prove that there are 2 power n different settings for n two-way switches. Suppose that we wanted to have m settings. How many switches would be necessary?