博文

目前显示的是 四月, 2011的博文

Linked List

Now I am reading things about the linked list. List contains Node Head,Tail which are also Node And the length of list. Node has a record of the next Node, it will point to the next element in the linked list. So, use while loop, like while(node.next!=null), this method will traverse the entire list.

Intern interview 2

MySQL 选取一个table 某一列的最大值,或者最小值 select min(COLUMN_NAME) from TABLENAME 选取前十项: select * from TABLENAME limit 10

Careercup April 19

今天做了 一道题,感触很大,给一组数 arraylist{2,9,11,3,5,6,34,22} target=14 找到其中两数之和是target 的数的index 想了一个办法先built 数组 Use loop do go over the entire list O(n^2) 发现网上大牛的解法佩服的不行O(n) int add(ArrayList al){ int target=11; boolean found=false; HashMap map = new HashMap (); for (int i = 0; i < al.size(); ++i) { Integer temp = map.get(target - Integer.parseInt(al.get(i).toString())); if (temp == null) { map.put(Integer.parseInt(al.get(i).toString()), i); } else { found = true; System.out.println(String.format("Given sum %d, found %d at index %d and %d at index %d.", target,Integer.parseInt(al.get(i).toString()), i, target - Integer.parseInt(al.get(i).toString()), temp)); } } 用HashMap,连table 都不用建立。 Go over 一遍就可以了,用(target-al(i)),做HashMap 大赞!!!

Intern interview prepare

c++ STL standard template library 其实STL就是一个模板,一个程序员写好一个类,以后可以复用,不用再写。 Careercup 很好的查题目的网站 总结一下去Broadcom 和 Moto面试的题 这次面试比较失败 Broadcom 两个多小时的面试题,有些记不清了,应该当时写的。 记得最清楚的就是阿三哥问我的那道题: 1. which language do you prefer, describe the difference between and C++ and Java 我的回答是Java is more Objective oriented, it does not have pointer, it's platform independent, it's easy to use and has friendly IDE (对方笑了,明显不是重点) 说完后,他说这些都不是重点, 我疑惑。 重点应该是: garbage allocation, C++ 没有这个机制,需要手动收回memory(这个问题很重要,manager 问了类似的问题) 2. Fred 问我的问题: 解释一下Semaphore, (一开始没懂) 写一个程序 用semaphore 实现,有的threads want to write to that buffer other threads want to read from that buffer (OS 写过啊,可是当时想不起来了) During the R/W, there may be context switch, so there may be RAW hazard. 3. a string which contains characters such as "aafjkczddfcccbbdae", think of a way to find the character which appears most of the time, which has the highest frequency.(没想出来) 4. change that string to ordered string such as "aaabbbbccccc" th

Data Structure Review(1)

Triangle Array: Assume location (i, j,k) The first case 0<=i One example of array is 0 1 2| 0 1 3| 0 1 4 0 2 3 0 2 4 1 2 3 0 3 4 1 2 4 1 3 4 2 3 4 The first element of a column is (0, 1, k) We have to go through k choose 3 elements to reach the point (since the range is from 0 to k-1, after choose the three elements, the order is fixed) After that is (0,j,k), we have to go through j chose element to reach that At last (i,j,k) we have to go another i choose i element, So total cost for reaching that point is: k choose 3 + j choose 2 + i choose i I do not think the triangle array has any advantage

Floating Point Pipeline

For floating point operation, we have several functional units. Such as: adder, multiplier, divider, ALU (integer value) These functional units can execute concurrently. For a floating point adder which take four cycles to complete, after its execution begins, another execution functional unit except itself could start(revised:for the adder it could also start because it's pipelined but for the divider it can not start). Thus data hazard may happen, because several instruction may arrive at the MEM stage at the same time. We need to resolve this conflict by stall, we can detect the conflict in the ID stage before execution. I do not know the specific method yet, I will find it latter.

Data Hazard

今天学习了Data Hazard 的知识: 主要有几种, RAW, WAR, WAW Read After Write Instruction 1: r3<--r2+r1 Instruction 2: r4<--r3+r2 "RAW" means r3 should be read by I2 after I1 has written it. I1: r1 <-- r3+r4 I2: r3 <--r1+r2 "WAR" means r3 should be read by I1 before I2 could write to it.

Pipeline Exception Handling

今天看了一种最简单的, exception handling in pipeline 如果, exception happens. IF will fetch a trap instruction to handle the exception Also, the instruction before the exceptional instruction will be stopped. The instruction precede to it will continue. It will save PC and restore it after exception has been handle. 我猜应该是trap instruction 结束以后。 这个只是对于integer value, but for floating point operation. One instruction may take several cycles to complete. 不知道该怎么办,我觉得应该用stall 的方法 。

Page Fault

2010 Fall 学operating system的时候 学过但是记不清了,是cache miss 还是 memory miss 刚才wiki 了一下,发现是 memory miss, the memory for a computer is limited, sometimes we do not need to load all the data a process need to the memory. We may save part of them to the disk, and load it when the process requires. The memory system is hierarchy. If the process requires the data, it will go to the address in memory to find it, if the data has been swapped to the disk, a page fault will be generated.

Topology Sorting 拓扑排序

Data Structure 作业 已知一个文件: the first character of the file is the number of elements Then there will be pairs of numbers such as: 3 1 1 4 For the first pair, it means 1 is after 3. In the topology, 3 precedes to 1. One example of the file is: 5 3 1 1 4 2 0 0 1 0 4 3 4 I should sort them according to this information. The method I used is called successor list. First I will build a successor list: 0-->1,4 1-->4 2-->0 3-->4 The implementation of this is simple, go over the file word by word, after reading the element number 5. If it's the first, third, 5th ... of the word then save the number to temporary variable, if it's 2nd 4th 6th or .... Save it to the cache[temp], also increment count[2nd 4th 6th or ...] vector by 1. After that I will check if there is an element in count vector with value 0(the element in the vector is initialed to all 0) If there is push it to the no_predecessor list. The procedure is the first round of checking After that, pop element from

Amdahl's Law 阿姆达尔定律

Amadahl Gene 发现的定律 极其的简单 speedup(overall)= Exectution time(old)/Execution time(new)=1/(1-Fraction(enhanced))+Fraction(enhanced)/speedup(Enhanced) 说白了就是1个processor,或者一个machine 可能有不同个component 1个component 性能提高了,对整个processor or machine性能提高有多大 比方说一个processor 比重占全局的10% 它的性能提高了100倍。那个整个系统性能提高应该是 1/(90%+10%/100)=1/90.1%

面试准备(test methodologies)

Black Box Testing: It's a specification based testing. It's name is black box, because tester input and sees the output. The entire procedure is like a black box, the tester does not know what's inside the box. White Box Testing: It's a unit based testing. We divide the program into different components or units, and test them separately. Then do the integration.

Pipeline Register (流水寄存器)

这个中文翻译也太扯淡了 由于Pipeline 把instruction 分成不同的stage, the time needed by each stage is different. So we need to set a time which is slightly longer than the longest time needed among all the stages. The purpose for using pipeline register is to ensure clock synchronization. When the clock cycle edge arrives, all the stages will go to next step at the same time.

Pipeline Hazard

疑惑了几天什么叫做: Pipeline Hazard 终于明白了,原来这么简单啊。 Pipeline 可能分成5个stages 1. 当硬件不能support 5 个stage 同时运行的时候。 2. 当 Instruction 之间相互联系的时候 (我最开始想到的,如果一条instruction 需要另外一个才能执行) 3. Instructions may change PC (不明白) Pipeline 本来是为了提高效率,hazard 却降低了它的效率

Benchmark 简介

初次认识 benchmark 它是对一个系统的评价。 最早,system designer 自己做benchmark,但是他们做的benchmark通常是 toy program, 这些程序不能真实的反应system 的性能 所以出现 了 benchmark designer 这些人设计 benchmark 通常是成千上万行的程序,这样很难修改 SPEC 好像是设计benchmark 的公司。

Homogeneous coordinate(齐次坐标)

Computer Vision 里面用到 Homogeneous coordinate 这个坐标系太有意思了。 1. 它可以把笛卡尔坐标系中infinity 的点表示成 finite 2. 一个点的坐标乘以 no-zero scalar 仍然表示这个点 (a point can be represented by a set of homogeneous coordinate, while can only be represented by a single Cartesian coordinate)