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
1
vote
1 answer

Lex-sorting a pandas series/dataframe

Hi I have a data frame which has the following values as input {1,20,21,10,100,1000,30} I need the output to be sorted as {1,10,100,1000,20,21,30} What is the best way to do this, I have more than 20000 values to be sorted in the above format. I…
Madan Kumar
  • 55
  • 1
  • 5
1
vote
2 answers

Comparing Strings lexicographically new approach fails for one test case

I was asked to check whether String a is lexicographically larger String b. So even before thinking about compareTo() method I got a new idea. Take the minimum of the lengths of both a & b. Iterate a for loop till that minimum length and store the…
Arun Sudhakaran
  • 2,167
  • 4
  • 27
  • 52
1
vote
1 answer

Lexicographically comparing two strings

I am trying to find out lexicographically smallest and largest substring of length z which is taken from input. I don't know why but the if condition is not working where I am trying to find the minimum substring. import java.io.*; import…
Eduardo
  • 35
  • 4
1
vote
2 answers

Assign same lexicographic rank to duplicate elements of 2d array

I'm trying to lexicographically rank array components. The below code works fine, but I'd like to assign equal ranks to equal elements. import numpy as np values = np.asarray([ [1, 2, 3], [1, 1, 1], [2, 2, 3], [1, 2, 3], [1, 1,…
orange
  • 7,755
  • 14
  • 75
  • 139
1
vote
1 answer

Sorting array with numpy

I'd like to change the order of the column elements in a = np.asarray( [[0,1,1,2,2,2,2,3,3,3,4,4,4,4,4,4], [4,0,3,0,1,2,5,1,2,5,3,4,6,6,7,7], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,1,0,0,1,1,1,0,0,0,1,1,0,1,0,1]] ) based on the values of row 1-3…
orange
  • 7,755
  • 14
  • 75
  • 139
1
vote
2 answers

Searching between dates in Hbase

I have Hbase table wiht rowKeys as such (delimter = '#') 0CE5C485#1481400000#A#B#C#T 00C6F485#1481600000#F#J#C#G 065ED485#1481500000#T#X#C#G ... ... The first part is actually the hex of the timestamp reversed (the second part is the timestamp). I…
Huga
  • 571
  • 1
  • 8
  • 21
1
vote
5 answers

How to impose a lexicographic order on an (arbitrary) POD C++ struct?

I have some POD struct foo; suppose it's struct foo { int x; unsigned y; }. I want to be able to compare struct foo's using lexicographic order - by order of their fields of course. That is, I want all of the operators <, ==, >, etc. to work for…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
3 answers

Sorting string lexicographically in c

I want to sort words of a string in lexicographical order. For Example: I have a string: I am Apple Output should be: am Apple I Problem (output): enter the string hello shamsh the sorted array: hello It's not sorting the string and whole…
Tabassum Ahmed
  • 51
  • 1
  • 2
  • 9
1
vote
1 answer

Find all possible combinations of of a particular size for a set of numbers

I'm looking to solve the following problem : Given two integers n and k, return all possible combinations of k numbers out of 1 2 3 ... n. Make sure the combinations are sorted. To elaborate, Within every entry, elements should be sorted. [1, 4] is…
Aditya Satyavada
  • 1,028
  • 1
  • 10
  • 14
1
vote
1 answer

Lexicographic Order in Multidimensional Array C++

I'm having trouble with one final task that my program should do. Having my output character in a lexicographic order. For example, if I input bbbaaa it should have an output of Frequencies: a 3 b 3 Not Frequencies: b 3 a 3 Can anyone…
Dave
  • 11
  • 1
1
vote
1 answer

How to manually lexicographically compareTo "abcd" & ""abcde" effectively

I wanted to write my own compareTo method, so I wrote this simple code: public int myCompare(String a, String b) { int min = Math.min(a.length(), b.length()); for (int i=0; i < min; i++) { int diff = a.charAt(i) - b.charAt(i); …
Nimrod
  • 1,100
  • 1
  • 11
  • 27
1
vote
3 answers

Order a List lexicographically using brute force
That's my code... string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse quis nisl vitae dolor tempus iaculis at id augue. Nullam metus mauris, viverra vitae tristique sed, pulvinar ac nulla." List listCarac =…
1
vote
3 answers

How can I merge two lexicographically ordered String ArrayLists into a new third ArrayList?

How can I merge two lexicographically ordered String ArrayLists into a new third ArrayList without modifying the two original lists? Duplicates are allowed, for instance. If list1 is: 1, 3, 5 and list2 is: 2, 4, 7, 8, 8. Then the new merged list3…
MercedezB
  • 53
  • 1
  • 7
1
vote
1 answer

Obtain lexicographically smallest & largest substring. My algorithm failed most of the test cases but I can't understand why. Help me figure it out

I had to do a test today for an interview and the problem was obtaining the lexicographically smallest and largest substring (in other words, sort by name). Link - Complete the function SmallestAndLargestSubstring, which takes a string S consisting…
user2296609
  • 35
  • 1
  • 7
1
vote
3 answers

Algorithm that spits out the smallest and largest substring starting with vowel and ending with consonant for a String

I am trying to write such an algorithm in Java. I am testing the String input "abaab". It's safe to assume the string inputs will be lowercase. I am at a loss in checking where my algorithm is going wrong (it only outputs "a a" for this input…
Dhruv Ghulati
  • 2,976
  • 3
  • 35
  • 51