其实都是很简单的data structure的应用。给你一个题吧 by ice (甲基苯丙胺) at 2006.3.2 00:24 [#746553@9]
one singly linked list has two heads (h1 and h2)
the linked list is structured like:
1(h1)->2->3->4->5->6.......->n
(n+1)(h2)->(n+2)->...->(n+m)->i (i<n)
given h1 and h2, return the merged node's address.
for example swap number a and b in place. like prototype: void swap(int a, int b). IN PLACE means no extra memory should be used.
-maple2000(等待着夏天);
2006-3-4(#2819008@0)
照这么说这题就没法做了,不允许使用额外变量。没有临时指针,比都没法比。不过我误会你了,看来你说"reverse a linked list"是另一道题。
-holdon(again);
2006-3-4(#2819014@0)
这样吧,你先实现swap(a,b) in place.介个比较好整一点。算法肯定有。
-maple2000(等待着夏天);
2006-3-4(#2819020@0)
这我初中就会了.
-holdon(again);
2006-3-4(#2819157@0)
please give the algorithm
-maple2000(等待着夏天);
2006-3-4(#2819553@0)
时间太久,我忘了行吗?
-holdon(again);
2006-3-4(#2819691@0)
It's really a good excuse to tell the interviewer.
-ice(甲基苯丙胺);
2006-3-4(#2819772@0)
what's the output? all possible two letters or you just need a random tow letters combination.
-ice(甲基苯丙胺);
2006-3-5(#2819865@0)
all two letters combinations, like ABCD => AB AC AD BC BD CD
-maple2000(等待着夏天);
2006-3-5(#2819873@0)
If need to know how many combinations ------>n! / x!*(n-x)!
-simonqu(后悔);
2006-3-5(#2819897@0)
not the number of combinations but the coms themself
-maple2000(等待着夏天);
2006-3-5(#2819908@0)
Easy way is something like bubble sort. Good way is something like merge sort. Instead of comparation, simply print them out. No difference
-simonqu(后悔);
2006-3-5(#2819945@0)
There should have some condition check
-simonqu(后悔);
2006-3-5(#2819994@0)
The basic idea is look forward 2 positions, have one pointer for current node and a pointer to the reserve node
-simonqu(后悔);
2006-3-5(#2819995@0)
For recursive way. Break the linked list form the middle like the merge sort; Instead of merge them together, relink them in a reevise way
-simonqu(后悔);
2006-3-5(#2819999@0)
All the questions here are real interview questions.
-maple2000(等待着夏天);
2006-3-4(#2818668@0)
write code to copy a binary search tree.
-maple2000(等待着夏天);
2006-3-4(#2818670@0)
It depends on sallow or deep copy. If it's sallow copy, you only need copy the pointer. Copying a collection in both java and C++ are sollow copy. If it's a deep copy, it depends on what language you're choosing
-simonqu(后悔);
2006-3-5(#2819956@0)
think of serializing and deserializing it. so it's deep copy.
-maple2000(等待着夏天);
2006-3-5(#2819959@0)
A language using array to implement BST, you need calculate the size of the array first then copy the whole chunk of the array. If use linked list, you need do a traverse to copy the linked list
-simonqu(后悔);
2006-3-5(#2819960@0)
When I say copy the linked list, I mean copy it into an array
-simonqu(后悔);
2006-3-5(#2819964@0)
implement a function that prints all possible ordering of the chars in a string.
-maple2000(等待着夏天);
2006-3-4(#2818683@0)
similiar to merge sort or quick sort. the Big O time should be nlg(n)
-simonqu(后悔);
2006-3-5(#2819965@0)
interesting idea
-maple2000(等待着夏天);
2006-3-5(#2819969@0)
implement a function that prints all possible combinations of the chars in a string.
-maple2000(等待着夏天);
2006-3-4(#2818685@0)
注意:每个问题最长时间约一小时。有感到简单的DX,如果你还在小公司的话,应该挑战MS, Google
-maple2000(等待着夏天);
2006-3-4(#2818720@0)
These're practical problems. The real challenge is algorithm. You can always refine your design, but without talent you can't solve the algorithm problem. I personally find difficulties on algorithm
-simonqu(后悔);
2006-3-5(#2819927@0)
design a thread pool
-maple2000(等待着夏天);
2006-3-4(#2818945@0)
This one is not easy. It's a OS related problem. It really test you how to implemet how to write a Semaphor and scheduler
-simonqu(后悔);
2006-3-5(#2819899@0)
design a garbage collector
-maple2000(等待着夏天);
2006-3-4(#2818947@0)
step1: Create a deamon which gonna scan the objects on the heap and free any objects without referencing( the refernce counter is 0 )
-simonqu(后悔);
2006-3-5(#2819877@0)
step 2 create a base class with a date member, reference counter and initially the counter will be one.
-simonqu(后悔);
2006-3-5(#2819881@0)
If you have the change seeing some sections of open source code, this is the most common way to clean the memory
-simonqu(后悔);
2006-3-5(#2819882@0)
step 3, whenever you create a new class, extends the base class we defined in step2
-simonqu(后悔);
2006-3-5(#2819890@0)
step 4
Anytime any object is referenced, increment the counter. Anytime any object is released, decrease the counter.
-simonqu(后悔);
2006-3-5(#2819892@0)
great! new JVM uses different scheme. instead of reference counter, tracing collector is in favor
-maple2000(等待着夏天);
2006-3-5(#2819902@0)
Java make it more complicated. There's difference between soft delete and hard delete. Anyway, it just another way to manage memory
-simonqu(后悔);
2006-3-5(#2819919@0)
any good memory management articles or books to recommand?
-maple2000(等待着夏天);
2006-3-5(#2819923@0)
Sorry, I only collect thoes information piece by piece. I do learn a lot from C Programming
-simonqu(后悔);
2006-3-5(#2819935@0)
It also can be implemented by event driven in Java or by call back in C++. Issue an event or triger the call back when the object finds its counter becoming zero
-simonqu(后悔);
2006-3-5(#2819906@0)
design a memory management scheme
-maple2000(等待着夏天);
2006-3-4(#2818950@0)
need more details
-simonqu(后悔);
2006-3-5(#2819900@0)
C++ way or Java way. Interviewer just want to know how you are familiar with any of them or even better all of them
-maple2000(等待着夏天);
2006-3-5(#2819928@0)
If you really want to know it, it's more easy to be understand through assembly language. Have a look how the object created on heap, how a function is called and how the parameters are passed to the function
-simonqu(后悔);
2006-3-5(#2819940@0)
After you familiar thoes problems you can do futher research on how compiler( C or C++) or interpeter(java) works
-simonqu(后悔);
2006-3-5(#2819941@0)
After that you need focus on How OS works on memory allocation, how paging work and how context switch works. Memory management is really not only related to languages
-simonqu(后悔);
2006-3-5(#2819943@0)
design a can-juice vendor machine and test it
-maple2000(等待着夏天);
2006-3-4(#2818958@0)
more details please
-simonqu(后悔);
2006-3-5(#2820000@0)
design an elevator control system and write test cases for it
-maple2000(等待着夏天);
2006-3-4(#2818963@0)
There's an exact example with UML Diagram in Deitel and Deitel. No need snoop around, simply copy it
-simonqu(后悔);
2006-3-5(#2819898@0)
Pick a book like C++ How to program or Java How to program. They're pretty books. You need one of them on hand
http://www.deitel.com/
-simonqu(后悔);
2006-3-5(#2819912@0)
Jig saw puzzle. What are the data structures? Assume you have some method which can tell you if two pieces fit together. How would you solve the puzzle, minimizing the number of times you have to call that function?
-maple2000(等待着夏天);
2006-3-5(#2819961@0)
Where did you collect such a big number questions. It makes me fell like a final exam. The above questions are really good.
-simonqu(后悔);
2006-3-5(#2819973@0)
check ur PM
-maple2000(等待着夏天);
2006-3-5(#2819974@0)
I alway tell people we're computer scientist not a damn programmer. Don't follow the trend but do some study on algorithm and OS. They're the core of CS. Sigh!!! No body believes me
-simonqu(后悔);
2006-3-5(#2819977@0)