Graph Data Structure Interview Questions
techiedelight.com
techiedelight.com
Does anyone really ask you to write this kind of code in interviews? They feel more like Computer Science homework questions.
Unless of course you are interviewing for a graph heavy job.
Very interesting stuff though. Love graph algorithms have coded many myself in JavaScript to prep for interviews.
edit source:
my algorithms code base test suite
For example, (11. Check if an undirected graph contains cycle or not) can easily be solved by just performing a DFS with some exit conditions.
...but have you coded any in JavaScript after the interview as part of the job? I suspect for most people the answer is no. It has always seemed strange to me to ask a topic that you're never going to encounter during your day to day work (yes, I know for some roles this isn't true).
We just don't trust the university to say that you've done the projects and sat the exams and demonstrated competence (what it's doing when it issues a degree), so each company unwraps that abstraction and runs its own projects and exams on the same material. But it is fundamentally based on college curricula.
Trusting universities is likely out of the question. Eventually, I expect the industry will create something like the Bar Exam so each candidate can pass a trusted test once upon graduation (or even without going to college), rather than creating the burden for each company to do all that grading.
Whoh!! All big IT companies ask these type of questions.. but mostly to graduate students and less experienced candidates.. but some companies might ask it to a 10 year old programmer as well..
Careful with absolutes. Although I used the word "any" in my post so I guess I shouldn't talk.
Having worked at some large tech companies I can say definitely it is not "all"
Some of these examples are 90+ lines of code which is why I ask. It would not be unrealistic with that much code that candidate will be sitting in the interview room for a half hour+ coding just one question.
Several of these are borderline trick questions or only test your ability to memorize. For example, I learned Dijkstra’s algorithm in school 10+ years ago but if you were to ask me to implement it without reading the algorithm I wouldn't be able to.
Asking graph data structure questions, sure. But here are more effective ways to know if a candidate will be a good fit than asking them to implement one of these.
Use these as your interview test questions and all you are testing is the ability for the candidate to regurgitate algorithms. None of these test creative problem solving.
Kudos to Dijkstra for nailing it down, but I think we do students a disservice by invoking his name all the time, thus making it seem scary.
Ofc, going the other way, once they realize Djikstra's algo is simple makes every other named algo less scary
And finally they (hopefully) realize such naming is a stupid thing to be scared by and disregard it entirely
I'm glad I wasn't interviewing at 10. I could program, but couldn't have handled any of these algorithms.
[0] https://github.com/poteto/hiring-without-whiteboards
related HN discussion thread[1]
In longer settings (at least an hour) and especially if I know other interviewers are asking other things I'll ask them to solve a problem and actually write code on a computer. A problem I sort of like is https://leetcode.com/problems/jump-game/#/description While I think there's a pretty simple solution that just loops over every element, what I did when I tried solving it myself was recognize it's a search problem and apply the generic search algorithm to it. (Create a frontier list with an initial starting point. Create a seen/visited set. While the list isn't empty, pop an item off. If it's what you're looking for, you're done. Mark it seen, expand its children and for each one add it to the frontier list if it hasn't already been seen.) Knowing the generic (iterative) algorithm is to me more important than the particulars of DFS/BFS (you can control which one by choice of data structure), I just want to visit all reachable nodes in my search space and it works. Of the several people I've given this to only one has solved it, and by solve I mean had any right approach even if non-compiling/terrible code. (They ended up using a BFS approach.) They also are a promotion level above mine and have had more years of experience. So maybe I need to retire it, but I still like the idea of seeing if someone can recognize a search problem and solve it because there are usually many ways of solving search problems.
Toward the end of the day, the last interviewer grilled me hard and I cracked under the pressure. It actually had been going well until the last two interviews (out of 5 or 6), in which one person asked me an unreasonably challenging problem (definitely not feasible for a whiteboard) and the other was not pleasant to interact with (almost confrontational the whole time; I felt on the defensive).
Prior to those, it was a healthy balance of reasonable challenge and solid conversation with engineers. It seemed like a cool place to work but their interviewing arrangement was brutal. I hope not to repeat that when I go looking again.
The coding test was 2 hours through a interview/code website (forgot the name). They monitored your keystrokes and report to the interviewer when open tabs on web-browser outside of their window. (I can dig and recall what that website was if others are interested).
The coding problem was basically masqueraded Union Find graph problem. I knew that after about 2 minutes of 'browsing' (as I can translate a functional ask into an existing pattern that's already solved).
http://www.geeksforgeeks.org/union-find/
Still went ahead trying to implement this by hand.. and failed. So did not get a job.
DFS Interview Questions - http://www.techiedelight.com/dfs-interview-questions/
BFS Interview Questions - http://www.techiedelight.com/bfs-interview-questions/
Added later: they fixed it. Quietly.
You can always ask these questions to reject a candidate because you don't like his body odor.