Questions tagged [lexicographic-ordering]

Use this tag to describe the way of ordering a sequence in a lexicographical order

lexicographical order is a generalization of the alphabetical order of the dictionaries to sequences of ordered symbols or, more generally, of elements of a totally ordered set.

There are several variants and generalizations of the lexicographical ordering. One variant applies to sequences of different lengths by comparing the lengths of the sequences before considering their elements.

cf.

48 questions
85
votes
8 answers

String Comparison in Java

What does "compare two strings lexicographically" mean?
Harshana
  • 7,297
  • 25
  • 99
  • 173
42
votes
3 answers

Sort list of strings ignoring upper/lower case

I have a list which contains strings representing animal names. I need to sort the list. If I use sorted(list), it will give the list output with uppercase strings first and then lowercase. But I need the below output. Input: var =…
Darknight
  • 1,132
  • 2
  • 13
  • 31
39
votes
5 answers

Dumping a dictionary to a YAML file while preserving order

I've been trying to dump a dictionary to a YAML file. The problem is that the program that imports the YAML file needs the keywords in a specific order. This order is not alphabetically. import yaml import os baseFile = 'myfile.dat' lyml =…
Ben
  • 426
  • 1
  • 4
  • 5
5
votes
7 answers

Given 2 strings, remove only one digit to make 1 string lexicographically smaller

I am trying to work through a coding problem of string manipulation in Java. The question is that Given two strings S and T consisting of digits and lowercase letters, you are allowed to remove only one digit from either string, count how many…
timeRocket
  • 93
  • 1
  • 1
  • 9
5
votes
3 answers

Definition of a lexicographical order?

I am currently reading about the std::next_permutation function and encountered the term "lexicographical order". At the particular time, I had no experience with this term whatsoever so did a google search for this and found only somewhat cryptic…
user8626782
5
votes
4 answers

interview prep: optimizing swapLexOrder

Interview hash map question on code fights, need help optimizing my brute force solution. Here is the problem: Given a string str and array of pairs that indicates which indices in the string can be swapped, return the lexicographically largest…
bhuj2000
  • 237
  • 3
  • 9
4
votes
2 answers

Bash string lexicographical comparisons inconsistency

Bash manual section 6.4 describes [[ string1 < string2 ]] as True if string1 sorts after string2 lexicographically in the current locale. I am using a stock English language Linux and was expecting my current locale is ASCII where…
Michael Chen
  • 631
  • 5
  • 12
3
votes
2 answers

Numbering permutations

Given an alphabet A = {a,b,c,d,...} of length n, I would like to get all permutations of length r (r < n). Now I would like to number these permutations, and there should be a reverse mapping. For example: A = {a,b,c}, r = 2 ab -> 0 ba -> 1 ac ->…
nuemlouno
  • 288
  • 1
  • 10
3
votes
1 answer

What is the equivalent way to do Ordering.lexicographical() in Java 8 Comparator?

Is there a way to implement Ordering.lexicographical() with Java 8 Comparator? Comparator.thenCompare seems to be limited in this
Kelvin Ng
  • 174
  • 1
  • 12
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
2 answers

How to lexicographically compare two vectors in reverse order?

If I want to compare two vectors in lexicographical order, I can do as follows: int main() { std::vector a{0, 7, 8, 9}; std::vector b{1, 2, 3, 4}; std::cout << std::boolalpha; std::cout << "a < b returns " << (a < b) <<…
2
votes
4 answers

How to list all permutations without repetition in Google Sheets?

The current post is a follow-up question to this linked one: Shuffle a deck of 7 hypothetical trading cards and list out the orders they can come in a Google Sheet Surprise! My problem child is actually for Shin Megami Tensei 3 permutations -- for a…
2
votes
1 answer

Is there a string "constant" that is guaranteed to be after all other strings?

I changed how I was doing things but at one point I needed to append a string to the end of an array of strings and I wanted it guaranteed to be lexicologically after all of the other strings. For integers this would be MAXINT or some similar…
pedz
  • 2,271
  • 1
  • 17
  • 20
2
votes
2 answers

How to sort a list by multiple fields in different orders (asc/desc) in Java?

I have an ArrayList in Java and each element in the list is an object with 3 fields (a, b and c). I should order by a in ascending order; if 2 elements have the same value for a, they should be ordered by b in descending order; finally, if 2…
pinux10
  • 31
  • 4
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…
1
2 3 4