Click here to Skip to main content
15,890,282 members
Home / Discussions / Algorithms
   

Algorithms

 
Questionpumping lema and regular languages Pin
Sadaiyappan8-May-09 6:39
Sadaiyappan8-May-09 6:39 
AnswerRe: pumping lema and regular languages Pin
Luc Pattyn8-May-09 6:51
sitebuilderLuc Pattyn8-May-09 6:51 
AnswerRe: pumping lema and regular languages Pin
Alan Balkany11-May-09 3:35
Alan Balkany11-May-09 3:35 
QuestionAlgorithm to sort list Pin
TheConfusedGuy7-May-09 11:27
TheConfusedGuy7-May-09 11:27 
AnswerRe: Algorithm to sort list Pin
harold aptroot7-May-09 12:24
harold aptroot7-May-09 12:24 
AnswerRe: Algorithm to sort list Pin
Luc Pattyn7-May-09 12:56
sitebuilderLuc Pattyn7-May-09 12:56 
AnswerRe: Algorithm to sort list Pin
Luc Pattyn7-May-09 13:55
sitebuilderLuc Pattyn7-May-09 13:55 
AnswerRe: Algorithm to sort list [modified] Pin
dybs7-May-09 17:55
dybs7-May-09 17:55 
Not certain how efficient this would be, but a tree structure may work for this as well. Bear with me, this might seem more complicated than it really is, trees aren't the easiest to explain in plain text Smile | :) Assume your initial list is sorted the start of each speed segment as you have described, with the first entry covering the overall speed of the track:

TheConfusedGuy wrote:
LOMILE, HIMILE, SPEED
0, 30, 25
2, 10, 15
4, 6, 10
*7,9,5
10, 20, 20
*Added for example clarification


I'm thinking the tree structure would be like so:
        0,30,25
       /       \
   2,10,15   10,20,20
   /     \
4,6,10  7,9,5

Insert procedure as follows:
1. Root node = (0,30,25)
2. New = (2,10,15), compare = (0,30,25)
3. 2 b/w 0 and 30, compare = child of compare (null/no children)
4. compare = null, add New as child of compare.

5. New = (4,6,10), compare = (0,30,25)
6. 4 b/w 0 and 30, compare = child of compare (2,10,15)
7. 4 b/w 2 and 10, compare = child of compare (null, no children)
8. compare = null, add New as child of compare.

9. New = (7,9,5), compare = (0,30,25)
10. 7 b/w 0 and 30, compare = child of compare (2,10,15)
11. 7 b/w 2 and 10, compare = child of compare (4, 6, 10)
12. 7 past 6, compare = sibling of compare (null, no more siblings)
13. compare = null, add New as sibling of compare

... and so on.

I know the insert procedure seems complicated (trees tend to be that way), but I think it would be relatively efficient. To find the speed limit for a given track position, simply compare the position to the LOWMILE value of each node when you traverse your tree. Your lookup wouldn't be O(1), but no worse O(log m(n)) (I think), where m is the max number of subsections to a given stretch, and n is the total number of defined subsections. So in the example here, it would be O(log 2(3)) Your 2 worst cases would be:

|----|----|----|
|----|
     |----|
          |----|

or

|----|----|----|
|----|----|
     |----|


I hope this all makes sense. This is all totally off the top of me head, so I could be mistaken on how efficient this might be. I'm curious what ya'll's opinion is on this method Smile | :)

Dybs

modified on Friday, May 8, 2009 12:14 AM

GeneralRe: Algorithm to sort list (Reply to All) Pin
TheConfusedGuy7-May-09 18:27
TheConfusedGuy7-May-09 18:27 
GeneralRe: Algorithm to sort list (Reply to All) Pin
dybs7-May-09 19:01
dybs7-May-09 19:01 
GeneralRe: Algorithm to sort list (Reply to All) Pin
TheConfusedGuy7-May-09 19:07
TheConfusedGuy7-May-09 19:07 
Questionbearing angle calculation Pin
ranjanguru6-May-09 22:45
ranjanguru6-May-09 22:45 
AnswerRe: bearing angle calculation Pin
molesworth6-May-09 23:38
molesworth6-May-09 23:38 
GeneralRe: bearing angle calculation Pin
ranjanguru6-May-09 23:48
ranjanguru6-May-09 23:48 
GeneralRe: bearing angle calculation Pin
molesworth7-May-09 0:06
molesworth7-May-09 0:06 
GeneralRe: bearing angle calculation Pin
molesworth8-May-09 3:13
molesworth8-May-09 3:13 
AnswerRe: bearing angle calculation Pin
OriginalGriff6-May-09 23:52
mveOriginalGriff6-May-09 23:52 
GeneralRe: bearing angle calculation Pin
ranjanguru6-May-09 23:57
ranjanguru6-May-09 23:57 
AnswerRe: bearing angle calculation Pin
Stuart Cox7-May-09 11:01
Stuart Cox7-May-09 11:01 
AnswerRe: bearing angle calculation Pin
cp98768-May-09 15:30
cp98768-May-09 15:30 
QuestionPolygon Rendering Performance Optimization Pin
StarBP6-May-09 11:27
StarBP6-May-09 11:27 
QuestionWhich language is this Urgent help required Pin
Sanjaykalsi5-May-09 22:55
Sanjaykalsi5-May-09 22:55 
AnswerRe: Which language is this Urgent help required Pin
OriginalGriff5-May-09 23:03
mveOriginalGriff5-May-09 23:03 
QuestionTrying to create a for loop that gives all Unique combinations without using recursive process. Pin
luke.orun5-May-09 13:49
luke.orun5-May-09 13:49 
AnswerRe: Trying to create a for loop that gives all Unique combinations without using recursive process. Pin
Luc Pattyn5-May-09 14:41
sitebuilderLuc Pattyn5-May-09 14:41 

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.