0

I tried searching this word but unable to get proper answer...
Is lexicographical means sorting alphabetically OR if two or more parameters share the same name, they are sorted by their value.

Thanks for your help!!!!.....

Moeed Farooqui
  • 3,604
  • 1
  • 18
  • 23

2 Answers2

1

If you sort the numbers 2,3,4 and 23 numerically, you get 2,3,4,23

If you sort them lexicographically, you get 2,23,3,4

For example, the output of ls -lis sorted lexicographically, therefore you see

file2
file23
file3
file4

Instead of

file2
file3
file4
file23
Ingo
  • 36,037
  • 5
  • 53
  • 100
0

lexicographical order stands for the way you order data (sort) - like in dictionary (alphabetically).

That is, in java, if you want to sort Strings you just order them using a.compareTo(b) < 0. If you have String[N] strings it will be lexicographically sorted if the following holds:

  • strings[0].compareTo(strings[1]) < 0
  • strings[1].compareTo(strings[2]) < 0
  • ...
  • strings[n-2].compareTo(strings[n-1]) < 0

Read more on wikipedia

sasha.sochka
  • 14,395
  • 10
  • 44
  • 68