开发者

Efficient way of Writing algorithm

I was wondering when some one asks you to solve an algorithmic problem, is it a good way to actually start off with Hastable, Hashset or HashMap开发者_如何学C. Normally i have heard people saying you shouldn't come up with Hashes as your first answer.

So how should we go about in algorithms: In-place should be given importance or make sure time complexity is best

I'm not trying to generalise, but still some suggestions would be helpful.

Thanks


The best you can hope for is a generalized answer for your generalized question.

It depends.

The reason there are many different algorithms is because there is not always 1 algorithm that is the best. And many algorithms aim to solve different problems from each other. Some algorithms it makes no sense to even talk about hash tables.

If someone asks me to solve an algorithmic problem though, I will probably try to use something that is built in to the language I'm using before designing my own algorithm. The reason is because I value my time. If I find later that the code is not efficient enough, then I can look for a better way to do it.


I think it is really situational. If random access is a priority and you need fast access and little constraint on memory utilization and no sequential access, then Hashtable, (et al), is the choice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜