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
3
votes
7 answers

Finding the lexicographically largest rotations in the string

I need to find the Lexicographically largest string out of the given input string. So if the input is enjoy the o/p should be yenjo The code i tried was.... int n; cout<<"Enter the number of strings"; cin>>n; int len[n]; char…
codefreak
  • 309
  • 2
  • 4
  • 15
3
votes
3 answers

C++ What using for lexicographical_compare?

I wan to user the function lexicographical_compare in algorithms library in c++. But I do not know what to write as far as the using statement. For example using std::lexicographical_compare ?? How can I figure this out for my self in the…
user174084
  • 1,087
  • 3
  • 14
  • 23
3
votes
4 answers

Generating Permutations in Lexicographic Order vs Sorting?

I'm a little bit confused. How is the problem of generating permutations in Lexicographic Order any different from the problem of sorting? Can someone please explain it to me with an example? Thanks
shobhu
  • 694
  • 2
  • 7
  • 16
3
votes
3 answers

sort with lexicographic order

I see the results from the following code, but I don't understand exactly how the or knows what to do in the following sort example: use Data::Dumper; $animals{'man'}{'name'} = 'paul'; $animals{'man'}{'legs'} = 2; $animals{'cheeta'}{'name'} =…
mleykamp
  • 1,356
  • 2
  • 9
  • 11
2
votes
2 answers

Sort list of lists in lexicographic order in Python

I want to get the minimal element of a list of list of tuples a = [[(1, 0), (2, 0), (1, 1)], [(2, 0), (1, 1), (1, 0)], [(1, 1), (1, 0), (2, 0)]] in lexicographic order, so that [(1,1),(1,0),(2,0)]] < [(1,0),(2,0),(1,1)] , since the 0-th entry of…
2
votes
1 answer

Reverse lexicographical using heapq

Essentially I am looking for an efficient way to implement custom comparators using heapq. For instance x = [('a',5),('c',3),('d',2),('e',1)] I could heapify it heapq.heapify(x) then pop the min value heapq.heappop(x) which would return ('a', 5).…
shenglih
  • 879
  • 2
  • 8
  • 18
2
votes
0 answers

Does this strict weak ordering have a name (spoilers for a specific coding puzzle)

There is a coding puzzle I have encountered on one of those sites (I don't recall if it was leetcode or something else) which goes as follows: Given a list of strings, return the lexicographically smallest concatenation that uses each of the strings…
Cereal
  • 156
  • 7
2
votes
2 answers

Does sort -n handle ties predictably when the --stable option is NOT provided? If it does, how?

Here it looks like the space after the 3 in both rows breaks the numerical sorting and lets the alphabetic sorting kick in, so that 11<2: $ echo -e '3 2\n3 11' | sort -n 3 11 3 2 In man sort, I read -s, --stable stabilize sort…
Enlico
  • 23,259
  • 6
  • 48
  • 102
2
votes
2 answers

List all permutations of the numbers 1,...,n in lexicographic order

I'm trying to program a Matlab to list all permutations of the numbers 1 through n in lexicographic order. What I have so far is below. I am using recursion to try and write a program that will work for n=3 first, and then see if I can gain insight…
Tanner
2
votes
1 answer

Generate strings in lexicographical order in Python

How can I write a Python generator that lazily generates all strings composed of lowercase English letters of up to a certain length1? I have written my own solution (posted below as an answer), but I would like to see if there are any more…
Anakhand
  • 2,838
  • 1
  • 22
  • 50
2
votes
1 answer

Double lexicographic sorting of binary (0-1) matrices

I want to sort a binary matrix so that its columns and rows are both in lexicographical order by switching rows and columns. In other words, I need a double-lexical ordering of a matrix consisting of zeros and ones, while the entries of all rows and…
Dunkelkoon
  • 398
  • 2
  • 10
2
votes
0 answers

Given a list of strings find a new string that is lexicographically smallest and is not a substring of any of the strings in the list

I'm trying to solve this by diving into two parts. First to get the lexicographically smallest values between a list of strings and then to check if it is not a substring in the given strings. For the substring check part, Create a Set from the…
boredDev
  • 317
  • 3
  • 18
2
votes
1 answer

Generate restricted weak integer compositions (or partitions) of an integer n into k parts in Python

(Re-posting, as I did not get any response to my previous post) I am trying to write a Python code to generate weak integer compositions (partitions) of a number 'n' into 'k' parts but with a MINIMUM and MAXIMUM value constraint on each partition…
2
votes
1 answer

Lexicographical order of numbers

I'm currently learning about lexicographical sorting but not much is found for numbers. The example i found is based of What is lexicographical order? In the example, it i said that 1 10 2 are in lexicographical ordering. The answer stated that…
Maxxx
  • 3,688
  • 6
  • 28
  • 55
2
votes
1 answer

State Diagram for Turing Machine to compute next string in lexicographical order

What would the state diagram look like for a Turing Machine that computes the next string in lexicographical order over alphabet Σ = {1, 2, 3}? String size is 4, i.e ---1, ---2, ---3, --11, --12, etc... Already tried figuring it out from Michael…