You are on page 1of 4

# CODE BREAKERS

MATHRIX 11
DEPARTMENT OF MATHEMATICS, CEG
1) Given a binary search tree, write a function which takes any given node from
the binary tree and a number. Function has to return the next higher number of
the given number from the binary search tree.
2) Efficient way to check palindrome in a link list
3) Algorithm to find the two numbers whose difference is minimum among the
set of numbers. For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19 the
algorithm should return min diff = 20-19 = 1. Constraint - Time Complexity O(N)
& Space is not a constraint [upto O(3N)]
4) Given an image, how will you turn it by 90 degrees? An image can be treated
as 2D matrix which can be stored in a buffer. We are provided with matrix
dimensions and its base address. How can we turn it? For example see the
below picture,
***^***
***|***
***|***
***|***
After rotating right, it appears (observe arrow direction)
****
****
****
-- - - >
****
****
****
5) Compute n modulo d without division(/) and modulo(%) operators, where d is
a power of 2 number.
6) Given a root of a tree, and an integer k. Print all the nodes which are at k
distance from root. For example, in the below tree, 4, 5 & 8 are at distance 2
from root.
1
/ \
2

/ \
4

5 8

CODE BREAKERS
MATHRIX 11
DEPARTMENT OF MATHEMATICS, CEG
7) Given a string or array of characters, which contains repeating characters ,
write a method to return the first unique character

## 8) Ram knows what will be the output of the following problem.

He has the following question to you !!!!
"{" "}" will it create new "Activation Record" (or Stack Frame) ?
int main()
{
int i=50;
{
int i=10;
printf("%d",i);
}
}
PREDICT THE OUTPUT
9)
main()
{
int i=300;
char *ptr;
ptr=&i;
*++ptr=2;
printf("%d",i);
}
10)
#include <iostream>
using namespace std;
int main()
{
int test = 0;
cout << "First character " << '1' << endl;
cout << "Second character " << (test ? 3 : '1') << endl;
return 0;
}

CODE BREAKERS
MATHRIX 11
DEPARTMENT OF MATHEMATICS, CEG
11)
struct aaa{
struct aaa *prev;
int i;
struct aaa *next;
};
main()
{
struct aaa abc,def,ghi,jkl;
int x=100;
abc.i=0;abc.prev=&jkl;
abc.next=&def;
def.i=1;def.prev=&abc;def.next=&ghi;
ghi.i=2;ghi.prev=&def;
ghi.next=&jkl;
jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
x=abc.next->next->prev->next->i;
printf("%d",x);
}
12) Hexspeak is a novelty speak of programmers who wanted a magic number, a
clear and unique identifier with which to mark memory or data using
13) Given a number x, find next number with same number of 1 bits in its binary
representation.
For example, consider x = 12, whose binary representation is 1100 (excluding
leading zeros on 32 bit machine). It contains two logic 1 bits. The next higher
number with two logic 1 bits is 17 (100012).
14)
#define PrintInt(x,y) printf("%d %d\n",*x,y)
main()
{
int y = 100, *p=(int*)calloc(1,sizeof(int));
*p = 10;
y = y/*p;
*p=*p+y;

## /* Adding y and *p */;

CODE BREAKERS
MATHRIX 11
DEPARTMENT OF MATHEMATICS, CEG
PrintInt(p,y);
}
15) Find the bugs else print the output
main()
{
const int x=5;
int *ptr;
ptr=&x;
*ptr=10;
printf("Const value changed to %d",x);
}