algorithm - Efficient data structures for data matching -


what efficient data structures matching data? example, suppose presented follow scenario:

<time available> <buy or sell> <company name> <buy or sell price> <amount buy or sell> 

so file may contain:

0 sell yahoo $100 #1 2 sell yahoo $14  #1 2 sell yahoo $28  #1 .. 95 other yahoo sells <$125 , amount #1 3 sell yahoo $17  #1 5 sell yahoo $33  #1 9 buy yahoo  $125 #100 

is possible match last buy previous 100 sells in o(n) time, n = 100 if buy matched lowest selling price corresponding company wants buy (or 1 comes first in case of tie)?

i know naive solution sort list , go in order, takes longer o(n) time. efficient data structures handling problem , similar ones it?

try using hash map company name heap of sell orders, ranked price. insertion of sell order o(log n) , buy order becomes constant if buy doesn't use sell order, or o(log n) if (your problem statement doesn't specify)


Comments

Popular posts from this blog

Receive udp packets in android gstreamer -

php - Extract Text from HTTP referer -

matplotlib - PYTHON: Annotate boxes disapear dependant on range -