A
A
artshelom2017-07-06 02:06:06
Java
artshelom, 2017-07-06 02:06:06

What sort to use?

Foreword:
I found an interesting task on the Internet by googling, I understood what it is on testing before an interview.
391b33ff5b2e47289ad7c4e154e7a2ab.png
Question:
The task is clear to me, as I understand it, it rests on sorting, I solved the task itself. But here it is impossible to make it run in the specified 1-10 seconds. As I understand it, you need to do sorting, which has a speed of log2 (N). Could you tell me at what stage it is better to do (When the dictionary is just being filled in or immediately after it was filled up or when the necessary words were found) sorting and what kind of sorting to do (While I'm thinking about Shell sorting, but maybe there is better) ???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2017-07-06
@artshelom

Who knows what you did there. In theory, it would be necessary to build a prefix tree based on a set of words, in each node of which there is a one-letter prefix (there is no need for a prefix at the root), the number of words starting with it and its parents, and links (no more than 26 - according to the number of letters of the alphabet) to children nodes.
When calling, you need to select a perfix branch and sort its child nodes. For such short arrays, insertion sort is relevant (yes, yes), but if you want to show off, choose something else .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question