Lost Password?


Go Back   CodeCall Programming Forum > Software Development > General Programming

General Programming Non language specific, Assembly, Linux/Unix, Mac and anything not covered in other topics. Talk about Programming Theory here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-03-2008, 02:33 PM
janemayers janemayers is offline
Newbie
 
Join Date: Mar 2008
Posts: 2
Rep Power: 0
janemayers is on a distinguished road
Default A job interview riddle I couldn't answer

I guess it won't help me now, but I'll appreciate your thoughts anyway.

You are given an array with n actors, each has a weight and an age.

You should build a data structure that has only one function: for any two real numbers i,j you should be able to return the youngest actor in this range of heights (if exists).

You can take as much time as you want (finite...) to build the data structure and you may assume that no changes will be made after initialization.

Any ideas?

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-03-2008, 03:54 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,278
Last Blog:
wxWidgets is NOT code ...
Rep Power: 36
WingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to all
Default

I'm guessing height = weight. There is also some sort of unique identifier: name, for each actor.

I would have a class containing array/vector of name, age, height, and a member function that loops through the array once, using local variables name/age updating name/age only if the current height is in the range and the age is less than the currently found age.

What language was this for?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-03-2008, 04:27 PM
janemayers janemayers is offline
Newbie
 
Join Date: Mar 2008
Posts: 2
Rep Power: 0
janemayers is on a distinguished road
Default

I'm sorry, I missed the most important part...
The query should run in O(1) time worst-case.
And, yes... height = weight (:
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-04-2008, 11:38 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,278
Last Blog:
wxWidgets is NOT code ...
Rep Power: 36
WingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to all
Default

O(1) makes that a much nastier problem. I think I see how to get it in O(ln(x)). This may have been a problem where the problem is not possible, but the goal was to see how you approach it.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-04-2008, 02:22 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

When you say the data structure has only one function, does that mean it can only have one function - to just search? Or the structures only purpose is to return the youngest actor + age?

If you can have a sorting function, you can sort the actors in a way such that their ages are ascending [the actor at the 0-th position is the youngest and the actor at the nth position is the oldest] In which case when you do a search(i, j) - if i < j the actor at the i-th position in the array will always be the youngest, if j < i the actor in the j-th position is the youngest. [No searching needed as you use the constant time reference of the array O(1)]. However, if you can't sort them prior to searching, I don't believe the problem is possible.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall

Last edited by John; 03-04-2008 at 02:27 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 03-05-2008, 02:35 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,278
Last Blog:
wxWidgets is NOT code ...
Rep Power: 36
WingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to all
Default

The function could be called recursively. I'm thinking of a tree, with a select function that traces down the nodes recursively.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Interview - Jordan xXHalfSliceXx Member Interviews 10 04-25-2008 11:53 AM
Interview - TcM xXHalfSliceXx Member Interviews 20 04-22-2008 02:50 PM
need an answer Chinmoy General Programming 3 02-20-2008 12:11 PM


All times are GMT -5. The time now is 06:34 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads