注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
大摩上海的tech summer intern,10道左右的技术小题,1道系统设计,技术小题的题目相当固定。以下是当时面试的时候准备技术小题找的一些面经和部分写了的答案。. From 1point 3acres bbs
花了半天地时间准备了40多道题,但是没学过操作系统,就都跳过了,除了一道线程通信和一道python的题,基本都是面经,. From 1point 3acres bbs
但是从来没有准备过系统设计的题,所以凉了。
还有一些图,没能贴上来。再链接里。
链接:https://pan.baidu.com/s/1ApQR4VepPIazsZjG0Uqo-w
提取码:ybel -baidu 1point3acres
复制这段内容后打开百度网盘手机App,操作更方便哦
1. memory leak
a. memory leak is a type of resource leak that computer manages the resources incorrectly. For example memory which is no longer needed is not released. and programmer find there is something in the memory which should have been empty.
2. stack overflow
a. it is a situation that the program wants to use more memory space than the stack can provide.
b. examples
i. recursion for too many times or the local variables are too large
3. compiled language/interpreted language
a. compiled language need to transform the codes to assembly language before running, while interpreted language can produce directly from the codes while running.--
b. compiled c++ pascal
c. interpreted: javascript vb python
4. sort
a. average best worst space algorithm
bubble n^2 n n^2 o(1) exchange all the inorder pairs
selection find the smallest one
insertion find the correct place and insert it
quick
b. quick sort
i. divide
1) find a pivot element
2) partition and rearrangement, the elements before the pivot is less than the pivot and the elements after the pivot is greater than pivot.google и
ii. conquer:
1) Sort the subarrays and recursively with quicksort.
iii. combine:
1) no combine
c. merge sort
i. If the list has only one element, return the list and terminate. (Base case)
ii. Split the list into two halves that are as equal in length as possible. (Divide)
iii. Using recursion, sort both lists using mergesort. (Conquer)
iv. Merge the two sorted lists and return the result. (Combine)
1) traverse
d. heap sort
i. heap
1) partial order tree
1) father is greater than children
ii. heap sort
heapSort(E,n)
Construct H from E, the set of n elements to be sorted;
for (i=n;i31;i--)
curMax = getMax(H);
deleteMax(H);
fix the heap
E[i] = curMax
1) heap construction
a) void constructHeap(H)
if (H is not a leaf)
constructHeap(left subtree of H);
constructHeap(right subtree of H);
Element K=root(H);
fixHeap(H,K) put k into a right place in a hierachial tree
return
5. 讲一下virtual function
a. signal
6. Do you know design pattern? do you know Singleton?
a. a kind of pattern to solve some general problems
b. singleton: only one instance of a class, and the instance can be accessed globally
i. example:
ii. Windows 是多进程多线程的,在操作一个文件的时候,就不可避免地出现多个进程或线程同时操作一个文件的现象,所以所有文件的处理必须通过唯一的实例来进行。
iii. 实现:
iv. http://www.runoob.com/design-pattern/singleton-pattern.html
7. Do you use template function?. 1point3acres
a. Function templates are special functions that can operate with generic types. This allows us to create a function template whose functionality can be adapted to more than one type or class without repeating the entire code for each type.
b. 通用指针 模板函数
8. Do you know sort algorithms? introduce quick sort?Do you know merging sort? Their time complexity?
9. Do you know the keyword final in c++
a. Specifies that a virtual function cannot be overridden in a derived class or that a class cannot be inherited from.
b. override-baidu 1point3acres
. 1point3acres.com
10. 函数传值和传引用的区别. 1point 3acres
a. address is passed,the variables can be changed in the function
11. struct 和 class 的区别
a. for c : struct cannot contain a function
b. for c++:
i. struct:the default variables are public
ii. class:default variable are private
12. 怎么理解static变量?
a. When we declare a member of a class as static it means no matter how many objects of the class are created, there is only one copy of the static member.. 1point 3 acres
b. A static member is shared by all objects of the class.
13. static变量和global变量的区别
a. if there are many files in a project ,global variables can be accessed in any files, but static variables can only be accessed within the same file.
14. 继承
a. https://www.tutorialspoint.com/cplusplus/cpp_inheritance.htm
b. new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.
15. Overloading (Operator and Function)
a. function overloading
b. types and/or the number of arguments in the argument list. You cannot overload function declarations that differ only by return type.
c. rewrite the function
16. 多态(Polymorphism)-baidu 1point3acres
a. poly while compiling
i. overloading
b. poly while running
i. dynamic binding later binding
• 编译时多态性:通过函数重载和操作符重载来实现,这也称为静态绑定或早期绑定。
• 运行时多态性:它通过方法覆盖来实现,也称为动态绑定或后期绑定。
Polymorphism is when you can treat anobject as a generic version of something, but when you access it, the codedetermines which exact type it is and calls the associated code
polymorphism is the ability (in programming)to present the same interface for differing underlying forms (data types).
17. virtual function
a. Defining in a base class a virtual function, with another version in a derived class, virtual function will signal to the compiler that we don't want static linkage for this function. this allow a later linkage and dynamic linkage。
b. pure function:without actual meaning =0
18. virtual inheritage
a. Virtual inheritance is a C++ technique that ensures only one copy of a base class's member variables are inherited by grandchild derived classes.
b. Without virtual inheritance, if classes A and B both inherit from class D, and class C inherits from classes A and B, then class C will contain two copies of D's member variables: one via A, and one via B. These will be accessible independently, using scope resolution.
19. Do you know resize() function of vector?. check 1point3acres for more.
a. resize the vector with parameter k , if the present size of the vector is greater than k, cut the redundent ones
b. reverse is prepare some memory space for the vector it is about the capacity. .и
20. 引用和指针的区别
a. pointer is an object with its value and address, its value is the address of another variable.
b. reference is another name for an object
c. Pointer:1.can bere-assign many times;2.can point to null;3.has its own memory address and sizeon stack;4.can have pointer to pointers to pointers offering extra levels ofindirection
d. Reference;1.can’t bere-seated after binding;2.always refer to an object;3.share the same memoryspace with origin object;4.only one level indirection
21. 简单讲一下list
a. 双向链表:doubly linked list
b. there is no need to prepare the memory first
c. easy add and delete
d. cannot locate with index
22. 讲一下smart pointer
a. Using smart pointers, we can make pointers to work in way that we don’t need to explicitly call delete.
b. Since destructor is automatically called when an object goes out of scope, the dynamically allocated memory would automatically deleted (or reference count can be decremented).
23. what is binary search tree?
. ----
24. Do you know c++ 11?
a. lambda expression anonymous function
i. define some small function locally
b. auto keyword
i. compiler will identify the type of the variables at the point of declaration ..
c. null pointer
i. rather than constant 0
d. override final
i. override :check if the function has been in the base class
ii. final: cannot been inheritted
25. 优先级序列 和堆的区别?
a. heap can be used to virualize the priority queue-baidu 1point3acres
26. stack vs heap
1. Stack:static;compile time;LIFO order;memorymanagement automatically;access fast;. 1point3acres.com
Know how much data before compile,not toomuch;
2. Heap:dynamic;run time;slower;size Islimited on virtual memory;allocat and free at any time;
27. thread vs process
1. Thread:run in shared memory space;easier tocreate and terminate;lightweight;faster task-switching;data sharing with otherthread;care synchronization overhead of shared data;
2. Process:separate memory space;independentof each other;consist of mutipule thread
28. linux & windows
操作系统 形态 说明
WINDOWS 商业产品 微软公司1983年开始推出的一套商业操作系统。
LINUX 一个内核 芬兰的李纳斯·托沃兹( Linus Torvalds) 1991 年上大学时发布的, 他对当时流行的教学系统Minix (Unix的一个版本)的很多特点很不满意, 于是决定自己写一个合乎自己要求的操作系统, 并把这个内核放到了Internet 上, 供大家修改。后来经过众多世界顶尖的软件工程师的不断修改和完善。
MAC OS 专属系统 是苹果公司基于FreeBSD操作系统的改造
29. index
1. this is a kind of specific column in the table, pointing to the row in the table, allowing faster retreavel of database
. 2. hash: . check 1point3acres for more.
i. much more efficient, not need to search from the root to the target
ii. it compares the hash value, so hash index can only satisfy the equality but not in equality.
3. b-tree
i. B-tree, allows logarithmic selections,insertions, and deletions in the worst case scenario. And unlike hash indexesit stores the data in an ordered way, allowing for faster row retrieval whenthe selection conditions include things like inequalities or prefixes.
30. gatbage collection
31. interface vs abstract method
1. abstract class:
i. a class without enough information to describe a specific object
2. abstract method:
i. methods declared in the abstract class
3. interface:
i. an abstract type, it is a set of abstract methods , a class can heritage the interface to heritage the abstract methods.
4. differences
i. Abstract method: constants,members,method stubs,defined method;
1) any visibility;
2) can be inheritaged with keyword extends without implementing all the classes.
ii. Interface:const,method stubs;
1) public;same visibility;
2) a derivative class can heritage multiple interfaces but only one abstract class in JAVA
32. primary key foreign key区别
1. key: constrain(standard and make sure the Structural integrity) & index
2. primary key:
i. eg: the unique one student number
ii. constraint the only one to denote every records;
iii. the unique one for a table ;
iv. not null
3. foreign. From 1point 3acres bbs
i. constraint. Waral dи,
ii. the foreign keys are from another table
iii. duplicated;null;one or more in a table;
33. SQL join
1. INNER JOIN: Returns all rows when there isat least one match in BOTH tables
2. LEFT JOIN: Return all rows from the lefttable, and the matched rows from the right table.
3. RIGHT JOIN: Return all rows from the righttable, and the matched rows from the left table
4. FULL JOIN: Return all rows when there is amatch in ONE of the tables ..
fill the blank with null-baidu 1point3acres
34. copy constructor & assignment operator
.-- 1. create copy assign to create ..
2. copy constructor :construct a objective with another object of the class, there will be a default copy constructor and assignment operator. 1point 3 acres
i. pass the parameter using reference, or there will be infinite recursion
3. copy constructor :Initialize a previous un-initialized object with the data of otherexist object;
4. assignment operator: replace the data of a previously initialized object with some otherobject's data
35. static method
1. it can be called on a class and does not require the class to be instantiated.
36. what's thedifference between TCP and UDP?
TCP UDP.--
是否连接 面向连接 面向非连接
connection-oriented connectionless
传输可靠性 可靠的 不可靠的
ack
streaming datagram
in order not in order. check 1point3acres for more.
Reliability: TCP is connection-orientedprotocol.
Reliability: UDP is connectionlessprotocol.. 1point3acres
. .и
Ordered: don’t have to worry about dataarriving in the wrong order.
Ordered: If you send two messages out, youdon’t know what order they’ll arrive in i.e. no ordered
. .и
Heavyweight:.
Lightweight: No ordering of messages, notracking connections,-baidu 1point3acres
Streaming: Data is read as a “stream,” withnothing distinguishing where one packet ends and Datagrams: Packets are sentindividually and are guaranteed to be whole if they arrive. One packet
..
37. exception and error
1. Errors tend to signal the end of your application as you know it. It typically cannot be recovered from and should cause your VM to exit. this cannot be recovered or prevented only by the program itself
i. Example: OutOfMemoryError - Not much you can do as your program can no longer run.
2. Exceptions are often recoverable and evenwhen not, they generally just mean an attempted operation failed, but yourprogram can still carry on.. ----
i. Example: IllegalArgumentException - Passed invalid data to a method so that method call failed, but itdoes not affect future operations.
38. starvation vs deadlock
1. 这道题是比较经典的一个题目,也看的比较多了,我回答是死锁是因为临界资源调度出现问题,导致系统出现环形结构,造成系统崩溃。而饥饿是因为调度算法的问题,导致有进程一直无法取得资源。本质上区别就是死锁是破坏性的,而饥饿只是某些进程始终无法取得资源。
39. privateconstructor:
1. The constructor can only be accessed from static method inside the class itself. Singleton can also belong to this category.
2. A utility class, that only contains static methods.. 1point3acres
40. Protected constructor
1. can only be accessed within the derivative classes
When a class is (intended as) an abstract class, a protected constructor is exactly right. In that situation you don't want objects to be instantiated from the class but only use it to inherit from.
There are other uses cases, like when acertain set of construction parameters should be limited to derived classes.
41. SQL injection. Waral dи,
submit a database SQL command that is executed by a webapplication,exposing the back-end database. A SQL injection attack can occurwhen a web applicationutilizes user-supplied data without proper validation orencoding as part of a command or query.
.--
· when data entered by users issent to the SQL interpreter as a part of a SQL query.
· Attackers provide specially crafted input data to the SQL interpreter and trick the interpreter to executeunintended commands.
1. should strictly constrain the pattern of the input of user
42. Sleep() VS wait()
. Waral dи, 1. Sleep: Thread类的静态方法,虽然休眠,但是锁并未释放,是当前线程进入停滞状态,让出cpu
2. Wait:object类的方法,进入等待池中,释放对象的锁;使用notify或notify all 唤醒等待池中的线程。Wait必须放在synchronize Blocking中,否则runtime 抛出illegalMonitorStateException。
43. HashTable &HashMap
1. inheritage different
i. hashtable-dictionary hashMap-abstractMap. 1point 3 acres
ii. Hashtable 中的方法是同步的,而HashMap中的方法在缺省情况下是非同步的。在多线程并发的环境下,可以直接使用Hashtable,但是要使用HashMap的话就要自己增加同步处理了。
iii. null key
Hashtable中,key和value都不允许出现null值。
在HashMap中,null可以作为键,这样的键只有一个;可以有一个或多个键所对应的值为null。
iv. 哈希值的使用不同,HashTable直接使用对象的hashCode。而HashMap重新计算hash值。
.
. Waral dи,
. 1point 3acres
.1point3acres
. ----
|