EMC Written Exam for Software Engineer Applicants 程序员招聘面试试题思路详解

来源:互联网 发布:西门子plc编程软件xp 编辑:程序博客网 时间:2024/06/04 07:44

EMC Written Exam for Software Engineer Applicants
November 2007
Instructions
You will have 3 hours to take this exam. This exam contains 19 pages, and is divided into 4
sections. During this exam, you are NOT allowed to use any computers, calculators, or other
electronic devices. Please review the questions first, and pace yourself accordingly. Good luck!
Section 1: Informational only(0 points each, 0% of total score)
This section contains multiple-choice questions. These questions do not count for any points, and
are only for informational purposes. Please mark your answers on the answer sheet located on
page 12.
1. In applying for this job,what is your first choice of location?
A. Beijing
B. Shanghai
2. What is your second choice of location?
A. Beijing
B. Shanghai
C. None(I am only applying for the first choice location)
3. If your location choices include Beijing, what is your team preference?
A.. Beijing: EMC team
B. Beijing: Vmware team
C. Beijing: No preference(either team)
D. I am only applying for Shanghai position(EMC team only)
4. What is your first choice in terms of position(job role)?
A. Software Development Engineer
B. Software QA Engineer
C. No preference
5. What is your second choice in terms of position(job role)?
A. Software Development Engineer
B. Software QA Engineer
C. None.(I am only applying for the first choice position.)

 

Section 2: Multi-Choice(1 point each, 60% of total score)
This section contains 32 multi-choice questions. For each question, only one answer is correct.
Please mark your answer sheet located on page 12. Answers marked on this question sheet will
not be read or scored.
A correct answer will score 1 point; a blank answer will score 0 points; an incorrect answer will
score negative 1/4 point. You are allowed to leave an answer blank.


1. Place the following 6 values in increasing order:
-0.5, (2/e), −e(1/ 2) , 2(1/ e) ,(1/π ), -(π /2)
A. -(π /2), −e(1/ 2) , -0.5, (1/π ), , (2/e) 2(1/ e)
B. −e(1/ 2) , -(π /2), -0.5, (1/π ), (2/e), 2(1/ e)
C. −e(1/ 2) , -(π /2), -0.5, ,(1/ 2(1/ e) π ), (2/e)
D. -(π /2), −e(1/ 2),-0.5, 2(1/ e),(1/π ), (2/e)
E.−e(1/ 2) , -(π /2), -0.5, (1/π ), , (2/e) 2(1/ e)

 


2. A positive number, when divided by 3, has a remainder of 1. When divided by 5, it has a
remainder of 4. And when divided by 7, it has a remainder of 3. What is the smallest number
that satisfies above conditions?
A. 64
B. 94
C. 129
D. 304
E. None of the above.

 


3. Assuming n>=2, how many prime numbers are there among n!+2, n!+3, n!+4,…, n!+n?
A. 1;
B. 2
C. floor(n/2)
D. n-1
E. None of the above


4. What are the most reasonable two numbers to follow the sequence:
A. 124, 217
B. 125, 217
C. 125, 215
D. 126, 215
E. None of the above


5. If F(n)=50!*5 , (n is positive integer), what number is the least value of n such that F(n) and
F(n+1) have the same number of trailing 0’s (F(n) is represented in decimal)?
n
A. 34
B. 35
C. 36
D. 37
E. None of the above


6. There are 5 balls making a ring. Each ball is red or white, with equal probability. What is the
probability that no two red balls are adjacent to each other in this ring?
A. 7/32
B. 5/16
C. 11/32
D. 13/32
E. None of the above


7. As shown in the following figure, the shaed region is enclose by four lines, which all start from
a square’s vertex, and end at a midpoint of the square’s side. If the side of the square has a length
of 1, then what is the area of the shaded region?
A. 2/7
B. 1/4
C. 1/5
D. 1/9
E. None of the above


8. A Double Tower of Hanoi contains twice the number of disk as the regular Tower of Hanoi
problem, where each disk size appears twice. So there are 2n disks, of n different sizes (n>0). As
usual, there are 3 pegs. The objective is to transfer the whole tower form the original peg to one of
the other two pegs, moving only one disk at a time, without putting a larger one over a smaller one.
Putting a same-sized disk onto another is okay. If we are required to reproduce the original
top-to-bottom order arrangement, how many moves (minimal) does it take? Remember, disks of
equal size need to be in original order, and cannot be inversed.
A. 2n + 2n−1
B. 22n −1
C. 2(n+1) − 2
D. 2(n+2) −5
E. 2*3(n−1) +1
9. A binary tree has 7 nodes, which are denoted as A, B, C, D, E, F, and G. When the tree is walked
in pre-order, the route is A-B-D-G-C-E-F. When this tree is wealked in in-order, the route is
D-G-B-A-E-C-F. Which of the following is the correct route when the tree is walked in
post-order?
A. A-B-D-G-E-F-C
B. G-D-B-A-E-F-C
C. D-B-G-A-C-E-F
D. G-D-B-E-F-C-A
E. None of the above

思路:

前序遍历: A B D G C E F

中序遍历:D G B A E C F

 

根据前序遍历的结果

前序遍历的非递归方法

while(p || !is_empty())

{

     while(p)

    {

            s.push(p);

            cout<<p->data;

            p = p->left;

    }

    s.pop();

     p = p->right;

}

先输出的肯定是根节点,然后输出的根节点的左节点 ,如果没有了左节点,那么就输出右节点。依次类推就能把所有节点输出了

     可能的二叉树结构为;

                     A

                   /     \

                 B        C

              /     \    /     \

            D       G E     F

或者

                    A

                  /    \

                B      C

               /       /   \

             D      E     F

                \

                  G

 

中序遍历的非递归的方法

while( p || ! is_empty())

{

            while(p)

            {

                 s.push(p);

                  p = p->left;

            }

            s.pop();

            cout<<p->data;

             p = p->right;

}

 

中序遍历先输出 左子树的左子节点,然后输出根节点,然后输出右子节点。以此类推

 

得出的节点为:

                   A

                  /    \

                B      C

               /       /   \

             D      E     F

                \

                  G

 

 

 所以呢得出这个二叉树的结构为:

 

                    A

                  /    \

                B      C

               /       /   \

             D      E     F

                \

                  G

 

 

那么后序遍历得出的为:

LRD 先访问左节点,然后右节点,最后根节点

所以呢输出结果为:

G D B E F C A

 

 


10. Which of following entities CANNOT be shared by multiple threads of a process?
A. Data section
B. Thread-local variables
C. Register set
D. Stack
E. None of the above


11. According to ISO/OSI model, which layer does the UDP protocol belong to ?
A. Network layer
B. Transport layer  //UDP提供不可靠的传输服务
C. Data link layer
D. Application Layer
E. None of the above


12. Generally, in a Linu

x system with Bourne-like shell, which of folowing methods does NOT
make a program run in background?
A. Adding a “&” at the end of the command line.
B. Pressing “Ctrl+Z” when the program is running in the foreground, and then using the system
command “bg”
C. Starting a program to fork a child process, executing the program form child process by calling
the system libray function, and then terminating the parent process.
D. Pressing “Ctrl+S” when the program running in the foreground.
E. None of the above.


13. Which of following numbers(in base 3) is closest to decimal number 0.8889?


A. 0.21
B. 0.211
C. 0.212
D. 0.22
E. None of the above


14. RAID-3, RAID-4, and RAID-5 have the same fault-tolerance mechanism to protect data.
Which of the following statements is NOT true to describe their differences?
A. RAID-3 accesses all the disks at one time,while RAID-4 and RAID-5 accesses each disk
independently
B. In RAID-3 and RAID-4, a dedicated disk is used to store parity, while in RAID-5 the parity is
striped across all the disks in the array,
C. RAID-3 can only execute one I/O request at a time, while RAID-4 and RAID-5 can execute
multiple I/O requests simultaneously.
D. RAID-3 and RAID-4 requires a minimum of 3disks to implement, while RAID-5 requires a
minimum of 5 disks to implement.
E. None of the above


15. For an IA-32 system, which of following choices is the correct order according to the memory
layout of a Linux program, from lower address to higher address?


A. Heap, Stack, Text
B. Text, Heap, Stack
C. Heap, Text, Stack
D. Text, Stack, Heap
E. Stack, Heap, Text


16. Which of following statements is NOT true about sort algorithms?


A. Quick sort has a time complexity of O(nlog(n)) in average, and O( n2 ) in the worst case.
B. Bubble sort is a stable sort algorithm, and its time complexity is O( n2 )
C. Merge sort’s time complexity is O(nlog(n)), and it requires O(n) linear amount of extra storage
space.
D. Selextion sort’s time complexity is O( n2 ), and it is also a stable sort algorithm.
E. Heap sort has a time complexity of O(nlog(n)) in worst case, but it requires O(n) linear amount
of extra storage space.

 

快速排序 不稳定排序 ,平均时间复杂度为O(nlog(n)) ,最坏的复杂度为O( n2 )

冒泡排序:稳定的排序,时间复杂度为:O( n2 )

选择排序: 时间复杂度为O( n2 ), 但是它是不稳定的排序方法


17. In C, someone writes the following function to reverse a one-dimensional array. For example,
when the input is {1,2,3,4,5}, then the result should be {5,4,3,2,1}.
int reverse_array(int *list, int len){
int *p1,*p2;
int temp;
if(len<=0) return -1;
while(p1!=p2){
temp=*p1;
*p1=*p1;
*p2=temp;
p1++;
p2--;
}
Return 0;
}
Which of the following statements is correct when you compile and run this program?
A. Compilation error appears
B. Program runs correctly
C. Program runs correctly when length of input array is odd.
D. Program runs correctly when length of input array is even.
E. None of the above

应该是直接运行错误 , 这个代码并没有这个功能,而且运行也不会出错,应该是。


18. Assume you have two singly linked lists, denoted as L1 and L2. It is possible that L1 and L2
meet on some node and have a common tail. If L1 has m nodes and L2 has n nodes, then what is
the best time complexity to check if the two linked lists meet and to find out the meeting point?
(Only O(1) constant amont of extra storage space is allowed.)
A. O((m+n)*log(m+n))
B. O(m*n)
C. O(m+n)
D. O((m+n)*log(m*n))
E. O(log(m*n))


19. Tjere are n green buckets and n red buckets. Each green bucket is of a different size, but for
every green bucket, there is a corresponding red bucket of the dame size. What is the AVERAGE
time complexity to find all matching buckets pairs(red and green bucket of the same size) if the
comparisons between buckets of same color are forbiden. (Only O(1) constant amount of extra
storage space is allowed.)
A. O(n)
B. O(log(n))
C. O(n*n)
D. O(nlog(n))
E. None of the above
20. In Java, how can you force garbage collection of an object ?
A. Garbage collection of a particular object annot be forced.
B. Call System .gc()
C. Call System.gc(), passing in a reference to the object to be garbage collected.
D. Call Runtime.getRuntime().gc()
E. Set all referenes to the object to new values(for example, null)


21. A Java program is shown as below:
Public class Test{
Static boolean foo(char c){
System.out.print(c);
Return true;
}
Public static void main(String[] argv){
int i=0;
for(foo(‘A’);foo(‘B’)&&(i<2);foo(‘C’)){
i++;
foo(‘D’);
}
}
}
What wil the above program print?
A. ABDCBDCB
B. ABCDABCD
C. Compilation error.
D. An exception is thrown at runtime.
E. None of the above.


22. In C, which of following definitions is correct in defining an array of pointers, with each item
of this array being a pointer to function like
int func(int *)?
A. int (*p[20])(int *)
B. int (*p)(int *)[20]
C. int (*p)(int *[20])
D. int *(*p[20])(int *);
E. None of the above.

指针数组 数组里面装的是指针

 

 


23. In little-endian systems, what is the result of following C program?
typedef struct bitstruct{
int b1:5;
int :2;
int b2:2;
}bitstruct;
void main(){
bitstruct b;
memcpy(&b,”EMC EXAMINATION”,sizeof(b));
printf(“%d,%d\n”, b.b1, b.b2);
}

b.b1 = 5;

b.b2 = -2

大小端的问题:

小端 是 数据的高字节存储在空间的高地址,数据的低字节存储在空间的低地址

大端  数据的高字节存储在空间的低地址,数据的低字节存储在空间的高地址

 


24. In IA-32 systems, what is the result of following C program?
#define MAX 255
int main(){
unsigned char A[MAX+1],i;
for(i=0;i<=MAX;i++)
A[i]=i;
printf(“%d\n”,A[0]);
Return 0;
}
A. 0
B. 255
C. 256
D. The program won’t return and will print nothing
E. Compile error.

 

首先 unsigned char 的范围为 0~255

当 i 的值为 256时 ,会转化为 0

这个有问题的,改为

for(i = 0;i< MAX ; i++)

就可以了

 


25. What is the result of following C program?
int inc(int a){
return (++a);
}
typedef int (*FUNC1) (int in);
int multi(int *a, int *b, int *c){
return (*c=*a**b);
}
typefef int (FUNC2) (int *, int *, int *);
void show(FUNC2 fun, int arg1, int *arg2){
FUNC1 p=&inc;
int temp=p(arg1);
printf(“%d\n”,*arg2);
}
Main(){
Int a;
Show(multi,10,&a);
Return 0;
}
A.. 100
B. 110
C. 120
D. 130
E. None of the above

 这个题目有问题,函数参数根本没有给与初始化。


26. What will the following C function f2() print?
void f1(char *s  ,  char *t){
if(*s==’\0’) return;
*t=*s;
f1(++s,++t);
}
void f2(){
char *s1=”The C Programming Language is good”;
char *s2=”The C Programming Language”;
char *t=(char *)malloc(strlen(s1)+1);
memset(t,0,strlen(s1)+1);
f1(s1,t);
f1(s2,5);
printf(“%s\n”,t);
}
A. egaugnaL gnimmargorP C ehT
B. The C Programming Language
C. 27
D. Doog si egaugnaL gnimmargorP C ehT
E. The C Programming Language is good

思路:

函数f1(char *s ,char *t)

这个函数的功能是将字符串 s 复制到字符串中 t 中,

函数f2(){}首先给t分配一个内存空间,然后将里面的内容初始化为0,然后然后将s1的内容复制到t中。


27. In C++, Class A is defined simply as:
Class A{};
What is results of calling sizeof(A)?
A. 0
B. 1
C. 4
D. 64
E. None of the above

思路:

空类的大小为1

类的实例化是在内存中分配一块地址,每个实例在内存中都有独一无二的二地址。同样,空类也会实例化,所以编译器会给空类隐含的添加一个字节,这样空类实例化后就有独一无二的地址了。所以,空类的sizeof为1,而不是0.

 

 


28. What will the following C++ function print?
int func()
{
float a=1.0f;
cout<<boolalpha<<( (int)a==(int &)a )<<” ”;
float b=0.0f;
cout<<boolalpha<<( (int)b==(int &)b )<<endl;
}
A. true true
B. false false
C. true false
D. false true
E. None of the above

思路:

首先a 为1.0f是浮点数,把他

 

 


29. Four people are in a group
Alice says,”Exactly one of us is lying.”
Bob says, ”Exactly two of us are lying.”
Charles says, “Exactly three of us are lying.”
Dick says, “All four of us are lying.”


How many people in this group are lying?
A. 0
B. 1
C. 2
D. 3
E. 4

思路 4个人都在说慌

首先 A说有一个说谎,肯定就是自己了,

然后 B说有两个说谎,那么他肯定是自己说谎 然后知道A也说谎,那么就有两个

然后 C听说 A在说谎,B说谎,那么自己说谎,他说有3个

最后 D听说已经有3 个在说谎了,自己也说谎,总共有4个在说谎了。


30. Allen and Brenda, both have a note stuck on their forehead, with a positive integer number
written on it .Both Allen and Brenda can see each other’s number. They also know that the two
numbers have a difference of one. They are trying to figure out the number on their own forehead.
Allen first says,”I don’t know my number.”
Brenda says,” I don’t know my number either”
Then Allen says “Now, I know my number”
Brenda now says, “Yeah, I know my number also!”
What is the number of Allen and Brenda?
A. 2,1
B. 1,2
C. 3,2
D. 2,3
E. 4,3


31. The traveling gropu will consist of exactly three members to be selected from the seven pepole:
A,B,C,D,E,F and G. The selection will be done according to the following conditiions:
* Neither A nor B can be in the group unless the other is also in the group.
*If C is in the group, the D must be in the group
*E and F cannot sboth be in the group
* If G is in the group, then A cannot be in the group
Which of following is the travelling group?
A. (C,E,G)
B. (D,E,G)
C. (C,D,A)
D. (E,F,G)
E. (A,B,G)


32. Two kinds of chemical material are stored in six buckets(each bucket has only one kind of
chemical). The volumes of these buckets are: 8L, 13L, 15L, 17L, 19L and 31L. It is also known
that the price of one chemical is twice that of the other. A man has purchased five of the buckets,
and found that he spent the same amount money on each kind of chemical. Which bucket was left
unsold?
A. 8L
B. 13L
C. 15L
D. 17L
E. 19L


Section 3: Programming Questions(5 points each, 30% of total score)
This section contains 4 programming questions. These questions are to evaluate your
programming skills. Please choose and answer any 3 of the 4 questions (You can skiop any one
qeustion). Your answers here will help us in our candidate selection for the face-to-face interiews
and for the final offers. Please wirte your answers directly on these question sheets. For each
problem, you may write your answer using any one of these programming language: C, C++, C#,
or Java.
All algorithms should be implemented by yourself, instead of calling any existing API. In general,
no libray functions can be used, except for those that are explicitly allowed by the question. Here
are some guidelines:

 

1. Write a function to find the Kth node form the last node of a singly-linked list, and analze the
time and space complexity of your funciton.
The input to the function is a pointer or reference to the head of the list.
The output is a pointer or reference to the Kth node from the last node.
For example, given a pointer or reference to the node that conains ”1” below, if K is 3, your
function should return a pointer or reference to the node that contains “8”.
1 3 5 2 4 8 7 6

typedef struct LinkNode
{  
 int data ;
 struct LinkNode *next;
}node;

node *nizhi(node *head)
{
 node *p ,*s0 ,*s1;
 p = head->next;
 s0=NULL;
 s1=NULL;
 while(p)
 {
  s0 = p;
  p = p->next;
  s0->next = s1;
  s1 = s0;
 }
 head->next = s0;
 return head;
}

node *create(int n)
{  

 node *head=new node();
 node *p ;
 p = head;
 int x;
 while(n)
 {
  node *pNode= new node();
  printf("请输入节点数据:");
  scanf("%d",&x);
  pNode->data = x;
  p->next = pNode;
  p = pNode;
  n--;

 }
 p->next=NULL;
 return head;
}

node *findx(node *head , int k)
{
   node *p = head->next;
   int i = 0;
   while(p)
   {
     i++;
  if(i == k)
  {
   return p;
   break;
  }
  p = p->next;
   }
}


void main()
{
 int n;
 node *head = new node();
 node *phead = new node();
 node *p;

 printf("请输入节点个数:");
 scanf("%d",&n);
 head = create(n);
 phead = nizhi(head);

    p = findx(phead , 2);
 cout<<p->data<<endl;


}

 

3. Write a function to find the two closest points given N points in X-Y coordinates, and analyze
the time and space complexity of your function.
The input to this funciton is a pointer or reference to an array of points, along with N.
The ouput is a pointer or reference to a two-element array that stores the coordinates of the two
points closest to each other.

 

void findx(int a[][2] ,int N)
{
  int i ,j ,k,temp,tmp;
  int count_1[100];
  int count_2[100];
  k = 0;
  int min[100];
  for(i = 0; i<N ;i++)
  {
   for(j = i+1 ;j<N ;j++)
   {
    min[k] = (a[j][1]-a[i][1])*(a[j][1]-a[i][1]) + (a[j][0] -a[i][0])*(a[j][0] -a[i][0]);
    count_1[k] = i;
    count_2[k] = j;
    k++;
   }
  }
  for(i = 0 ;i<k-1 ;i++)
  {
   if( min[i+1] > min[i])
   {
    temp = min[i+1];
    min[i+1] = min[i];
    min[i] = temp;
   }
  }
  // 最小值为min[k-1]
  for(i = 0;i<k ;i++)
  {
   if( min[k-1] == (a[count_1[i]][1]-a[count_2[i]][1])*(a[count_1[1]][1] -a[count_2[i]][1]) + (a[count_1[i]][0]-a[count_2[i]][0])*(a[count_1[i]][0]-a[count_2[i]][0]) )
   {
                tmp = i;
   }
  }
  printf("相距最近的俩个节点为:\n");
  cout<<"(";
  cout<<a[count_1[tmp]][0];
  cout<<",";
  cout<<a[count_1[tmp]][1];
  cout<<")"<<endl;
    
  cout<<"(";
  cout<<a[count_2[tmp]][0];
  cout<<",";
  cout<<a[count_2[tmp]][1];
  cout<<")"<<endl;
  

}

void main()
{
 int a[3][2]={{1,1},{3,1},{3,2}};
 findx(a,3);
}

 

3. Write a function to find any subset of 3 integers from a set of N integers that have a sum with
the smallest absolute value, and analyze the time and space complexity of your function.
The input to this funciton is pointer or reference to any array of integers, along with the value of
N.
When N>=3, the ouput is a 3-element array of integers, such that their sum has the smalles
absolute value.
When N<3, the ouput is null.
For example,given the following input:{-99, -66, 0, 2, 3}, your function should return {0,2,3}

 

 

思路: 把这个数组中的所有的数每三个进行相加,然后再比较他们的和,求出最小的,

首先对这个数组进行排序,从小到大,确定a[first]+a[begin]+a[end] 先确定a[first] a[end] 然后再变换a[begin]

当求的和小于0时,说明这个和有负数,还得继续进行加,beign++;

当求的和大于0时,当再加时,肯定会比这个和还要打,所以呢就进行end--;

记录每次求的的和,与之前的最小的进行比较 ,把其中最小的设为最小,然后继续,知道把所有的都比较完成。

 int threeIntegerSumMinAbsValue(int a[] ,int len)
 {
 
  //quickSort(a, 0, a.length-1);

   int i ,j,tmp;
   for(i =0 ;i<len-1 ;i++)
   {
    for(j = i+1 ;j<len ;j++)
    {
     if(a[i]>a[j])
     {
      tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
     }
    }
   }

 

 

 
  int resultMin = 65535;  //设置最大的数

  for(i = 0 ; i<len ; i++)
  {
 
     int first = i;
     int begin = 0;
     int end = len-1;
     int sumtemp = 65535;
     if(begin==i)
  {
        begin++;
  }
   
     if(end==i)
  {

   end--;

  }
     while(begin<end)
  {
   
        int loopSum = a[first]+ a[begin] + a[end];
        if( loopSum<0 )
  {
          loopSum=-loopSum;
    {
              begin++;
    }
        
          if(begin==i)
    {
             begin++;
    }
         
  }
        else
  {
          end--;
          if(end==i)
    {
             end--;
    }
         
  }
        if(loopSum<sumtemp)
  {
          sumtemp = loopSum;
          if(loopSum==0)
          break;
  }
  }
  
     if( sumtemp<resultMin )
  {
          resultMin = sumtemp;
  }
   
     if(resultMin==0)
  {
          break;
  }
   
 
  }
 
  return resultMin;
 }

 


void main()
{
 int a[]={-99,-66,0,2,3};
 int m;
 m=threeIntegerSumMinAbsValue(a ,5);
      cout<<m<<endl;
}

 

 

原创粉丝点击