Questions tagged [lexicographic]

lexicographic or lexicographical order is a generalization of the way the alphabetical order of words is based on the alphabetical order of their component letters.

Definition:

Given two partially ordered sets A and B, the lexicographical order on the Cartesian product A × B is defined as

(a,b) ≤ (a′,b′) if and only if a < a′ or (a = a′ and b ≤ b′).

The result is a partial order. If A and B are totally ordered, then the result is a total order as well. More generally, one can define the lexicographic order on the Cartesian product of n ordered sets, on the Cartesian product of a countably infinite family of ordered sets, and on the union of such sets.

Read more

238 questions
9
votes
4 answers

String encoding of primitive types preserving lexicographic order

Does anyone know of a library for encoding a number of primitive types (like integers, floats, strings, etc) into a string but preserving the lexicographical order of the types? Ideally, I'm looking for a C++ library, but other languages are fine…
nilton
  • 798
  • 1
  • 8
  • 11
9
votes
2 answers

lexicographically smallest string after rotation

I am trying to solve this problem in spoj I need to find the number of rotations of a given string that will make it lexicographically smallest among all the rotations. For example: Original: ama First rotation: maa Second rotation: aam This is the…
doctore
  • 518
  • 9
  • 18
8
votes
1 answer

What does lexical file name order mean?

In the package initialization part of the Go specification, what does "lexical file name order" mean? To ensure reproducible initialization behavior, build systems are encouraged to present multiple files belonging to the same package in …
Salah Eddine Taouririt
  • 24,925
  • 20
  • 60
  • 96
8
votes
6 answers

How do I sort an ArrayList lexicographically?

I am trying to sort an ArrayList of Strings that represent card values. So, some cards contain letters ("King") and some contain Strings containing only a number ("7"). I know to use Collections.sort, but it only sorts Strings that contain letters.…
Jake
  • 81
  • 1
  • 1
  • 3
7
votes
2 answers

SQLAlchemy order_by string column with int values

I have a table with a String column but it holds only integers (as strings). Problem comes when I want to order_by this column on certain query. SQLAlchemy (or python more specifically) uses lexicographic order for strings, so >>> '100000' <…
Javier Novoa C.
  • 11,257
  • 13
  • 57
  • 75
7
votes
3 answers

Creating a program that prints true if three words are entered in dictionary order

I am trying to create a program that asks the user for three words and prints 'True' if the words are entered in dictionary order. E.G: Enter first word: chicken Enter second word: fish Enter third word: zebra True Here is my code so far: first…
Joe Dingle
  • 123
  • 1
  • 4
  • 12
7
votes
6 answers

strcmp() but with 0-9 AFTER A-Z? (C/C++)

For reasons I completely disagree with but "The Powers (of Anti-Usability) That Be" continue to decree despite my objections, I have a sorting routine which does basic strcmp() compares to sort by its name. It works great; it's hard to get that one…
Aaron Burke
  • 486
  • 3
  • 12
6
votes
3 answers

Python equivalent of bash sort lexicographical and numerical

So I've been working on a Python script that combines some information into a "bed" format. Which means that I'm working with features on a genome, my first column is the scaffold name (string), the second the start position on that scaffold…
Joëlle
  • 63
  • 4
5
votes
1 answer

Why doesn't STL's implementation of next_permutation use the binary search?

I came up with this question after reading the excellent answer of std::next_permutation Implementation Explanation. Please refer to that post for an explanation of the algorithm used by STL, but I'll replicate the code here for your…
nalzok
  • 14,965
  • 21
  • 72
  • 139
5
votes
7 answers

How do you structure your comparison functions?

I frequently encounter situations, especially with sorting in C++, where I am comparing a series of fields in order to compare a larger structure. A simplified example: struct Car{ Manufacturer make; ModelName model; Year year; }; bool…
jasonmray
  • 2,350
  • 2
  • 19
  • 14
5
votes
1 answer

Who is the greatest among all strings?

I'm inserting a special (summary) row into a DataTable, and I want it to appear last in a sorted DataView. I know the DataView is being sorted (ascending) by a particular string column, and for display purposes it doesn't matter what value appears…
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
5
votes
3 answers

Lexicographically sort C#

I have this code for sorting strings: class Program { static void Main() { int x = Convert.ToInt32(Console.ReadLine()); List sampleList = new List(); for (int i=0; i
classical312
  • 185
  • 1
  • 4
  • 11
5
votes
4 answers

How do I sort efficiently a quadruple structs in C++?

I have a struct with members x,y,z and w. How do I sort efficiently first by x, then by y, by z and finally by w in C++?
user2381422
  • 5,645
  • 14
  • 42
  • 56
4
votes
2 answers

How is 'Jared' greater than 'Brittany'?

I'm looking in my book, and it doesn't explain it. Its telling me what a binary search tree is and it decided to use strings. Jared / \ Brittany Megan / \ / \ Brett Doug Jim Whitney So supposedly, a…
Strawberry
  • 66,024
  • 56
  • 149
  • 197
4
votes
3 answers

What is an elegant idiom for a lexicographic Ord instance?

This code works, but it's verbose, and I'm sure there's a more concise way. import qualified Data.Vector as V data Event a = Event { start :: Time , duration :: Time , payload :: Maybe a } deriving (Show,…
Jeffrey Benjamin Brown
  • 3,427
  • 2
  • 28
  • 40
1
2
3
15 16