Interview Question


Country: United States




Comment hidden because of low score. Click to expand.
1
of 1 vote

Stack

- sneha February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

I think it is linked list.

- Anonymous February 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is stack because even the process execution uses stack to execute the functions which are present in the program. For example, while debugging the process using gdb, few commands are stack trace... .

- srik545 March 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

LinkedList, because it's ordered container object.

- Igory February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think it is stack

- u2005k February 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

linked list

- thriveni February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think it is stack.

- Anonymous February 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Stack

- Anonymous February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think it is linked list.

- Anonymous February 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Recursion actually needs to switch/restore back the states correctly. This restoration can happen effectively through pointers as they are address-based.

Hence, linked lists are preferred.

- Sudhindra.A February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Stacks are preferred.

- Anonymous February 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Linklist

- deepesh February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Stack

- Anonymous February 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

for recursion only and only STACK

- Anonymous February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think it is linked list.

- Anonymous February 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you explain me why you need stack and with an exampl if you feel free ?

- Shrikant March 25, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I browsed through some web resources and found stack to be most successful but can't find reason behind it. Can anyone explain?

- Droid February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I didn't understand the "best". But the stack is must have datas structure for recursion.

- Anonymous February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Linkedlist is must have.

- Anonymous February 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

STACK

- PKT February 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think it is linked list.

- Anonymous February 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

stack, it is first in, last out

- USTChucat February 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi USTChucat, again I am confused: we know that certain recursive algorithms (merge sort etc) work on array, and of course there are other algorithms (tree walker etc) using stacks. So what exactly does "best" mean here, and what's your reason to pick stack over, say, array? Thanks.

- Chih.Chiu.19 February 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I thought it was asking us which kind of data structure was best fit for implementing recursion in compilers, rather than which kind of data structure should be used in implementing recursion algorithm.

- USTChucat February 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks.

- Chih.Chiu.19 February 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Of those options, only the queue is fundamentally wrong.
However, none of the other options are particularly good.
A better option would be a tree, as the recursion might require many evaluations at each level, and a tree will be more flexible for that, and also allow parallelisation if the problem is suitable..

As this is an interview question, going beyond the presented options is probably not a bad thing.

- dcrafti February 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

LOL.

- Anonymous February 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Suppose we have three functions in recursion. For example. f1,f2, and f3.
f1 {
f2{
f3{
}
}
}

So complier should store f1 , f2 in such way that our program correctly jumb back to f2 after executing f3. And we know STACK works as "Last in First out" so f3 goes last and comes first according to concept. This what I can suggest here.

- Ricky February 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It is stack because a LIFO data structure.

- pra February 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think its is link list becoz link list have next & previous node to track the data recursively.

- kalpana February 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think its is link list becoz link list have next & previous node to track the data recursively.

- kalpana February 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Stack for sure

- Abhinav March 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Stacks are more suitable for recursion..

- kri1311 March 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

jnfgkjnf

- Anonymous March 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hi ,

ans : linked list ,because we can insert or delete etc, can do at any address location. in case of array ,stack and queue . we have to traverse , it takes more time.

- kbkdec15 April 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hi ,

ans : linked list ,because we can insert or delete etc, can do at any address location. in case of array ,stack and queue . we have to traverse , it takes more time.

- kbkdec15 April 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hi ,

ans : linked list ,because we can insert or delete etc, can do at any address location. in case of array ,stack and queue . we have to traverse , it takes more time.

- kbkdec15 April 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hi ,

ans : linked list ,because we can insert or delete etc, can do at any address location. in case of array ,stack and queue . we have to traverse , it takes more time.

- kbkdec15 April 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the concept of stack is necessary,but the successful implementation of the stack using linked list can make it much better through the top and head pointers the push,pop,peek and empty can be provided in O(1) that to with pointer access it is made fast.So considering recursion the idea of stack is important but the implementation is made via the list for maintaining the states.

- Anonymous August 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi, Stack Prints LIFO order. And recursion also works in the same principle. So, only stack best suits for it.Actually Linked list, uses the concept of recursion, doesn't mean the best example for recursion.

- Prashanth August 29, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More