Click here to Skip to main content
15,889,826 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: Get all groups in 4x4 matrix with width and height of power 2 Pin
Gerry Schmitz6-Apr-19 10:13
mveGerry Schmitz6-Apr-19 10:13 
AnswerRe: Get all groups in 4x4 matrix with width and height of power 2 Pin
Daniel Pfeffer6-Apr-19 21:16
professionalDaniel Pfeffer6-Apr-19 21:16 
QuestionTracking Sales and returns. Pin
Member 1420060727-Mar-19 20:22
Member 1420060727-Mar-19 20:22 
QuestionHow to find a good algorithm to fill a dense grid? Pin
Member 141732236-Mar-19 4:36
Member 141732236-Mar-19 4:36 
QuestionHow to calculate the number of labels available on a roll Pin
Member 1409963724-Feb-19 20:10
Member 1409963724-Feb-19 20:10 
GeneralRe: How to calculate the number of labels available on a roll Pin
CHill6024-Feb-19 23:52
mveCHill6024-Feb-19 23:52 
QuestionSteiner tree formulation WITHOUT set of terminals as input Pin
Member 1415897621-Feb-19 21:17
Member 1415897621-Feb-19 21:17 
QuestionNeed an efficient algorithm to solve the following problem Pin
User 1411988416-Feb-19 0:11
User 1411988416-Feb-19 0:11 
The problem is the following:

Given N containers with different sizes between 1 and N (2 <= N <= 10^5), each of them placed in a line, determine how many places can be freed if one container can be placed in another only if its size is less that the others size and they don't have any other containers between them. Multiple placings can be made, so if there are containers placed in each other, they can be placed in another container (if the bottom container size is less than the others size), a container can be placed in another group of container (if its size is less than the top container size), and a group of containers can be placed in another group of containers with similar rules.
Example: if N = 8 and the containers are placed in the following order: 1 8 2 4 3 6 7 5, then 7 places can be freed; we place 3 in 4, then 2 in 3, 6 in 7, 5 in 6, 4 in 5, 7 in 8, and 1 in 2. This way all the containers can be packed in a single group.

My idea of solving this problem is the following: calculate the minimum difference between all the neighbour containers sizes, then find the first pair where this minimum appears and make a placement. Then repeat the whole process again until no placements can be made. Then calculate the freed places.
This can be done trivially in quadratic time, but that is too slow. The other thing that bothers me that this method may not lead to the optimal solution.

Note: I have to implement the algorithm in C++, and my program has to finish in 200ms. This is why a quadratic solution has no chance. Also, I don't want to have my job done by others, I posted this because I got stuck solving the problem, and needed some help to know if my approach is correct or how can I make optimizations.

modified 24-Apr-22 21:01pm.

AnswerRe: Need an efficient algorithm to solve the following problem Pin
Gerry Schmitz16-Feb-19 8:33
mveGerry Schmitz16-Feb-19 8:33 
QuestionHelp to predict the output of this code Pin
Member 141133789-Jan-19 12:39
Member 141133789-Jan-19 12:39 
AnswerRe: Help to predict the output of this code Pin
Daniel Pfeffer9-Jan-19 21:48
professionalDaniel Pfeffer9-Jan-19 21:48 
AnswerRe: Help to predict the output of this code Pin
ChrisFromWales1-May-19 0:14
ChrisFromWales1-May-19 0:14 
PraiseDinic’s algorithm for Maximum Flow Pin
AshishKhuraishy6-Dec-18 3:56
AshishKhuraishy6-Dec-18 3:56 
GeneralRe: Dinic’s algorithm for Maximum Flow Pin
Patrice T25-Dec-18 16:15
mvePatrice T25-Dec-18 16:15 
SuggestionVector representation of the code. Pin
Member 1406583326-Nov-18 7:50
Member 1406583326-Nov-18 7:50 
GeneralRe: Vector representation of the code. Pin
Gerry Schmitz27-Nov-18 9:19
mveGerry Schmitz27-Nov-18 9:19 
GeneralRe: Vector representation of the code. Pin
shooky561-Dec-18 5:04
shooky561-Dec-18 5:04 
QuestionOptimal Task Scheduling with Complete Knowledge Pin
Member 140435574-Nov-18 12:11
Member 140435574-Nov-18 12:11 
AnswerRe: Optimal Task Scheduling with Complete Knowledge Pin
Mycroft Holmes4-Nov-18 19:31
professionalMycroft Holmes4-Nov-18 19:31 
GeneralRe: Optimal Task Scheduling with Complete Knowledge Pin
Member 140435575-Nov-18 1:37
Member 140435575-Nov-18 1:37 
AnswerRe: Optimal Task Scheduling with Complete Knowledge Pin
Gerry Schmitz12-Nov-18 8:20
mveGerry Schmitz12-Nov-18 8:20 
QuestionChess Futility pruning Pin
GM Fafkorn5-Oct-18 22:13
GM Fafkorn5-Oct-18 22:13 
QuestionAlgorithms help Pin
Member 139775798-Sep-18 7:36
Member 139775798-Sep-18 7:36 
QuestionStart with a group of size X, divide it into Y groups, Z times, minimize overlap Pin
Member 139396526-Aug-18 5:08
Member 139396526-Aug-18 5:08 
AnswerRe: Start with a group of size X, divide it into Y groups, Z times, minimize overlap Pin
Stefan_Lang7-Aug-18 23:29
Stefan_Lang7-Aug-18 23:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.