Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8088775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:11:09+00:00 2026-06-05T19:11:09+00:00

I have a database in which I’d like to store an arbitrary ordering for

  • 0

I have a database in which I’d like to store an arbitrary ordering for a particular element. The database in question doesn’t support order sets, so I have to do this myself.

One way to do this would be to store a float value for the element’s position, and then take the average of the position of the surrounding elements when inserting a new one:

Item A - Position 1
Item B - Position 1.5  (just inserted).
Item C - Position 2

Now, for various reasons I don’t wish to use floats, I’d like to use strings instead. For example:

Item A - Position a
Item B - Position aa  (just inserted).
Item C - Position b

I’d like to keep these strings as short as possible since they will never be “tidied up”.

Can anyone suggest an algorithm for generating such string as efficiently and compactly as possible?

Thanks,

Tim

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:11:10+00:00Added an answer on June 5, 2026 at 7:11 pm

    It would be reasonable to assign ‘am’ or ‘an’ position to Item B and use binary division steps for another insertions.
    This resembles 26-al number system, where ‘a’..’z’ symbols correspond to 0..25.

    a b   //0 1
    a an b  //insert after a  - middle letter of alphabet  
    a an au b  //insert after an
    a an ar au b  //insert after an again (middle of an, au)
    a an ap ar au b   //insert after an again
    a an ao ap ar au b //insert after an again
    a an ann ao...  //insert after an, there are no more place after an, have to use 3--symbol label
    ....
    a an anb...  //to insert after an, we treat it as ana
    a an anan anb  // it looks like 0 0.5 0.505 0.51  
    

    Pseudocode for binary tree structure:

    function InsertAndGetStringKey(Root, Element): string
      if Root = nil then
        return Middle('a', 'z') //'n'
    
      if Element > Root then
        if Root.Right = nil then
          return Middle(Root.StringKey, 'z') 
        else
           return InsertAndGetStringKey(Root.Right, Element)   
    
      if Element < Root then
        if Root.Left = nil then
          return Middle(Root.StringKey, 'a') 
        else
           return InsertAndGetStringKey(Root.Left, Element) 
    
    Middle(x, y): 
      //equalize length of strings like (an, anf)-> (ana, anf)
      L = Length(x) - Length(y)
      if L < 0 then
        x = x + StringOf('a', -L) //x + 'aaaaa...' L times
      else if L > 0 then
        y = y + StringOf('a', L)  
    
      if LL = LastSymbol(x) - LastSymbol(y)  = +-1 then
        return(Min(x, y) + 'n')  // (anf, ang) - > anfn
      else
        return(Min(x, y) + (LastSymbol(x) + LastSymbol(y))/2) // (nf, ni)-> ng
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database which contains an Assignment table. The table looks like this:
I have a database which needs to store year ranges (such as lifespan) which
I have sqlite database which I would like to insert values in Hebrew to
An example for the sake of the question: I have a database which contains
I have a question about generic list. Assume that I have a database which
I have a database which has an orders table and inventory table. The order-items
I have a database which stores the work my staff do. One particular query
I have a database which contains fisheries in different regions. I am using the
I have a database which is including two tables, Labs and LabUsers How do
I have a database which I regularly need to import large amounts of data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.