views:

706

answers:

2

I was preparing for technical interviews and would like to know how could I go about briefly explaining an interviewer about the approach to designing the following programs without going into unnecessary details

1. Program that lets people play tic tac toe with each other over the internet?               
2. A suitable data structure for a photo editor or text editor? Why?
3. Implementing code to operate the elevators?
4. Implementing the rendering engine of a web browser?

I could come up with the following:

  1. There are primarily 2 parts to the program. One deals with the rendering of the board display. The other is the actual engine containing methods to find the winning move, AI, game completion, etc. Then, there will be the code related to the network.

  2. A linked list of strings seems appropriate for the text editor, since the primary element is text and related manipulations. Does a linked list of objects seem right for the photo editor?

  3. This again involves a display rendering of the elevators along with resource synchronization.

  4. Don't have much clue about how to approach this one.

Are the sufficient enough? Am I missing some important details in approaching these problems.

+3  A: 

The photo editor is an interesting one.

You need to consider the requirements of a photo editor:

  • rapid selection, decode and display of part of a multi-megabyte data structure (16M?+)
  • responsive display of user operation of paint tools - the brush should not lag, even if brushing over the whole image
  • can you efficiently operate paint tools when zoomed out?
  • save to common formats efficiently
  • consider impact of all this data on CPU cache and bandwidth - note that accessing main memory can take 100s of times longer than accessing cache. How do you make most operations happen in the cache?
  • what common features do existing editors have - undo, layers, effects, real-time blend modes, gamma conversion at the final display pass

I suggest holding multiple zoom levels with lower resolution and bit-depth (like mipmaps) in memory at once to allow efficient operation at different zoom levels, encoding changes as patches to the base image, not directly editing the base (i.e. layer every change separately). The patches could be encoded as a grid with only painted squares having memory allocated to them. Edits can be encoded as actions (e.g. tool, mouse down, movement, mouse up) before they are rendered into pixels - this allows a cheap paint to be done as patches at the current mipmap level and quickly displayed, while a background thread creates patches at the other mipmap levels.

Alex Brown
+1  A: 

Hi

Elevator scheduling is achieved by SCAN algorithm. Its also used for disk scheduling.

I hope this helps.

cheers

Andriyev
I think the question was how to have a system for two people to play against each other on the internet, not an algorithm for solving tic-tac-toe
Splat
Actually the SCAN algorithm is not really good if you have a lot of elevators (you'll end up with unnecessary stops). It's fairly more complicated, but really the usual way to go with only one elevator
Samuel Carrijo
Yes, SCAN is not good with multiple elevators. I had a chance to read on this in my Formal Methods course where we had to model an elevator and verify the model using SMV (a model checker). I came across this paper (http://www.icis.ntu.edu.sg/scs-ijit/1203/1203_10.pdf) which some what helps in multi-elevator situations.
Andriyev
I agree with Splat, the first question as stated is about people playing against each other, not against a computer. Rule #1 in an interview - answer the question that was asked. :-) I've interviewed people who have made this mistake, and from that point on I wonder if the person is going to misunderstand everything someone asks them to do and waste a lot of time writing code that does things no one wants.
Neil
My bad there. I considered putting up stuff like Alpha-Beta pruning after reading the line "Am I missing some important details in approaching these problems." Though the first half (removed now) of my response was off target.
Andriyev