Sunday, June 28, 2009

Some Data Structure Programs



/*1. WAP to implement searching in a linked list */

#include<iostream.h>
#include<conio.h>
#include<process.h>

class node
{
 int data;
 node *next;
 public:
 void insert();
 void search(int);
 void display();
};

node *start,*head,*temp;

void node::insert()
{
 head=new node;
 cout<<"\n Enter the data item: ";
 cin>>head->data;
 head->next=NULL;
 if(start==NULL)
 {
  start=head;
 }
 else
 {
  temp=start;
  while(temp->next!=NULL)
  {
   temp=temp->next;
  }
  temp->next=head;
 }
}

void node::display()
{
 temp=start;
 if(start==NULL)
 cout<<"\n Data list is empty ";
 else
 {
  cout<<"\n DATA LIST: ";
  while(temp!=NULL)
  {
   cout<<temp->data<<" ";
   temp=temp->next;
  }
 }
}

void node::search(int data)
{
 temp=start;
 if(start==NULL)
 cout<<"\n Data list is empty ";
 else
 {
  int flag=0;
  while(temp!=NULL)
  {
   if(data==temp->data)
   {
    cout<<"\n The data item is present in the list ";
    flag=1;
    break;
   }
   temp=temp->next;
  }
  if(flag!=1)
  cout<<"\n The data item is not found to be present ";
 }
}

void main()
{
 int ch,data;
 node ob;
 start=NULL;
 clrscr();
 do
 {
  cout<<"\n\n\n ... SINGLY LINKED LIST - SEARCH ... ";
  cout<<"\n\n 1.Insert\n 2.Display\n 3.Search\n 4. Exit\n ";
  cout<<"\n Enter your choice: ";
  cin>>ch;

  switch(ch)
  {
   case 1: ob.insert();
               break;
   case 2: ob.display();
               break;
   case 3: cout<<"\n Enter the data item to be searched: ";
               cin>>data;
               ob.search(data);
               break;
   case 4: cout<<"\n .... Thanking You! ....";
               getch();
               exit(0);
   default: cout<<"\n Invalid key-in ";
  }
 }while(1);

}



/*2. WAP to implement sorting in a linked list */

#include<iostream.h>
#include<conio.h>
#include<process.h>

class node
{
 int data;
 node *next;
 public:
 void insert();
 void sort();
 void display();
};

node *start,*head,*temp;

void node::insert()
{
 head=new node;
 cout<<"\n Enter the data item: ";
 cin>>head->data;
 head->next=NULL;
 if(start==NULL)
 {
  start=head;
 }
 else
 {
  temp=start;
  while(temp->next!=NULL)
  {
   temp=temp->next;
  }
  temp->next=head;
 }
}

void node::display()
{
 temp=start;
 if(start==NULL)
 cout<<"\n Data list is empty ";
 else
 {
  cout<<"\n DATA LIST: ";
  while(temp!=NULL)
  {
   cout<<temp->data<<" ";
   temp=temp->next;
  }
 }
}

void node::sort()
{
 if(start==NULL)
  cout<<"\n Data list is empty ";
 else
 {
  node *t1,*t2,*temp;
  for(t1=start;t1!=NULL;t1=t1->next)
  {
   for(t2=t1->next;t2!=NULL;t2=t2->next)
   {
    if(t1->data > t2->data)
    {
     temp->data=t1->data;
     t1->data=t2->data;
     t2->data=temp->data;
    }
   }
  }

  cout<<"\n List is sorted ";
 }
}

void main()
{
 int ch,data;
 node ob;
 start=NULL;
 clrscr();
 do
 {
  cout<<"\n\n\n ... SINGLY LINKED LIST - SORT ... ";
  cout<<"\n\n 1.Insert\n 2.Display\n 3.Sort\n 4. Exit\n ";
  cout<<"\n Enter your choice: ";
  cin>>ch;

  switch(ch)
  {
   case 1: ob.insert();
               break;
   case 2: ob.display();
               break;
   case 3: ob.sort();
               break;
   case 4: cout<<"\n .... Thanking You! ....";
               getch();
               exit(0);
   default: cout<<"\n Invalid key-in ";
  }
 }while(1);

}



/* 3.WAP to reverse a linked list, start pointer is given */

#include<iostream.h>
#include<conio.h>
#include<process.h>

class node
{
 int data;
 node *next;
 public:
 void insert();
 void reverse(node *);
 void display();
};

node *start,*head,*temp;

void node::insert()
{
 head=new node;
 cout<<"\n Enter the data item: ";
 cin>>head->data;
 head->next=NULL;
 if(start==NULL)
 {
  start=head;
 }
 else
 {
  temp=start;
  while(temp->next!=NULL)
  {
   temp=temp->next;
  }
  temp->next=head;
 }
}

void node::display()
{
 temp=start;
 if(start==NULL)
 cout<<"\n Data list is empty ";
 else
 {
  cout<<"\n DATA LIST: ";
  while(temp!=NULL)
  {
   cout<<temp->data<<" ";
   temp=temp->next;
  }
 }
}

void node::reverse(node *start)
{
 if(start==NULL)
  cout<<"\n Data list is empty ";
 else
 {
  int a[50],i=0,n;
  temp=start;
  //storing the data items to an array
  while(temp!=NULL)
  {
   a[i]=temp->data;
   temp=temp->next;
   n=i++;
  }
  i=n;
  temp=start;
  //forming linked list in reversed order
  while(temp!=NULL)
  {
   temp->data=a[i];
   temp=temp->next;
   i--;
  }

  cout<<"\n List is reversed ";
 }
}

void main()
{
 int ch,data;
 node ob;
 start=NULL;
 clrscr();
 do
 {
  cout<<"\n\n\n ... SINGLY LINKED LIST - REVERSE ... ";
  cout<<"\n\n 1.Insert\n 2.Display\n 3.Reverse\n 4. Exit\n ";
  cout<<"\n Enter your choice: ";
  cin>>ch;

  switch(ch)
  {
   case 1: ob.insert();
               break;
   case 2: ob.display();
               break;
   case 3: ob.reverse(start);
               break;
   case 4: cout<<"\n .... Thanking You! ....";
               getch();
               exit(0);
   default: cout<<"\n Invalid key-in ";
  }
 }while(1);

}


/*4. WAP to reverse a linked list within the list */

#include<iostream.h>
#include<conio.h>
#include<process.h>

class node
{
 int data;
 node *next;
 node *prev;
 public:
 void insert();
 void reverse();
 void display();
};

node *start,*head,*temp,*last;

void node::insert()
{
 head=new node;
 cout<<"\n Enter the data item: ";
 cin>>head->data;
 head->next=head->prev=NULL;
 if(start==NULL)
 {
  start=head;
  last=head;
 }
 else
 {
  last->next=head;
  head->prev=last;
  last=head;
 }
}

void node::display()
{
 temp=start;
 if(start==NULL)
 cout<<"\n Data list is empty ";
 else
 {
  cout<<"\n DATA LIST: ";
  while(temp!=NULL)
  {
   cout<<temp->data<<" ";
   temp=temp->next;
  }
 }
}

void node::reverse()
{
 if(start==NULL)
  cout<<"\n Data list is empty ";
 else
 {
  int len=0,lenM=0;
  temp=start;
  while(temp!=NULL)
  {
   len++;
   temp=temp->next;
  }
  node *t1,*t2,*temp;
  t1=start;
  t2=last;
  while(lenM<len/2)
  {
   temp->data=t1->data;
   t1->data=t2->data;
   t2->data=temp->data;
   t1=t1->next;
   t2=t2->prev;
   lenM++;
  }
  cout<<"\n List is reversed ";
 }
}

void main()
{
 int ch,data;
 node ob;
 start=last=NULL;
 clrscr();
 do
 {
  cout<<"\n\n\n ... SINGLY LINKED LIST - REVERSE WITHIN THE LIST ... ";
  cout<<"\n\n 1.Insert\n 2.Display\n 3.Reverse\n 4.Exit\n ";
  cout<<"\n Enter your choice: ";
  cin>>ch;

  switch(ch)
  {
   case 1: ob.insert();
               break;
   case 2: ob.display();
               break;
   case 3: ob.reverse();
               break;
   case 4: cout<<"\n .... Thanking You! ....";
               getch();
               exit(0);
   default: cout<<"\n Invalid key-in ";
  }
 }while(1);

}


/*5. WAP to remove first & last occurence of an element in a linked list */

#include<iostream.h>
#include<conio.h>
#include<process.h>

class node
{
 int data;
 node *next;
 public:
 void insert();
 void delet(int);
 void display();
};

node *start,*head,*temp;

void node::insert()
{
 head=new node;
 cout<<"\n Enter the data item: ";
 cin>>head->data;
 head->next=NULL;
 if(start==NULL)
 {
  start=head;
 }
 else
 {
  temp=start;
  while(temp->next!=NULL)
  {
   temp=temp->next;
  }
  temp->next=head;
 }
}

void node::display()
{
 temp=start;
 if(start==NULL)
 cout<<"\n Data list is empty ";
 else
 {
  cout<<"\n DATA LIST: ";
  while(temp!=NULL)
  {
   cout<<temp->data<<" ";
   temp=temp->next;
  }
 }
}

void node::delet(int data)
{
 temp=start;
 if(start==NULL)
 cout<<"\n Data list is empty ";
 else
 {
  //counting no. of occurence
  int count=0;
  while(temp!=NULL)
  {
   if(data==temp->data)
   {
    count++;
   }
   temp=temp->next;
  }

  //storing the position of occurence into an array
  int a[50],i=1,n,p=0;
  int pos[20];
  temp=start;
  while(temp!=NULL)
  {
   if(data==temp->data && i<=count)
   {
    pos[i]=p;
    i++;
   }
   temp=temp->next;
   p++;
  }

  //deleting first and last occurence
  int fst=pos[1];
  int lst=pos[count];
  node *t;
  temp=start;
  p=0;
  while(temp!=NULL)
  {
   if(data==temp->data && (fst==p || lst==p))
   {
    if(temp==start)
    {
     start=temp->next;
    }
    else
    {
     t->next=temp->next;
    }
   }
   t=temp;
   temp=temp->next;
   p++;
  }

 }
}

void main()
{
 int ch,data;
 node ob;
 start=NULL;
 clrscr();
 do
 {
  cout<<"\n\n\n ... SINGLY LINKED LIST - DELETE ... ";
  cout<<"\n\n 1.Insert\n 2.Display\n 3.Delete\n 4.Exit\n ";
  cout<<"\n Enter your choice: ";
  cin>>ch;

  switch(ch)
  {
   case 1: ob.insert();
               break;
   case 2: ob.display();
               break;
   case 3: cout<<"\n Enter the data item to be deleted: ";
               cin>>data;
               ob.delet(data);
               break;
   case 4: cout<<"\n .... Thanking You! ....";
               getch();
               exit(0);
   default: cout<<"\n Invalid key-in ";
  }
 }while(1);

}


/* 6.WAP to create a tree from inorder & preorder traversal sequences */

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>

char inorder[20];
struct node
{
 char data;
 int num;
 node *left;
 node *right;
};

node *root;

class bst
{
 public:
 bst()
 {
  root=NULL;
 }
 node * insert(node *,int,char);
 node * create(char []);
 void postorder(node *);

};

int pos(char a)
{
 int p;
 for(int i=0;inorder[i]!='\0';i++)
 {
  if(inorder[i]==a)
  {
   p=i;
   break;
  }
 }
 return p;
}


node * bst::insert(node *root,int num, char data)
{
 if(root==NULL)
 {
  root=new node;
  root->data=data;
  root->num=num;
  root->left=root->right=NULL;
 }
 else if(num<root->num)
  root->left=insert(root->left,num,data);
 else
  root->right=insert(root->right,num,data);

 return root;

}



node * bst::create(char pre[])
{
 const len=strlen(pre);
 char data;
 int num;
 for(int i=0;i<len;i++)
 {
  data=pre[i];
  num=pos(pre[i]);
  root=this->insert(root,num,data);
 }
 return root;
}


void bst::postorder(node * root)
{
 if(root!=NULL)
 {
  postorder(root->left);
  postorder(root->right);
  cout<<root->data<<" ";
 }
}


void main()
{
 clrscr();
 bst ob;
 char ino[25],pre[25];
 cout<<"\n Enter the inorder sequence: ";
 gets(ino);
 cout<<"\n Enter the preorder sequence: ";
 gets(pre);
 strcpy(inorder,ino);
 root=ob.create(pre);
 cout<<"\n The tree is created and the post order sequence is: ";
 ob.postorder(root);
 getch();

}


/* 7.WAP to exchange right and left subtree of each node OR to produce mirror image of the tree */

#include<iostream.h>
#include<conio.h>
#include<process.h>

struct node
{
 char data;
 node *lchild,*rchild;
};

node *head;

class tree
{
 node *root;
 public:
 tree()
 {
  root=NULL;
 }
 node * read();
 node * makenode(char);
 void createtree(node *);
 void inorder(node *);
 void preorder(node *);
 void postorder(node *);
 void exchange(node *);
};

node * tree::read()
{
 char item;
 cout<<"\n Enter data: ";
 cin>>item;
 root=makenode(item);
 createtree(root);
 return root;
}

node * tree::makenode(char x)
{
 head=new node;
 head->data=x;
 head->lchild=head->rchild=NULL;
 return head;
}

void tree::createtree(node *root)
{
 int ch;
 char item;
 if(root!=NULL)
 {
  cout<<"\n Create left child for "<<root->data<<" (if so press \"1\")";
  cin>>ch;
  if(ch==1)
  {
   cout<<"\n Enter data: ";
   cin>>item;
   root->lchild=makenode(item);
   createtree(root->lchild);
  }

  cout<<"\n Create right child for "<<root->data<<" (if so press \"1\")";
  cin>>ch;
  if(ch==1)
  {
   cout<<"\n Enter data: ";
   cin>>item;
   root->rchild=makenode(item);
   createtree(root->rchild);
  }
 }
}

void tree::inorder(node *root)
{
 if(root!=NULL)
 {
  inorder(root->lchild);
  cout<<root->data<<" ";
  inorder(root->rchild);
 }
}

void tree::preorder(node *root)
{
 if(root!=NULL)
 {
  cout<<root->data<<" ";
  preorder(root->lchild);
  preorder(root->rchild);
 }
}

void tree::postorder(node *root)
{
 if(root!=NULL)
 {
  postorder(root->lchild);
  postorder(root->rchild);
  cout<<root->data<<" ";
 }
}

void tree::exchange(node *root)
{
  if(root!=NULL)
  {
   exchange(root->lchild);
   exchange(root->rchild);
   node *temp;
   temp=root->lchild;
   root->lchild=root->rchild;
   root->rchild=temp;
  }
}

void main()
{
tree ob;
node *root;
int ch;
clrscr();
do
{
cout<<"\n\n.... BINARY TREE ....\n\n";
cout<<"\n1.Creation\n2.Inorder Traversal\n3.Preorder Traversal";
cout<<"\n4.Postorder Traversal\n5.Exchange\n6.Exit";
cout<<"\n\t Enter your choice: ";
cin>>ch;
switch(ch)
{
 case 1:root=ob.read();
            break;
 case 2:ob.inorder(root);
            break;
 case 3:ob.preorder(root);
            break;
 case 4:ob.postorder(root);
            break;
 case 5:ob.exchange(root);
            break;
 case 6:cout<<"\n\n\t... Thanking You ...";
            getch();
            exit(0);
 default:cout<<"\n Invalid key-in ";
}

}while(1);

}


Friday, June 19, 2009

Infosys Questions with Answers



 

Father's age is three years more than three times the son's age. After three years, father's age will be ten years more than twice the son's age. What is the father's present age.
33 years. (2 marks)

Find the values of each of the alphabets.
N O O N
S O O N
+ M O O N
----------
J U N E

9326 (2 marks)

There are 20 poles with a constant distance between each pole A car takes 24 second to reach the 12th pole. How much will it take to reach the last pole.
41.45 seconds (2 marks)
Let the distance between two poles = x
Hence 11x:24::19x:?

A car is travelling at a uniform speed. The driver sees a milestone showing a 2-digit number. After travelling for an hour the driver sees another milestone with the same digits in reverse order. After another hour the driver sees another milestone containing the same two digits. What is the average speed of the driver.
45 kmph (4 marks)

The minute and the hour hand of a watch meet every 65 minutes. How much does the watch lose or gain time and by how much?
Gains; 5/11 minutes (4 marks)

Ram, Shyam and Gumnaam are friends. Ram is a widower and lives alone and his sister takes care of him. Shyam is a bachelor and his niece cooks his food and looks after his house. Gumnaam is married to Gita and lives in large house in the same town. Gita gives the idea that all of them could stay together in the house and share monthly expenses equally. During their first month of living together, each person contributed Rs.25. At the end of the month, it was found that Rs 92 was the expense so the remaining amount was distributed equally among everyone.  The distribution was such that everyone received a whole number of Rupees. How much did each person receive?
Ans. Rs 2 (4 marks)
(Hint: Ram's sister, Shyam's niece and Gumnaam's wife are the same person)

At 6'o a clock ticks 6 times. The time between first and last ticks is 30 seconds. How long does it tick at 12'o clock.
66 sec. (2 marks)

Three friends divided some bullets equally. After all of them shot 4 bullets the total number of bullets remaining is equal to the bullets each had after division. Find the original number divided.
18 (2 marks)

Initially . x x x
Now x-4 x-4 x-4
Equation is 3x-12 = x

A ship went on a voyage. After it had travelled 180 miles a plane started with 10 times the speed of the ship. Find the distance when they meet from starting point.
200miles. (2 marks)
Distance travelled by plane = 1/10 distance travelled by ship + 180

Complete the Table given below:
Three football teams are there. Given below is the group table. Fill in the x's


Played Won Lost Draw Goals For Goals Against
A 2 2 x x x 1
B 2 x x 1 2 4
C 2 x x x 3 7


Ans : The filled table is given below (4 marks)

Played Won Lost Draw Goals For Goals Against
A 2 2 0 0 7 1
B 2 0 1 1 2 4
C 2 0 1 1 3 7

There are 3 societies A, B, C.  A lent cars to B and C as many as they had already.
After some time B gave as many tractors to A and C as many as they have. After sometime c did the same thing. At the end of this transaction each one of them had 24. Find the cars each originally had.

A had 39 cars, B had 21 cars & C had 12 cars (4 marks)

There N stations on a railroad. After adding X stations on the rail route 46 additional tickets have to be printed. Find N and X.
x=2 and N=11

Let initially, N(N-1) = t
After adding, (N+X)(N+X-1) = t+46
By trail and error method (4 marks)

Given that April 1 is Tuesday. A, B, C are 3 persons told that their farewell party was on
A - May 8, Thursday
B - May 10,tuesday
C - June 5, Friday
Out of A, B, C only one made a completely true statement concerning date, day and month
The other told two one told the day right and the other the date right..
What is correct date, month, day.


Ans: B - (May 10) SUNDAY
C - June 6 (Friday). (5 marks)

The Bulls, Pacers, Lakers and Jazz ran for a contest. Anup, Sujit, John made the following statements regarding results.
Anup said either Bulls or Jazz will definitely win
Sujit said he is confident that Bulls will not win
John said he is confident that neither Jazz nor Lakers will win

When the result came it was found that only one of the above three had made a correct statement.  Who has made the correct statement and who has won the contest.
Sujit; Lakers (5marks )

Five people A ,B ,C ,D ,E are related to each other. Four of them make one true statement each as follows.
(i) B is my father's brother.
(ii) E is my mother-in-law.
(iii)C is my son-in-law's brother
(iv)A is my brother's wife.


(i) D
(ii) B
(iii) E
(iv) C (10 marks)

 

Mr.Mathurs jewels have been stolen from his bank locker . The bank has lockers of 12 people which are arranged in an array of 3 rows and 4 columns like:
1 2 3 4
5 6 7 8
9 10 11 12
The locker belonging to JONES was to the right of BLACK'S locker and directly above MILLAR'S.
BOOTH'S locker was directly above MILLAR'S.
SMITH'S locker was also above GRAY's (though not directly).
GREEN'S locker was directly below SMITH'S.
WILSON'S locker was between that of DAVIS and BOOTH.
MILLAR'S locker was on the bottom row directly to the right of HERD'S.
WHITE'S locker was on the bottom right hand corner in the same column as BOOTH'S.
Which box belonged to Mr.Mathurs?

Box number 9 belongs to Mr.Mathurs.

Fifty minutes ago if it was four times as many minutes past three o'clock, how many minutes is it to six o'clock?
Twenty six minutes.

If a clock takes 7seconds to strike 7, how long will the same clock take to strike 10?
The clock strikes for the first time at the start and takes 7 seconds for 6 intervals-thus for one interval time taken=7/6.
Therefore, for 10 seconds there are 9 intervals and time taken is 9*7/6=10 and 1/2 seconds.

Three criminals were arrested for shop lifting. However, when interrogated only one told the truth in both his statements, while the other two each told one true statement and one lie. The statements were:
ALBERT :(a)Chander passed the merchandise. (b)Bruce created the diversion.
BRUCE :(a)Albert passed the merchandise. (b)I created the diversion.
CLIVE :(a)I took the goods out of the shop. (b)Bruce passed them over.

Albert passed the goods. Bruce created the diversion..Clive took the goods out of the shop.

Everyday in his business a merchant had to weigh amounts from 1 kg to 121 kgs, to the nearest kg. What are the minimum number of weight required and how heavy should they be?
The minimum number is 5 and they should weigh 1,3,9,27 and 81 kgs.

A hotel has 10 stores. Which floor is above the floor below the floor, below the floor above the floor, below the floor above the fifth.
The sixth floor.

Seven members sat around a table for three days for a conference. The member's names were Abhishek,  Amol,  Ankur,  Anurag,  Bhuwan, Vasu and Vikram. The meetings were chaired by Vikram. On the first evening members sat around the table alphabetically. On the following two nights, Vikram arranged the seating so that he could have Abhishek as near to him as possible and absent minded Vasu as far away as he could. On no evening did any person have sitting next to him a person who had previously been his neighbor. How did Vikram manage to seat everybody to the best advantage on the second and third evenings?
Second evening: Vikram, Ankur, Abhishek, Amol, Vasu, Anurag and Bhuwan.
Third evening :Vikram, Anurag, Abhishek, Vasu, Bhuwan, Ankur, Amol.

Two trains start from stations A and B spaced 50 kms apart at the same time and speed. As the trains start, a bird flies from one train towards the other and on reaching the second train, it flies back to the first train. This is repeated till the trains collide. If the speed of the trains is 25 km/h and that of the bird is 100km/h.
How much did the bird travel till the collision.

100 kms.

Four prisoners escape from a prison. The prisoners, Mr East, Mr West, Mr South, Mr. North head towards different directions after escaping. The following information of their escape was supplied: The escape routes were The North Road, South Road, East Road and West Road.
None of the prisoners took the road which was their namesake.
Mr. East did not take the South Road
Mr. West did not the South Road.
The West Road was not taken by Mr. East
What road did each of the prisoners take to make their escape?

Mr. East took the North Road
Mr. West took the East Road
Mr. North took the South Road
Mr. South took the West Road.

Complete the series:
5, 20, 24, 6, 2, 8, ?

12 (as 5*4=20, 20+4=24, 24/4=6, 6-4=2, 2*4=8, 8+4=12).

Replace each letter by a digit. Each letter must be represented by the same digit and no beginning letter of a word can be 0.
O N E
O N E
O N E
O N E
-------
T E N

0 =1, N = 8 ,E = 2, T = 7

Ann, Boobie, Cathy and Dave are at their monthly business meeting. Their occupations are author, biologist, chemist and doctor, but not necessarily in that order. Dave just told the biologist that Cathy was on her way with doughnuts.
Ann is sitting across from the doctor and next to the chemist. The doctor was thinking that Boobie was a goofy name for parent's to choose, but didn't say anything. What is each person's occupation?

Since Dave spoke to the biologist and Ann sat next to the chemist and across the doctor, Cathy must be the author and Ann the biologist. The doctor didn't speak, but David did, so Bobbie is the doctor and Dave the chemist.

Sometime after 10:00 PM a murder took place. A witness claimed that the clock must have stopped at the time of the shooting. It was later found that the position of both the hands were the same but their positions had interchanged. Tell the time of the shooting (both actual and claimed).
Time of shooting = 11:54 PM
Claimed Time = 10:59 PM

Next number in the series is
1 , 2 , 4 , 13 , 31 , 112 , ?

 
224.
No number has digits more than 4. All of them are 1 , 2, 4, 8 , 16 , 32 , 64 converted to numbers in base 5

Shahrukh speaks truth only in the morning and lies in the afternoon, whereas Salman speaks truth only in the afternoon. A says that B is Shahrukh. Is it morning or afternoon and who is A - Shahrukh or Salman.
Afternoon ; A is Salman.

Two trains starting at same time, one from Bangalore to Mysore and other in opposite direction arrive at their destination 1 hr and 4 hours respectively after passing each other. How much faster is one train from other?
Ans: Twice

There are 6 volumes of books on a rack kept in order ( ie vol.1, vol. 2 and so on ).
Give the position after the following changes were noticed.

All books have been changed

Vol.5 was directly to the right of Vol.2
Vol.4 has Vol.6 to its left and both weren't at Vol.3's place
Vol.1 has Vol.3 on right and Vol.5 on left
An even numbered volume is at Vol.5's place

Find the order in which the books are kept now.

Ans: 2 , 5 , 1 , 3 , 6 , 4

I bought a car with a peculiar 5 digit numbered license plate which on reversing could still be read. On reversing value is increased by 78633.Whats the original number if all digits were different?
Only 0 1 6 8 and 9 can be read upside down. So on rearranging these digits we get the answer as 10968

Supposing a clock takes 7 seconds to strike 7. How much long will it take to strike 10?
10 1/2 seconds.

A man collects cigarette stubs and makes one full cigarette with every 8 stubs. If he gets 64 stubs how many full cigarettes can he smoke.
Ans: 8+1=9

A soldier looses his way in a thick jungle. At random he walks from his camp but mathematically in an interesting fashion. First he walks one mile East then half mile to North. Then 1/4 mile to West, then 1/8 mile to South and so on making a loop.  Finally how far he is from his camp and in which direction.
Ans: Distance travelled in north and south directions
1/2 - 1/8 + 1/32 - 1/128 + 1/512 - and so on
= 1/2/((1-(-1/4))
Similarly in east and west directions
1- 1/4 + 1/16 - 1/64 + 1/256 - and so on
= 1/(( 1- ( - 1/4))
Add both the answers

How can 1000000000 be written as a product of two factors neither of them containing zeros
Ans: 2 power 9 x 5 power 9

Conversation between two mathematicians:
First : I have three children. The product of their ages is 36. If you sum their ages, it is exactly same as my neighbor's door number on my left.
The second mathematician verifies the door number and says that it is not sufficient.
Then the first says " Ok one more clue is that my youngest is really the youngest". Immediately the second mathematician answers .

Can you answer the question asked by the first mathematician? What are the children ages?
Ans 1,6 and 6

Light glows for every 13 seconds . How many times did it glow between 1:57:58 and 3:20:47 am.
Ans: 383 + 1 = 384

500 men are arranged in an array of 10 rows and 50 columns according to their heights.
Tallest among each row of all are asked to fall out.
And the shortest among them is A.
Similarly after resuming that to their original positions that the shortest among each column are asked to fall out.
And the tallest among them is B .
Now who is taller among A and B ?


Ans A

A person with some money spends1/3 for cloths, 1/5 of the remaining for food and 1/4 of the remaining for travel. He is left with Rs 100/- . How much did he have with him in the beginning ?
Ans: Rs 250/-

There are six boxes containing 5 , 7 , 14 , 16 , 18 , 29 balls of either red or blue in color. Some boxes contain only red balls and others contain only blue. One sales man sold one box out of them and then he says " I have the same number of red balls left out as that of blue ". Which box is the one he sold out ?

Ans: Total no of balls = 89 and (89-29 /2) = 60/2 = 30
and also 14 + 16 = 5 + 7 + 18 = 30

A chain is broken into three pieces of equal lengths containing 3 links each. It is taken to a blacksmith to join into a single continuous one . How many links are to to be opened to make it ?

Ans: 2.

Grass in lawn grows equally thick and in a uniform rate. It takes 24 days for 70 cows and 60 days for 30 cows to eat the whole of the grass. How many cows are needed to eat the grass in 96 days.?

Ans: 20
g - grass at the beginning
r - rate at which grass grows, per day
y - rate at which one cow eats grass, per day
n - no of cows to eat the grass in 96 days
g + 24*r = 70 * 24 * y
g + 60*r = 30 * 60 * y
g + 96*r = n * 96 * y
Solving, n = 20.

From a vessel, 1/3rd of the liquid evaporates on the first day. On the second day 3/4th of the remaining liquid evaporates. What fraction of the volume is present at the end of the second day.

Ans: 50%

An orange glass has orange juice and white glass has apple juice both of equal volumes. 50ml of the orange juice is taken and poured into the apple juice.
50ml from the white glass is poured into the orange glass. Of the two quantities, the amount of apple juice in the orange glass and the amount of orange juice in the white glass, which one is greater and by how much?


Ans: The two quantities are equal

There is a 4 inch cube painted on all sides. This is cut down into of 1 inch cubes.
What is the no of cubes which have no pointed sides.


Ans: 8

Sam and Mala have a conversation.
Sam says I am certainly not over 40
Mala says I am 38 and you are atleast 5 years older than me
Now Sam says you are atleast 39
All the statements by the two are false.

How old are they really?

Ans: Mala = 38 yrs
Sam = 41 yrs.

At 6'o a clock ticks 6 times. The time between first and last ticks is 30 seconds. How long does it tick at 12'o clock.
Ans: 66 sec. (2 marks)

Three friends divided some bullets equally. After all of them shot 4 bullets the total number of bullets remaining is equal to the bullets each had after division. Find the original number divided. 
Ans: 18 (2 marks)
Initially . x x x
 
Now x-4 x-4 x-4
 
Equation is 3x-12 = x

A ship went on a voyage. After it had travelled 180 miles a plane started with 10 times the speed of the ship. Find the distance when they meet from starting point. 
Ans: 200miles. (2 marks)
Distance travelled by plane = 1/10 distance travelled by ship + 180

Complete the Table given below:
Three football teams are there. Given below is the group table. Fill in the x's 
Played Won Lost Draw Goals For Goals Against 
A 2 2 x x x 1 
B 2 x x 1 2 4 
C 2 x x x 3 7 
Ans: The filled table is given below (4 marks)
Played Won Lost Draw Goals For Goals Against
 
A 2 2 0 0 7 1
 
B 2 0 1 1 2 4
 
C 2 0 1 1 3 7

There are 3 societies A, B, C. A lent cars to B and C as many as they had already. After some time B gave as many tractors to A and C as many as they have. After sometime c did the same thing. At the end of this transaction each one of them had 24. Find the cars each originally had. 
Ans: A had 39 cars, B had 21 cars & C had 12 cars (4 marks)

There N stations on a railroad. After adding X stations on the rail route 46 additional tickets have to be printed. Find N and X. 
Ans. x=2 and N=11
Let initially, N(N-1) = t
After adding, (N+X)(N+X-1) = t+46
By trail and error method (4 marks)

Given that April 1 is tuesday. A, B, C are 3 persons told that their farewell party was on 
A - May 8, thursday 
B - May 10,tuesday 
C - June 5, friday 
Out of A, B, C only one made a completetly true statement concerning date,day and month The other told two one told the day right and the other the date right. What is correct date, month, day.
Ans: B - (May 10) SUNDAY
C - June 6 (Friday). (5 marks)

The Bulls, Pacers, Lakers and Jazz ran for a contest. Anup, Sujit, John made the following statements regarding results. 
Anup said either Bulls or Jazz will definitely win 
Sujit said he is confident that Bulls will not win 
John said he is confident that neither Jazz nor Lakers will win 
When the result came it was found that only one of the above three had made a correct statement. Who has made the correct statement and who has won the contest. 
Ans: Sujit; Lakers (5marks )

Five people A ,B ,C ,D ,E are related to each other. Four of them make one true statement each as follows.
(i) B is my father's brother. 
(ii) E is my mother-in-law.
(iii)C is my son-in-law's brother
(iv)A is my brother's wife.
Ans: (i) D
(ii) B
 
(iii) E
(iv) C (10 marks)

 

Which of the following involves context switch,
a) system call 
b)privileged instruction
c)floating point exception
d)all the above
e)none of the above
Ans: a

For 1 MB memory no of address lines required,
a)11 
b)16 
c)22 
d) 24
Ans: 16

Semaphore is used for
a) synchronization 
b) dead-lock avoidance
c)box 
d) none
Ans : a

Y=10; 
if( Y++>9 && Y++!=10 && Y++>10)
printf("........ Y);
else printf("".... )

Ans : 13

f=(x>y)?x:y
a) f points to max of x and y
b) f points to min of x and y
c)error
d) ........

Ans : a

if x is even, then

(x%2)=0
x &1 !=1
x! ( some stuff is there)

a)only two are correct
b)three are correct

Ans : all are correct

Which of the function operator cannot be over loaded

a) <=
b)?:
c)==
d)*

Ans: b and d

10,20,30,40,50,60 : give the order when put in a queue and in a stack

Ans : Queue : 10,20,30,40,50,60
stack : 60,50,40,30,20,10

Debugging is the process of finding
Ans : logical and runtime errors

Trace the error:

void main()
{
int &a;
/* some other stuff here */
}

Ans: syntax error

A problem with a function named 'myValue' will be given and asked to  find the value of main() for an argument of 150,

Ans : 150

 



 

Contact Form

Name

Email *

Message *