TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How do you approch going from brute forcing to optimizing an algorithm?

1 点作者 jamessantiago超过 6 年前
This is related to programming puzzles. I&#x27;m a fairly experienced developer and I tend to take to things like CodinGame or HackerRank if I want to familiarize myself with a new language (in addition to other methods, but that&#x27;s another topic).<p>I often run into the problem of optimization when I get a problem that expects you to realize that you can make assumptions and capitilize on these in code. For example, you might be able to reduce the search space if you know certain items don&#x27;t need to be checked or that you can create a linear algorithm for an NP problem because of this reduced search space. Often it&#x27;s something simple like figuring out the behavior of a spiral matrix so you can derive the value at a specific location without iterating through all sequences.<p>So, to go about this, this is my general approach:<p><pre><code> - Look for search speace type optimizations (e.g. if I&#x27;m brute forcing do I need to brute force everything or use binary searches or similar techniques to reduce the problem?) - Plenty of google&#x2F;wikipedia time trying to understand the algorithms at play (e.g. how to you figure out primes... ok, what&#x27;s a sieve.. ok...) - Give up and look for solutions and then try to figure out how they arrived at that solution </code></pre> Is there a better approach? Should I skip to other&#x27;s solutions faster to become more comfortable with this type of work, or am I missing some fundamental process for solving these type of problems? Are there ways to improve on my knowledge that can get me from brute force to optimization faster?

暂无评论

暂无评论