Lexicographic sorting of given set of keys

Given a set of strings, print them in Lexicographic order (dictionary/alphabetical order).

 


 

Lexicographic sorting of a set of keys can be accomplished with a simple trie-based algorithm as follows

  • Insert all keys in a trie.
     
  • Print all keys in the trie by performing pre-order traversal on trie to get output in lexicographically increasing order.

C++

Download   Run Code

Output:

a
accomplished
algorithm
all
based
be
by
can
depth
first
in
increasing
insert
is
keys
kind
lexicographic
lexicographically
means
of
order
output
preorder
results
set
simple
sorting
that
the
traversal
trie
we
which
with

Thanks for reading.




Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂
 





Sort by:   newest | oldest | most voted
Abhsihyam
Abhsihyam

Java implementation for the above problem

Git Link: https://github.com/abhishyam21/trees/tree/master/src/com/trie

Simran Singh grewal
Simran Singh grewal

What is Its time complexity?

wpDiscuz