您的位置:首页 > 其它

阿里笔试题(2015)持续更新中

2014-08-30 02:16 344 查看
第一次做阿里笔试题,除了ACM题之外从来没有做过校招网络题呀,完全是裸考,总体感觉吧,对于我来说,感觉时间不够用,不是题不会,感觉时间紧,大脑很混乱,总结这一次的笔试题

废话不多说,直接上题和答案



平均每个人逗留时间为20分钟,那么开场前20分钟一共来了400人,且有20个人逗留时间已经到,应该容纳400人



双向循环列表,从任何一个元素开始可以遍历全部元素

先和后面的元素相连

s->next=p->next;

p->next->prev=s;

在前面的元素相连

p->next=s;

s->pre=p;

答案显而易见 第二项



画图可以实现



时间轮转为1秒

A 24

B 20

C 7

D14

总时间为73所以平均周转时间为73/4=18.25



有4种坐的方式

在不考虑四个小孩的顺序只考虑这四个小孩坐哪四个位置的时候, 四个小孩坐一起的时候有8个方向,2个面对面的时候只有4个。

结果为480



动态分配都在堆中,毋容置疑



Yield()暂时交出cpu控制权,从running状态转为runnalbe状态,但是仍有可能被调度,sleep()线程指定休眠一段时间wait()在其他线程调用此对象的notify()notifyAll()方法时才能继续执行线程中sleep()方法和yeild()方法的主要区别
: 1.sleep()
方法会给其他线程运行的机会,而不管其他线程的优先级,因此会给较低优先级的线程运行的机会;yeild()方法只会给优先级相同的或者比自己高的线程运行的机会2.sleep()方法声明抛出InterruptionException异常,而yeild()方法没有声明抛出任何异常3.sleep()方法比yeild()方法具有更高的可移植性4.sleep()方法使线程进入阻塞状态yeild()方法使线程进入就绪状态当前运行的线程可以调用另一个线程的join()方法,当前运行的线程将转到阻塞状态直到另一个线程运行结束,它才会恢复运行
 join()有两种形式:public void join()和public void join(long timeout)可以设置阻塞的时间
sleep()方法进入阻塞状态,当有两个线程(线程1和线程2),线程1的优先级比线程2的优先级高,线程1sleep()则线程2可以获得运行机会

当有比当前线程优先级高的线程出现时,高优先级会抢占CPU并运行,yield()方法,暂停一段时间,且这段时间不确定,它会使与当前线程相同优先级的线程获得运行机会

具有相同优先级的多个线程调度不一定是分时的,多核CPU可能同时调度



首先选择排序、插入排序、冒泡排序时间复杂度为 O(n^2)

快速排序最坏排序为时间复杂度O(n^2)

堆排序需要知道是大顶堆或者小顶堆,因为不了解数列特征所以不推荐其复杂度为O(nlgn);

所以快排是最优的





TCP/IP建立在三次握手协议基础上



前提条件是,虚拟机发生故障当且仅当它的宿主发生故障

根据条件得出虚拟机发生故障则物理机发生故障,则这台物理机所虚拟出的虚拟机会发生故障,所以虚拟机发生的故障不是彼此独立的,单台虚拟机的故障率和单台物理机的故障率是相同的,如果组成集群,那么当某个虚拟机发生故障时,另一个虚拟机会代替发生故障的虚拟机运行,所以可靠性比5台物理机的可靠性相同,所以无法判断这一百台虚拟机和100台物理机哪个更可靠

附加题1

sleep()和wait()的区别

sleep()是让进程休眠一段时间,sleep()休眠持有锁,不释放系统资源,时间过后自动醒来进入可运行状态,但不一定执行,取决于虚拟机的调度,sleep(milliseconds)可以用时间指定使它自动唤醒过来,如果时间不到只能调用interrupt()强行打断。

wait是进入线程等待池等待,出让系统资源,其他线程可以占用CPU。一般wait不会加时间限制,因为如果wait线程的运行资源不够,再notify()也没用,要等待其他线程调用notify/notifyAll唤醒等待池中的所有线程,才会进入就绪队列等待OS分配系统资源。

使用范围:wait,notify和notifyAll只能在同步控制方法或者同步控制块里面使用,而sleep可以在任何地方使用 
   synchronized(x){ 
      x.notify() 
     //或者wait() 
   }

附加题2

大意,插入一个二叉树,求二叉树最大节点和最小节点的绝对值

java 代码如下

//树节点

public class TreeNode1 {
private TreeNode1 leftChild;
private TreeNode1 rightChild;
int intege;

public TreeNode1 getLeftChild() {
return leftChild;
}
public void setLeftChild(TreeNode1 leftChild) {
this.leftChild = leftChild;
}
public TreeNode1 getRightChild() {
return rightChild;
}
public void setRightChild(TreeNode1 rightChild) {
this.rightChild = rightChild;
}
public int getIntege() {
return intege;
}
public void setIntege(int intege) {
this.intege = intege;
}
public TreeNode1(int intege) {
super();
this.intege = intege;
}

}

二叉树

public class Btree1 {

private int max;
private int min;

public Btree1(int max, int min) {
super();
this.max = max;
this.min = min;
}

//构造二叉树
public void insert(TreeNode1 root, int i) {
if (root == null) {
System.out.println("树为空");
} else {

if (root.getIntege() < i) {
if (root.getLeftChild() != null) {
insert(root.getLeftChild(), i);
} else {
root.setLeftChild(new TreeNode1(i));
}
} else {
if (root.getRightChild() != null) {
insert(root.getRightChild(), i);
} else {
root.setRightChild(new TreeNode1(i));
}
}
}
}

插入二叉树,遍历找到节点最大值和最小值
public void FindMax_Min(TreeNode1 root) {
if (root == null) {
System.out.println("该树为空");
} else {
if(root.getIntege()>max)
{
max=root.getIntege();
}
if(root.getIntege()<min)
{
min=root.getIntege();
}
//System.out.println(root.getIntege() + "  ");
if (root.getLeftChild() != null) {
FindMax_Min(root.getLeftChild());
}
if (root.getRightChild() != null) {
FindMax_Min(root.getRightChild());
}
}
}
public void Max_Min_abs()
{
System.out.println(max-min);
}
public static void main(String[] args) {
int a[]={1,45,6,7,12,89,2,17};
Btree1 b=new Btree1(-10000,10000);
TreeNode1 treeNode1=new TreeNode1(a[0]);
for(int i=1;i<a.length;i++)
{
b.insert(treeNode1, a[i]);
}
b.FindMax_Min(treeNode1);
b.Max_Min_abs();
}

}

附加题3

求两个字符串最大的连续出现的公共部分 列如query为acbac,text为acaccbabb那么公共子串为cba 长度为3

下面为java代码编写

import java.util.Scanner;

public class FindMaxSubString {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("请输入query");
/*String str1 = "acbac";
String str2 = "acaccbabb";
*/
String str1=s.nextLine();
System.out.println("请输入text");
String str2=s.nextLine();
String result = getMaxString(str1, str2);
if(result!=null)
{
System.out.println(result.length());
}
else
{
System.out.println("没有公共子串");
}
}

private static String getMaxString(String str1, String str2) {
String max = null;
String min = null;
max = (str1.length() > str2.length() ? str1 : str2);
min = max.equals(str1) ? str2 : str1;
for (int i = 0; i < min.length(); i++) {
for (int start = 0, end = min.length() - i; end != min.length() + 1; start++, end++) {
String sub = min.substring(start, end);
if (max.contains(sub))
return sub;
}
}
return null;
}

}

本人做的,可能有不对的,希望大家提出啊,持续更新中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  2015阿里笔试题