Which of the two sequences is lexicographically smaller ?
A = { 11 ,11,17,61 }
B = { 3 , 3, 5,89 }
Source : Problem 10419 — Sum-up the Primes ( UVa Online Judge )
For 2 Sample which is correct A or B.
Please Help.
If I am missing anything please clarify ?
In lexicographic comparison you start comparison their elements till you get the different elements.
Here in the first comparison it self it’s unmatched, hence now you just pick the smaller number as lexicographic ally smaller.
Hence B is L.smaller.
say two sequence are 1,2,4,5 and 1,2,4,8.
Here first three match 4th does not. hence compare 5 and 8, since 5 is smaller sequence 1,2,4,5 is smaller.
In 1,2,3 and 1,2,3,4.
1,2,3 is smaller
3 Likes
Lexicographical order is similar to “dictionary order”
you first check the first elements of the strings, say A and B.
if the first element of A is smaller, then A is lexicographically smaller. if the elements are equal, check element #2 in both the strings.
A = { 11 ,11,17,61 }
B = { 3 , 3, 5,89 }
B1< A1
therefore,
B is lexicographically smaller.
eg:
A = { 3 ,3,17,61 }
B = { 3 , 3, 5,89 }
A1=B1
A2=B2
A3>B3
therefore, B is lexicographically smaller