ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories >> Code-Snippets
 
 


 

Back to Questions Page
 
Question
Show by induction that 2n > n2, for all n > 4.
Rank Answer Posted By  
 Question Submitted By :: Shara
This Interview Question Asked @   Qatar-University , Kanvay, Turkey
I also faced this Question!!   © ALL Interview .com
Answer
it is wrong .
 
0
Rajesh
 
 
Question
Coin Problem 

You are given 9 gold coins that look identical. One is 
counterfeit and weighs a bit greater than the others, but
the difference is very small that only a balance scale can
tell it from the real one. You have a balance scale that 
costs 25 USD per weighing.

Give an algorithm that finds the counterfeit coin with as 
little weighting as possible. Of primary importance is that
your algorithm is correct; of secondary importance is that
your algorithm truly uses the minimum number of weightings
possible. 

HINT: THE BEST ALGORITHM USES ONLY 2 WEIGHINGS!!!
Rank Answer Posted By  
 Question Submitted By :: Shara
This Interview Question Asked @   Qatar-University
I also faced this Question!!   © ALL Interview .com
Answer
1. Divide the coins in 3 groups of 3 coins each
2. Put 2 groups in the weighing scale
3a. If both the groups weigh equal
    1. Pick 2 coins from the 3rd group and put in weighing scale
    2. If they weigh equal, the 3rd coin is counterfeit.
Else the coin which weigh more is counterfeit
3b. If they do not weigh equal, pick the group with more
weight and do steps 3a1 and 3a2.  
 
4
Pawan Jain
 
 
Question
 What is the time complexity T(n) of the following program?

a)
int n, d, i, j;
cin >> n;
for (d=1; d<=n; d++)
for (i=1; i<=d; i++)
for (j=1; j<=n; j += n/10)
cout << d << " " << i << " " << j << endl;


b)
void main()
{ int n, s, t;
cin >> n;
for (s = 1; s <= n/4; s++)
{t = s;
while (t >= 1)
{ cout << s << " " << t << endl;
t--;
}
}
}


c)
void main()
{ int n, r, s, t;
cin >> n;
for (r = 2; r <= n; r = r * 2)
for (s = 1; s <= n/4; s++)
{
t = s;
while (t >= 1)
{
cout << s << " " << t << endl;
t--;
}
}
}

Rank Answer Posted By  
 Question Submitted By :: Shara
This Interview Question Asked @   Qatar-University , Cts
I also faced this Question!!   © ALL Interview .com
Answer
1.t(n)=10*n*n*(n+1)/2
2.t(n)={n/4*(n/4)*[(n/4)+1]}/2
 
0
Arunthathi
 
 
 
Answer
a-   (n*n)*log(n).
b-  log(n)*log(n).
c-log(n)*log(n)*log(n).
 
0
Rajesh Kumar Pal
 
 
Question
How reader and writer problem was implemented and come up
with effective solution for reader and writer problem in
case we have n readers and 1 writer.
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   NetApp
I also faced this Question!!   © ALL Interview .com
Answer
The reader and writer problem is IMPLEMENTED THROUGH 
SEMAPHORES.

THE EFFECTIVE SOLUTION TO SOLVE THE READER AND WRITER 
SOLUTION IS :


A)    If a writer is waiting in the ready queue to enter 
into the critical section, then the current reading process 
should be completed without delay.

B)    Only one reader can be put into the ready queue 
because the writer is waiting.

c)    The semaphores such as ReadCount-to count the number 
of reader in ready queue,
Reader and Writer, these are the important semaphores to 
solve the reader and writer problem.
 
1
Sriram
 
 
Question
Finding a number multiplication of 8 with out using 
arithmetic operator
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   NetApp , Eyeball
I also faced this Question!!   © ALL Interview .com
Answer
i << 3
 
5
Wl
 
 
Answer
/*      PROGRAM TO FIND WHETHER A NUMBER IS A MULTIPLE OF 2 
AND 8 WITHOUT
		USING ARITHMETIC OPERATOR  */

#include<stdio.h>
#include<conio.h>
void main()
 {
   int num;
   clrscr();
   printf("\n enter a  number");
   scanf("%d",&num);
   if(num & 1)
    printf("\n not a multiple of 2");
   else
    printf("\n a multiple of 2");
   if(num & 7)
    printf("\n not a multiple of 8");
   else
    printf("\n a multiple of 8");

   getch();
 }
 
0
Splurgeop
 
 
Answer
i=n<<3;
 
0
Raghuram.A
 
 
Answer
boolean div8(x){
  return (x & 7)
}

if return is 0 = divisible by 8
 
0
Lloyd.tumulak
 
 
Answer
int i,n=1;
 i=n<<3
 
0
Ram
 
 
Answer
#include <stdio.h>
main()
{
      int x,n;
      printf("Enter the X number:");
      scanf("%d",&x);
      n=(x<<3)-x;
      printf("The Answer is : %d",n);
      getch();
}
 
0
Saravanan E
 
 
Answer
#include <stdio.h>
main()
{
      int x,n;
      printf("Enter the X number:");
      scanf("%d",&x);
      n=(x<<3)-x;
      printf("The Answer is : %d",n);
      getch();
}
 
0
Saravanan E , Ps Technologies,
 
 
Question
Finding a number which was log of base 2
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   NetApp
I also faced this Question!!   © ALL Interview .com
Answer
log of base 2 means given variable is power of 2. So 

void main(){
     int x;
     if(x&(x-1){ 
        printf("Given Number is not log base 2\n");
     }
 
}
 
5
Jaganathan Gnanavelu
 
 
Question
Sorting entire link list using selection sort and insertion
sort and calculating their time complexity
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   NetApp , Microsoft
I also faced this Question!!   © ALL Interview .com
Answer
insertion sort took more time, because it done after 
complete selection sort...
 
0
Shiju
 
 
Question
Link list in reverse order.
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   NetApp
I also faced this Question!!   © ALL Interview .com
Answer
recursive reverse(ptr)
  if(ptr->next==NULL)
  return ptr;
  temp=reverse(ptr->next);
  ptr=ptr->next;
  return ptr;
  end
 
0
Sameera.adusumilli
 
 
Answer
node *reverse(node *first)


{
node *cur,*temp;


cur=NULL;

while(first!=NULL)


{temp=first;

first=first->link;

temp->link=cur;

cur=temp;
}

return cur;

}
 
0
Raghuram.A
 
 
Answer
/*
the structure is as follows:
struct node
{
   int data;
   struct node *next;
}
*/

struct node * reverse (struct node *home , struct node *rev)
{  
  struct node temp , *p;

  if(home != NULL)
  {
    temp = home;
    while(temp != NULL)
    {
       //this part will create a new node with the name p.
       p = myalloc;
       p -> data = temp -> data;
       p -> next = NULL;
          
       if(rev == NULL)
          rev = p;
       else
       {
              p -> next = rev;
              rev = p;
       }
       temp = temp -> next;
      }
   }
return rev;
}
 
0
Shruti
 
 
Answer
**Liked list as a stack = linked list in reverse order.

/*
the structure is as follows:
struct node
{
   int data;
   struct node *next;
}
*/

struct node * reverse (struct node *home , struct node *rev)
{  
  struct node temp , *p;

  if(home != NULL)
  {
    temp = home;
    while(temp != NULL)
    {
       //this part will create a new node with the name p.
       p = myalloc;
       p -> data = temp -> data;
       p -> next = NULL;
          
       if(rev == NULL)
          rev = p;
       else
       {
              p -> next = rev;
              rev = p;
       }
       temp = temp -> next;
      }
   }
return rev;
}
 
0
Shruti
 
 
Answer
write a link list program to insert integer number and then 
display its sum as well. Your program should display the 
address as well as the result
write a program to reverse a link list so that the last 
element becomes the first one and so on
copy one link list to another list
 
0
Aqib
 
 
Answer
//Go through the code, incase any issues feel free to 
revert.

Copying a link list:

//home is the stationary pointer of the main linked list 
which is to be copied.

//head is the stationary pointer of the new linked list 
which has to be created..

//temp and temp1 are the moving pointers attached to the 
respective linked list...


struct node *copy(struct node *home , struct node *head)
{
  struct node *temp , *temp1 , *p;
  
  temp = home;
  while(temp != NULL)
  {
       p = (struct node *) malloc (sizeof(struct node));
       p -> data = temp -> data;
      
       if(head == NULL)
             head = p;
        
        else
        {
             temp1 = head;
             while(temp1 -> next != NULL)
                   temp1 = temp1 -> next;
               
              temp1 -> next = p;
         }
    temp = temp -> next;
}
return head;
}
 
0
Shruti
 
 
Answer
#include <stdio.h>

typedef struct list
{
 int data;
 struct list * next;
} LIST;

LIST* reverse(LIST *head)
{
  LIST* temp;
  LIST* temp1;

  if (head == NULL || head->next == NULL)
    return head;
  else
  {
    temp = head->next;
    head->next = NULL;
    while(temp)
    {
      temp1 = temp->next;
      temp->next = head;
      head = temp;
      temp = temp1;
    }

    return head;
  }
}

int main(int argc, char ** argv)
{
 int i=0;
 LIST* head = NULL;
 LIST* node = NULL;
 int count;

 if (argc < 2) printf("usage: a.out <count>");
 else count = atoi(argv[1]);

 for (i=0;i<count;i++)
 {
   node = (LIST*)calloc(sizeof(LIST));
   node->data = i;
   node->next = head;

   head = node;
 }

 node = head;
 while(node)
 {
   printf("before %d\n", node->data);
   node = node->next;
 }

 head = reverse(head);
 printf("after head=%d\n", head->data);
 node = head;
 while(node)
 {
   printf("after %d\n", node->data);
   node = node->next;
 }
}
 
0
Lijun Li
 
 
Question
String reverse with time complexity of n/2 with out using
temporary variable.
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   NetApp , Symantec
I also faced this Question!!   © ALL Interview .com
Answer
#include<iostream.h>

#include<string.h>//complexity-n/2

int main()
{
int i,l,l1;
char str[100];
cout<<"enter string:";
gets(str);
l=strlen(str);
if(l%2==0)
l1=(l/2-1);
else
l1=l/2;
for(i=0;i<=l1;i++)/*swap elements from 2 ends till u reach
middle part of array*/
{
char t=str[i];
str[i]=str[l-i-1];
str[l-i-1]=t;
}
str[l]=0;
cout<<"\n\nreversed string is:"<<str;
getch();
return 0;
}
 
0
Raghuram
 
 
Answer
#include<stdio.h>
#include<string.h>
main(int argc, char *argv[])
{
  char  *string = argv[1];
  int len = strlen(string);
  int i = 0;
  int j = len - 1;
  printf("string before is %s\n", string);
  printf("len is %d\n", len);
  while(i <= j)
  {
    *(string+i) += *(string+j);
    *(string+j) = *(string+i) - *(string+j);
    *(string+i) = *(string+i) - *(string+j);
    i++;
    j--;
    if(len % 2)
     if(i == j) break;
  }
  printf("reversed string is %s\n", string);
}
 
0
Gayathri Sundar
 
 
Answer
#include<stdio.h>

void reverse(char *);

void main()
{
	char str[]="Hello";

	reverse(str);
	printf("Reverse String is %s",str);
	
}

void reverse(char *p)
{

	char *q=p;
	while(*++q!='\0');
	q--;

	while(p<q)
	{
		*p=*p+*q;
		*q=*p-*q;
		*p=*p-*q;
		p++;
		q--;
	}

}
 
0
Atul Kabra
 
 
Answer
refer c book!
    or
contact me
 
0
Prof.muthu (9962940220)
 
 
Answer
#inclue<stdio.h>
       #include<string.h>
       main(){
           char a[10],i;
           int len=1;
           printf(" Enter string ");
           fgets(a,9,stdin);
     
           len = strlen(a);
     
      
          for(i=0 ; i<(len/2) ; i++){
                  a[i]=a[i]+a[len-2];
                  a[len-2]=a[i]-a[len-2];
                  a[i]=a[i]-a[len-2];
                  len--;
          }
          printf("\n Reverse string with n/2 complexity
 %s",a);
          return 0;
      }
 
0
Suraj Bhan Gupta
 
 
Answer
It's all O(n). You're finding the length of the string,
which itself is an O(n) operation.
So, O(n + n/2) = O(n).
 
0
A
 
 
Answer
#include <iostream>
#include <string>
using std::string;
using std::cout;
using std::endl;
using std::cin;

int main()
{
    string s("abcdefghijklmnopqrstuvwxyz");
    string::size_type s_size = s.size();

    for (string::size_type x = 0; x != s_size; x++){

        if ( (s_size -x -1) > x ){

            s[x] ^= s[s_size - x -1];
            s[s_size - x -1] ^= s[x];
            s[x] ^= s[s_size - x -1];

        }else{
            break;
        }

    }

    cout << s << endl;
}
 
0
Mm Chen
 
 
Question
String copy logic in one line.
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   NetApp
I also faced this Question!!   © ALL Interview .com
Answer
strpy(n1,n2)
here copy of string n2 in string n1
 
0
Vijay
 
 
Answer
while(str1[i]!=0) str2[j++]=str1[i++];
 
0
Raghuram.A
 
 
Answer
for(i=0;(str2[i]=str1[i])!='\0';i++);
 
0
Lavanya
 
 
Answer
while ((*target++ = *source++));
 
0
Yash
 
 
Answer
for(i=0; str2[i] = str1[i]; i++);
 
0
Shruthirap
 
 
Answer
strcpy(s1,s2); //copies string s1 to s2
 
0
Rajendra
 
 
Answer
void cpy_user(char *s, char *t)
{
while ((*s++ = *t++) != '\0');
}
 
0
Jitendra
 
 
Question
how to retrive file ,using file info on click event of a 
buton and disply it on a web form
Rank Answer Posted By  
 Question Submitted By :: Tina
This Interview Question Asked @   Activa-Softec
I also faced this Question!!   © ALL Interview .com
Answer
If your document store in database in binary format then
code for retrive the document is

string sqlQuery="write the select statement"
datareaderObject =cmd.executereader(sqlQuery,connectionname);
if(datareaderObject.read())
{
 Response.Buffer = false;
            Response.ClearHeaders();
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition",
"attachment; filename=" +
datareaderObject["docname"].ToString());

            //Code for streaming the object while writing
            const int ChunkSize = 1024;
            byte[] buffer = new byte[ChunkSize];
            byte[] binary = (datareaderObject["doc"]) as byte[];
            MemoryStream ms = new MemoryStream(binary);
            int SizeToWrite = ChunkSize;
            for (int i = 0; i < binary.GetUpperBound(0) - 1;
i = i + ChunkSize)
            {
                if (!Response.IsClientConnected) return;
                if (i + ChunkSize >= binary.Length)
SizeToWrite = binary.Length - i;
                byte[] chunk = new byte[SizeToWrite];
                ms.Read(chunk, 0, SizeToWrite);
                Response.BinaryWrite(chunk);
                Response.Flush();
            }
            Response.Close();
        }
    }

if document store in virtual path


 if (datareadear.Read())
        {
            FileInfo file = new
System.IO.FileInfo(Server.MapPath("datareadear["filename"].ToString());
            if (file.Exists)
            {
                Response.Clear();
                Response.AddHeader("content-disposition",
"attachment; filename=" + file.Name);
                Response.AddHeader("Content-Length",
file.Length.ToString());
                Response.ContentType =
"application/octet-stream";
                Response.WriteFile(file.FullName);
                Response.End();
            }
            else
            {
                Response.Redirect("../error.aspx?error=" +
"File dose not exits");
                Response.End();
            }
        }
 
0
Kapil
 
 
Question
how to connect  bind a control to database by writing a 
stored procedure?
Rank Answer Posted By  
 Question Submitted By :: Tina
This Interview Question Asked @   Satyam
I also faced this Question!!   © ALL Interview .com
Answer
dim con as sqlconncetion
dim cmd as sqlcommand
dim parm as sqlparameter
con=new sqlconnection
("server=localhost;database=Database1;username=sa;password=s
a")
cmd=new sqlcommand
con.open()
cmd.commandtype=commandtype.storedprocedure
cmd.commandtext="StoredprocedureName"
cmd.parmaeters.add("@Name",txtname.txt)
cmd.parameters.add("@sal",txtname.txt)
cmd.excutenonquery()
con.close()
 
2
Badrinath
 
 
Answer
dim con as sqlconncetion
dim cmd as sqlcommand
dim parm as sqlparameter
con=new sqlconnection
("server=localhost;database=Database1;username=sa;password=s
a")
cmd=new sqlcommand
con.open()
cmd.commandtype=commandtype.storedprocedure
cmd.commandtext="StoredprocedureName"
cmd.parmaeters.add("@Name",txtname.txt)
cmd.parameters.add("@sal",txtname.txt)
cmd.excutenonquery()
con.close()
 
0
Badrinath
 
 
Answer
SqlConnection conn = new SqlConnection(strconn);
SqlCommand comm = new 
SqlCommand"[StoreProcedureName]",conn);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.AddWithValue("@UserId", Id);
sqldataadapter da= new sqldataadapter;
Dataset ds = new dataset;
try
{
conn.open();
da.fill(ds);
conn.fill;
}
catch
{
throw(ex);
}
dlFilldatalist.datasourse = ds;
dlFilldatalist.databind();
 
0
Shivani
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com