Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Some questions can be answered easily by using specific language library. For example Java has Set, Maps, and List. Is it possible to answer those coding questions during interview by using these library or should we go more with a traditional down to earth approach, making it a C- kind of answer?

share|improve this question
    
Technically, a data structure is a library, but, since every serious languages will come with a bunch of good core data structures, to me 'library' tends to mean something else. –  Job Jun 20 '11 at 2:27
3  
I'd definitely learn to use the term 'library' correctly. You're unlikely to do well in interviews if you can't even do that. –  Tom Anderson Jun 20 '11 at 11:24
add comment

7 Answers

I think that the best solution is to offer to answer with both!

Start off with "Unless there is a compelling reason not to, I would use the blah function of the blat library, but if that were not appropriate for some reason, I would consider implementing from scratch. Would you like me to walk through the algorithm? "

share|improve this answer
2  
+1. It demonstrates that you understand the dangers of not-invented-here syndrome and reinventing the wheel, a good grasp of the standard library and what popular third-party libraries exist, and most importantly that you have fundamental knowledge of core computer science topics and algorithms. An answer like that would be a slam dunk in any interview I've been a part of. –  Pewpewarrows Jun 20 '11 at 13:53
add comment

Typically, at least in my experience, the interviewer will specify whether you should use standard library features or not. And even if data structures like those you listed don't exist in the language's standard library, sometimes they're okay with you using them anyway and assuming they are implemented or you know how to implement them.

Usually they're either looking for a high-level concept (in which case they'll tell you to feel free to assume Set, List, etc. exist and can be used), or they'll specifically ask you to implement a Set, List, etc. from scratch, in which case it's clear that you would not use the built-in one.

And if it's not clear, ask!

share|improve this answer
add comment

It really depends on the question. If they ask you to implement a linked-list, then most likely they are testing you on your data structure skills and not in the memorization of the name of the LinkedList class from the collection framework. Also, if they are asking to solve a puzzle using a data structure, then using a class from the collection framework might be the appropriate choice. Just recognize the intention of the question and if you are not sure, then just ask.

share|improve this answer
add comment

Perhaps you should be able to, sadly you can't. I once interviewed at a large (think 10^100) company, where an interviewer wrote a list up on the whiteboard like:

1, 4, 2, 2, 12, -3

and asked me to describe how I'd sort it. I responded thus:

.sort();

because that is how I would sort that list. I know Big-O and the costs of a few sorting algorithms, but I bet someone whose job is to write a library method for sorting a list can do a much better job than I can. I argue that being able to rely on, understand and use the work of other people is much more important for 21st-century software engineering than being able to reimplement the solution to a problem that was already solved by IBM card machines before WW2.

[Of course, I wasn't offered the job...]

share|improve this answer
1  
Agreed. For a six element list on a modern computer, the only sort algorithm with a significant cost is bogosort. Just call the default sort and get on with solving real problems. –  Paul Butcher Jun 20 '11 at 11:02
add comment

If someone asks you how to do something in Java, the correct answer should always be to use the facilities built into the standard library. A former co-worked of mine who was a C developer would interview Java developers and ask them to write how to reverse a linked list on a white board, he was looking for his C specific solution, which for a developer that will only be doing Java is the incorrect solution. The correct solution in Java can only be Collections.reverse(), anything else shows a lack of familiarity with idiomatic Java.

If they are asking and expecting something other than idiomatic Java, then you need to clarify that.

share|improve this answer
add comment

I honestly don't see what use questions like this can possibly give an interviewer. I suppose if you where interviewing an intern and wanted to be sure they'd had, and hadn't flunked their data structures class, sure...but I just don't see how these questions actually answer anything useful. Being able to regurgitate a linked list implementation on request does not a programmer make, and a person who cannot is not necessarily clueless either.

On the other hand, asking about how to USE these structures can be beneficial. That's what a programmer is actually going to do anyway. If you know the basic components of your data structures then you can better gage which is useful and where. Then you can take your time making your own implementation if it's actually necessary, with the aid of unit tests and a compiler (rather than a whiteboard).

Some interviewers claim that it helps them gauge how a person thinks. They expect you to talk about your process of solving the problem out loud. I see two problems with this:

1) It's not an interesting problem. There's nothing to think about.

2) Many people are derailed when trying to "think" out loud. The amount of brain centers that have to be involved in that process are much greater than just solving the problem. Some people are helped by this, other (and they may be very good too) people end up getting too distracted. This doesn't mean they're bad communicators either, just that they're the type that sit there in silence solving the problem and THEN proposing the solution they come up with.

Anyway, rant over.. I would say that if the interviewer asked you to solve a problem that involves a data structure that you should feel free to use one. I'd go so far as to propose that you can simply make up your own data structure API and just say (this does the basic XXXX operation). If they specifically ask you to write some part of a data structure though then of course you've run into one of THOSE people and will simply have to do it.

share|improve this answer
3  
IMO, somebody who claims to be a programmer who cannot figure out how to implement a simple linked list from first principles is either poorly educated or clueless. A recruitment process needs to filter out candidates like that. –  Stephen C Jun 20 '11 at 4:18
    
@stephen: why? When is that ever going to come up in their work? Maybe if you have a strong NIH ethic then you'll need someone who can implement a linked list: I'm happy to accept that it's a solved problem and find out whether candidates can solve problems they will come across in their work. –  user4051 Jun 20 '11 at 10:05
1  
Because although they'll probably never need to write a linked list, if they can't figure out how to do that, they won't be able to figure out how to do the many other equally simple programming tasks that will make up their job. –  Tom Anderson Jun 20 '11 at 11:27
1  
@Tom Anderson: Or at least part of their job. Hopefully, there'll be more to any dev job than routine small pieces. –  Vatine Jun 20 '11 at 12:17
    
@Steven - It's still not a fair test of ability even if you are concerned that they're able to do it. Nobody actually writes code on a whiteboard. Although there are places out there I'm sure, you shouldn't be writing things like this without unit tests either. I come damn close to being able to write a lot of things straight off the cusp and get it right, but I'd still expect there to be bugs in any first attempt at a linked list. Unless that is I was able to write "(this is a list)". –  Crazy Eddie Jun 21 '11 at 4:08
show 2 more comments

I'd suggest using the library. If the interviewer really wants me to explain the nitty-gritty, he can say "how would you do it without using a library?" or "how does that library class work?".

If he takes my initial answer as an indication that i don't know my stuff, then he's clearly a numbskull, and i wouldn't want to work for him anyway!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.