5 ms·
Well, this is interesting but not surprising. I have conducted hundreds of interviews and I am astonished at low level of knowledge or understanding of some th
by lmilcin 6y ago
Well, this is interesting but not surprising.
I have conducted hundreds of interviews and I am astonished at low level of knowledge or understanding of some things that are completely obvious to me.
I don't typically ask questions outside typical tech topics so that I don't bias against people who did not go to CS course.
Some of questions that I almost never get correct answer to but feel completely obvious to me:
- Under what conditions linked lists are faster than array lists (Java)?
- Why can't one process take a pointer, send it to another process to have it dereference to same data? When does this work?
- Is Java pass by reference or pass by value language? Why? (I ask this senior Java developers and never got correct answer)
- Can more than one processes listen on the same port on the same interface and IP address?
- What does `volatile` keyword do in Java, exactly?
- Explain what is a breakpoint and how it stops the program.
I would assume at least some of the things should be familiar to somebody who spent years programming in the given language.
- rcconf 6y agoI'll try to answer these, just for fun, even though I am not doing an interview. I have not Googled anything, so if things are horribly wrong, let me know. - I have no idea, but I could try answering this through thinking through the problem. Generally a linked list has a pointer to from one item to the other. An array list I assume uses arrays for holding the items using indexes. What are the available operations generally for a data structure? Search - Search would be O(1) in array list and O(N) in linked list, can't be this. Insert - Insert in a linked list is actually quite quick if you have the node since you could just move the pointers. For an array list, you would have to shift everything over. I think this is the answer. Remove - Same deal as Insert. Did I get this right? - Because processes cannot access each others memory, the OS prevents from happening. A pointer is a pointer to an address in memory so you generally cannot do this. In terms of where would this work, umm, maybe in an old OS that didn't have the protection, or perhaps dynamically linking libs? - Neither, it's pass by copy from what I recall. Or something of the sorts. Maybe call by sharing? I would just explain how it works since that's easier, generally everything in Java is copied, so it's pass by value in the traditional sense. But when you think pass by value, are objects copied? The answer is no, objects copy their pointer instead in Java. So when you modify a passed object, it does modify the underlying data in that object, but you can never re-assign the object. - Nope, I don't think so. From what I recall, I've always had programs fail to run if I use the same IP + Port + Interface. You can do virtual hosts in Apache/Nginx tho where you can handle multiple different domains on the same port. - Volatile is generally used when working with threading. I cannot fully recall what it is, but it's required in thread safety. I would generally use thread safety operations and data structures instead here, but I do recall having to use volatile a few times. - I don't know how a breakpoint works exactly, but it's a marker placed in code and when a debugger runs into it, it stops the process. I assume since the Java code gets converted to byte code for the JVM to process, it would be a byte code added between the lines where the breakpoint lives. Note: haven't used Java in 4 years.
- fiddlerwoaroof 6y agoI don’t know if this is true for linked-lists/arrays: but it is sometimes true that an O(1) algorithm is slower than an O(n) one, for small ns (hash-table vs. a linear search of a list of pairs is one example of this). For almost all of these questions I’d be concerned about unusual edge cases: like, I believe it’s possible for two processes to share the same IP/Port on Linux, if you set the right socket options.
- fiddlerwoaroof 6y agoYeah, I think SO_REUSEPORT allows that: https://superuser.com/a/1267230 https://superuser.com/a/1267230
- lmilcin 6y agoThanks for this one, I forgot about it. This is relatively new addition, in times past the only way was to listen on separate protocols (one process on TCP and one on UDP, for example).
- SAI_Peregrinus 6y agoIt's also OS (well, network stack) dependent. The most general answer is that it's possible, but you might need a custom network stack to do it.
- marcosdumay 6y ago> In terms of where would this work, umm, maybe in an old OS that didn't have the protection, or perhaps dynamically linking libs? Modern OSes all have shared memory functionality. And dynamically linked libs are a complicated thing, so it's both yes and no there, at least on some OSes, while on others it's a clear no :) > Neither, it's pass by copy from what I recall. Pass by copy is the same thing as pass by value. In C and Pascal the definitions are pretty clear, but people insist on using them on other languages where they don't make sense. Let's extend it a bit: is Haskell a pass by value or pass by reference language? What about Prolog? About breakpoints, they usually have hardware support. But since Java runs on a virtual machine, I have no idea it the buck stops at the JVM or if they use the hardware interface.
- cupofgreentea 6y ago1) When adding the 2^n'th element. Linked List would just append to the tail O(1) time where as ArrayList would double the size copy half the array and then add it doing O(N) amount of work. Still though amortized analysis of insertions in array list is O(1) because rarely do we double the size of array. (30 times required to double the array for insertion of a billion elements).