wu :: forums
« wu :: forums - MS Interview Question »

Welcome, Guest. Please Login or Register.
Jan 9th, 2025, 7:35am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Grimbal, SMQ, Icarus, Eigenray, towr, william wu, ThudnBlunder)
   MS Interview Question
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: MS Interview Question  (Read 961 times)
minniekp
Newbie
*





   


Gender: female
Posts: 3
MS Interview Question  
« on: Aug 16th, 2007, 1:24am »
Quote Quote Modify Modify


This was asked in a Microsoft Phone in interview for a SDE role.
 
How do you test a stack??
 
Does anyone know how to do it ?  
The answer I gave was writing test cases to push elements and pop elements from a stack and printing them out.
 
Thanks
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: MS Interview Question  
« Reply #1 on: Aug 16th, 2007, 3:24am »
Quote Quote Modify Modify

There's a number of other things you could test for. For example the behaviour when you try to pop elements from an empty stack. Or when you try to push elements on a full stack (or if there even is a limit).
You could also test its performance, how fast are pop and push operation. And someone might be interesting in which direction in memory the stack grows (or if it's even in a definite direction; a stack implemented as list wouldn't necessarily gro in a set direction).
Corrupting the stack, and seeing if it can somewhat recover might also be interesting, depending on what the stack is for.
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: MS Interview Question  
« Reply #2 on: Aug 16th, 2007, 6:47am »
Quote Quote Modify Modify

One point is that you cannot test a stack (or anything) if you don't have a specification that tells how it is supposed to work.  How should it react if you pop() from an empty stack and how should it report a stack overflow?
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: MS Interview Question  
« Reply #3 on: Aug 16th, 2007, 7:01am »
Quote Quote Modify Modify

Maybe the goal of the test is to figure out what the specification might be Wink
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
minniekp
Newbie
*





   


Gender: female
Posts: 3
Re: MS Interview Question  
« Reply #4 on: Aug 16th, 2007, 11:48pm »
Quote Quote Modify Modify

Below is a link explaining how to test for stack overflow. Its quite complicated and not sure if this kind of explnation is an appropriate answer.
 
http://www.owasp.org/index.php/Testing_for_Stack_Overflow
IP Logged
TenaliRaman
Uberpuzzler
*****



I am no special. I am only passionately curious.

   


Gender: male
Posts: 1001
Re: MS Interview Question  
« Reply #5 on: Aug 17th, 2007, 1:30am »
Quote Quote Modify Modify

on Aug 16th, 2007, 11:48pm, minniekp wrote:
Below is a link explaining how to test for stack overflow. Its quite complicated and not sure if this kind of explnation is an appropriate answer.
 
http://www.owasp.org/index.php/Testing_for_Stack_Overflow

You may want to read the link again carefully. What it tests for and what Grimbal asked you earlier are two different things.
 
-- AI
IP Logged

Self discovery comes when a man measures himself against an obstacle - Antoine de Saint Exupery
GowriKumar
Junior Member
**





   
WWW Email

Gender: male
Posts: 55
Re: MS Interview Question  
« Reply #6 on: Aug 17th, 2007, 1:52am »
Quote Quote Modify Modify

Assuming that it is testing the "stack data structure" (and not the program stack), I would probably say the following things:
 
Say that the operations allowed on stack are:
push  
pop
top  
 
A few scenarios to look at would be:
- How does the stack handle push on a full stack
- pop on an empty stack
- top shouldn't remove element from the stack
  (calling top any number of times should return the same value)
- push and pop immediately should return the same element
- top and pop would return the same element. but pop should remove the element from the stack.  
- take a string push all the characters in the string and now pop all the elements from the stack into a new string. the new string must be reverse of the original string.
- push and pop ideally should be constant time operations (they shouldn't be dependant on the number of elements on the stack). If the stack is implemented as an array with the dynamic resizing probably there might be a performance bottle neck at some place.
- assuming the stack supports more than 1 million entries, push 1 million entries into the stack and pop all of them (and now see if there is any leak in the memory)
 
 
Regards,
Gowri Kumar
http://www.gowrikumar.com
IP Logged

www.gowrikumar.com
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board