2

It’s been a while and I’m having trouble wrapping my head around a algorithm I’m try to make. There are a list of objects with different configuration which are stored in a table.

There can be m different types of Configuration for example, A, B, C etc.

And each type of configuration can have sub types

Object,Parent Configuration,Configuration,Rank
O1, A, A1, 1
O2, A, A2, 2
O3, A, A3, 3
O4, B, B1, 4
O5, B, B2, 5
O6, B, C1, 6
O7, C, C2, 7

Given a user who wants n objects having any configuration in specified configurations order by rank such that there are maxinum no of different possible object configurations, for example:

if n==3, and configuration user is interested is in A1, A2, B1, B2, C1, C2

then a normal sql query like

SELECT *
FROM   table
WHERE  configuration IN ( a1, a2, b1, b2,
                          c1, c2 )
ORDER  BY rank
LIMIT  3;  

then the output would be object O1, O2 and O3 as their rank is highest, but the optimal solution is to return objects O1, O4, O6 the highest rank object for each parent configuration,

lets say if in above example n == 4 then the output would be O1, O4, O6 and O2 as we have exhausted all different type of configuration so we are again returning top rank object.

Any help ?

Shakun
  • 57
  • 2

0 Answers0