最佳適應算法和最壞適應算法
by Evaristo Caraballo
通過Evaristo Caraballo
算法:好,壞和丑陋 (Algorithms: The Good, The Bad and The Ugly)
Who has been in Free Code Camp without having the experience of spending hours trying to solve Algorithms?
誰曾參加Free Code Camp,卻沒有花費大量時間嘗試求解算法 ?
At Free Code Camp, we wanted to know why that was the case, and what more we could do to help you a bit.
在Free Code Camp,我們想知道為什么會這樣,以及我們還能做些什么來幫助您。
We made two different analyses to have a better idea of what was going on. Data were collected between Nov 2014 to Dec 2015.
我們進行了兩種不同的分析,以更好地了解正在發生的事情。 數據收集時間為2014年11月至2015年12月。
One of those analyses consisted of tracking the number of times people pasted their code to be checked by others in relevant Gitter chatrooms. We got data from the Gitter API. After some clean-up we tried to get the names of the functions of each challenge from posted messages at the Help chatroom. Although the data are not precise, it’s a good approximation of what could be happening.
這些分析之一是跟蹤人們在相關的Gitter聊天室中粘貼代碼以供其他人檢查的次數。 我們從Gitter API獲取數據。 進行一些清理后,我們嘗試從幫助聊天室中發布的消息中獲取每個挑戰的功能名稱。 盡管數據不精確,但是可以很好地近似所發生的事情。
The chart above speaks clearly on its own: algorithms like palindromes, title case, seek and destroy, longest word, reverse string, mutation or chunky monkey are those where many people ask for assistance.
上面的圖表清楚地說明了自己:回文,標題大小寫,查找和銷毀,最長的單詞,反向字符串,變異或矮胖的猴子之類的算法是許多人尋求幫助的算法。
Another analysis we made was to take the average time per page that each camper spent on each challenge, using Google Analytics data.
我們進行的另一項分析是使用Google Analytics(分析)數據獲取每個露營者在每項挑戰上花費的平均每頁時間。
Again, the ugly ones are challenges like palindromes, but there are other ones that also look ugly (let’s say 1/4 of the average time per level over the same average time) specially for basic and intermediate levels, like Spinal Tap Case, Pig Latin, Search and Replace, Common Multiple, Sum All Primes, Steamroller, Friendly Date Range, Pairwise, and others.
同樣,丑陋的挑戰是諸如回文集之類的挑戰,但是還有其他挑戰看起來也很丑陋(例如,在同一平均時間內每個級別的平均時間的1/4), 特別是對于基礎水平和中級水平而言 ,例如Spinal Tap Case,Pig拉丁語,搜索和替換,公倍數,所有素數之和,Steamroller,友好日期范圍,成對和其他。
Looking at the results, can we suggest the factors that are affecting the performance of campers with the algorithms?
從結果來看 , 我們能否通過算法提出影響露營者性能的因素 ?
The most apparent reasons, given in a tentative ordering, are:
按暫定順序給出的最明顯的原因是:
Campers are finding hard to deal specially with strings, and Regex is a bad word, no matter the level!
營員發現很難對付弦 ,而正則表達式無論級別高低都是一個壞詞!
There are some numeric challenges that are making camper’s life difficult, particularly those which are suitable for recursive calls.
有一些數字難題使露營者的生活變得困難,尤其是那些適合遞歸調用的難題。
Another common problem is dealing with nested collections of arrays/objects.
另一個常見的問題是處理數組/對象的嵌套集合 。
Difficulty with concepts and definitions is usual. For example, the concept of “symmetric difference” (with a Free Code Camp algorithm with the same name) is usually troubling because many campers don’t understand the concept properly, despite the inclusion of a widely accepted mathematical definition.
通常很難理解概念和定義 。 例如,“對稱差異”的概念(使用具有相同名稱的Free Code Camp算法)通常令人不安,因為盡管包含了廣泛接受的數學定義,但許多營員仍無法正確理解該概念。
Similarly, looking at the last chart you may be wondering why the time per page seems not to reflect the difficulty of the problem? One explanation could be that the basic and intermediate algorithms are been taken by campers who are just learning to code or seeing JavaScript for the first time. However this is a tentative explanation and may require more analyses.
同樣,查看最后一個圖表,您可能想知道為什么每頁時間似乎不能反映問題的難度 ? 一種解釋可能是,基本算法和中間算法是由剛開始學習編碼或第一次看到JavaScript的營員采用的。 但是,這只是一個初步的解釋,可能需要更多的分析。
If you are reading this and you have already suffered with some of the algorithms, you will realize that you are not alone. For those who are starting with algorithms, I would recommend the following:
如果您正在閱讀本文,并且已經受了某些算法的困擾,您將意識到自己并不孤單。 對于那些開始使用算法的人,我建議以下內容:
- Try to see if you can solve the easiest first: you might find some practice solving those that could help you to deal with the more difficult ones later… 嘗試先看看是否可以解決最簡單的問題:您可能會找到一些解決方法,可以幫助以后解決更困難的問題……
- Try to understand the problem! Start by asking what the problem is about. 嘗試了解問題! 首先詢問問題所在。
- Research. Check b0oks, references, and other online courses. And Share. We are offering a lot of help with likely a similar problem like yours. Ask in the chatroom. Send a message to CamperBot. Look at the Wiki. Try pair programming. Visit a Campsite and code with other campers in person. In one of the CodePens I made for this article, I also included links to the Free Code Camp wiki, so you can have a first overview of the problem and how it is normally solved. 研究。 檢查書,參考書和其他在線課程。 和分享。 對于像您這樣的類似問題,我們提供了很多幫助。 在聊天室提問。 發信息給CamperBot。 看一下Wiki。 嘗試配對編程。 參觀營地并親自與其他營員進行編碼。 在我為本文編寫的CodePens之一中,我還提供了指向Free Code Camp Wiki的鏈接,因此您可以初步了解該問題以及通常如何解決該問題。
You may already know that the problem is difficult: now the next step is trying to understand why and what make it so hard. This approach is key for algorithmic problem solving, and programming in general. Study, ask, and try again.
您可能已經知道問題很棘手:現在,下一步就是嘗試了解導致問題變得如此困難的原因和原因 。 這種方法對于解決算法問題和一般編程至關重要。 研究,詢問,然后重試。
The data we used for these analyses were for last year: this year SaintPeter and friends have been working hard in modify the curriculum, so you may notice a difference in your performance if you work through the improved Basic JavaScript section. If you haven’t done the updated curriculum it may be helpful to revisit that section.
我們用于這些分析的數據是去年的:今年, 圣彼得和朋友們一直在努力修改課程表,因此,如果您在改進的“基本JavaScript”部分中工作,您可能會發現性能有所不同。 如果您還沒有完成更新的課程表,那么重新訪問該部分可能會有所幫助。
- My bonus advice? Yes, try really hard yourself but… read other peoples’ code, too. When you read a book about JavaScript to learn programming, that is exactly what you are doing. Learn to reverse engineer existing code and to modify it to suit your needs. Why? First, no point in re-inventing the wheel. Second, you learn a lot by understanding the work of those who already solved the problem. Remember: you will find that most of the time you will be reusing modified snippets of a previous code into a new one. So no shame in reading other’s codes. That is part of the nature of Open Source, by the way… 我的獎金建議? 是的,你要自己努力,但是……也要閱讀其他人的代碼。 當您閱讀有關JavaScript的書以學習編程時,這就是您正在做的事情。 學習對現有代碼進行反向工程并進行修改以滿足您的需求。 為什么? 首先,重新發明輪子毫無意義。 其次,通過了解已經解決問題的人員的工作,您學到了很多東西。 請記住:您會發現大多數時候您將把先前代碼的修改片段重用到新代碼中。 因此,在閱讀他人的代碼時不會感到羞恥。 順便說一下,這是開放源代碼本質的一部分。
Happy Coding!
編碼愉快!
I’m also working on related visualizations at bl.ocks.org/evaristoc.
我還在bl.ocks.org/evaristoc上進行相關的可視化工作。
This analysis just scratches the surface of what we can learn from Free Code Camp’s open data. Join our Data Science chat room and help us make sense of all these data.
這種分析只是從表面上我們可以從Free Code Camp的開放數據中學到什么。 加入我們的數據科學聊天室 ,幫助我們理解所有這些數據。
翻譯自: https://www.freecodecamp.org/news/algorithms-the-good-the-bad-and-the-ugly-e63db0a9cfb3/
最佳適應算法和最壞適應算法