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

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -