-
Propose a data structure for the following:
- The data structure would hold elements from 0 to N-1.
There is no order on the elements (no ascending/descending order
requirement)
The complexity of the operations should be as follows:
* Initialization - O(1)
* Insertion of an element - O(1)
* Deletion of an element - O(1)
* Finding a element - O(1)
* Deleting all elements - O(1)
-
Given 13 balls, how would you arrange them in 9 lines, such
that there are 4 balls in each line ?
you can assume that the lines are arranged in 2-D space. a ball
cannot be placed on top of another ball.
If you find that too easy, and have loads of time to kill, then
how about arranging 22 balls in 21 lines of 4 :)
-
Write a "C" function,
int AddOvf(int* result, int a, int b)
If there is no overflow, the function places the reusltant
sum a+b in "result" and returns 0. Otherwise it returns -1.
The solution of casting to long and adding to find detecting the
overflow is not allowed :-)
-
Write a C function that rotates to the right by 'n' bit
positions the bits of an unsigned int x
No assumptions to be made on the the values 'n' can take and the
size of 'x'.
-
Can you explain the behaviour of the following C program?
int main()
{
float f=0.0f;
int i;
for(i=0;i<10;i++)
f += 0.1f;
if(f==1.0f)
printf("f is 1.0f\n");
else
printf("f is NOT 1.0f\n");
return 0;
}
-
You need to write a simple macro CHAR(x) which takes a character x and
converts it into ASCII value of x.
printf("%c",CHAR(a)) ==> a
printf("%c",CHAR(X)) ==> X
No, this simple definition doesn't work:
#define CHAR(x) 'x'