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

第一次做阿里笔试题。除了ACM题之外从来没有做过校招网络题呀。全然是裸考,整体感觉吧,对于我来说。感觉时间不够用,不是题不会,感觉时间紧,大脑非常混乱。总结这一次的笔试题

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


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


双向循环列表,从不论什么一个元素開始能够遍历所有元素

先和后面的元素相连

s->next=p->next;

p->next->prev=s->next;

在前面的元素相连

p->next=s;

s->pre=p;

答案显而易见


绘图能够实现


时间轮转为1秒

A 24

B 20

C 7

D14

总时间为73所以平均周转时间为16.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;
}
}

本人做的,可能有不正确的。希望大家提出啊。持续更新中


原文地址:https://www.cnblogs.com/bhlsheji/p/5284336.html