# 算法 Algorithms
# Grade 2 ( 5-7岁 ) 要掌握的程度
People follow and create processes as part of daily life. Many of these processes can be expressed as algorithms that computers can follow.
Routines, such as morning meeting, clean-up time, and dismissal, are examples of algorithms that are common in many early elementary classrooms. Other examples of algorithms include making simple foods, navigating a classroom, and daily routines like brushing teeth. Just as people use algorithms to complete daily routines, they can program computers to use algorithms to complete different tasks. Algorithms are commonly implemented using a precise language that computers can interpret.
Crosscutting Concept: Abstraction Connection Within Framework: K–2.Computing Systems.Hardware and Software
在日常生活中, 我们会创造并遵循各种各样的做事流程. 很多这样的流程能够转化成计算机可以遵循的算法.
比如学校晨会流程、打扫教室卫生的流程、放学流程, 是许多小学常见的流程, 这些流程可以转化为计算机的算法. 再比如, 制作简单食物的流程、巡视教室、刷牙等日常事务也可以转化为计算机算法. 就像人们使用流程来完成日常工作一样,我们也可以在计算机上编程, 让计算机使用算法来完成不同的任务.
注意, 算法通常需要使用计算机能够理解的编程语言来描述.
# Grade 5 ( 8-11岁 ) 要掌握的程度
Different algorithms can achieve the same result. Some algorithms are more appropriate for a specific context than others.
Different algorithms can be used to tie shoes or decide which path to take on the way home from school. While the end results may be similar, they may not be the same: in the example of going home, some paths could be faster, slower, or more direct, depending on varying factors, such as available time or the presence of obstacles (for example, a barking dog). Algorithms can be expressed in noncomputer languages, including natural language, flowcharts, and pseudocode.
Crosscutting Concept: Abstraction Connection Within Framework: 3–5.Data and Analysis.Collection
可以使用不同的算法完成同一项任务, 但是在特定任务背景下, 有些算法比其他算法更适合更有效.
比如说, 系鞋带或者决定放学回家的路径, 可以使用不同的算法来实现, 尽管最终的结果是相似的, 但是仍然有所不同: 不同算法找出的放学回家路径中, 有些路径更快, 有些更慢, 有些更直接. 这取决于不同的因素, 比如可用的时间或者障碍物的存在(比如恶狗拦道).
注意, 算法可以用非编程语言来表达, 包括自然语言、流程图、伪代码[1].
# Grade 8 ( 11-14岁 ) 要掌握的程度
Algorithms affect how people interact with computers and the way computers respond. People design algorithms that are generalizable to many situations. Algorithms that are readable are easier to follow, test, and debug.
Algorithms control what recommendations a user may get on a music-streaming website, how a game responds to finger presses on a touchscreen, and how information is sent across the Internet. An algorithm that is generalizable to many situations can produce different outputs, based on a wide range of inputs. For example, an algorithm for a smart thermostat may control the temperature based on the time of day, how many people are at home, and current electricity consumption. The testing of an algorithm requires the use of inputs that reflect all possible conditions to evaluate its accuracy and robustness.
Crosscutting Concepts: Human–Computer Interaction; Abstraction Connections Within Framework: 6–8.Data and Analysis.Inference and Models; 6–8.Computing Systems.Troubleshooting; 6–8.Data and Analysis.Visualization and Transformation
算法影响着人们和计算机的互动方式以及计算机的反应方式.
算法决定了用户在音乐网站上获得的推荐, 算法决定了游戏如何对触摸屏上的手指按压做出反应, 算法决定了数据如何在互联网上进行传输.
人们通常设计算法以尽可能地适用于多种情况. 具有可读性的算法, 更容易让人遵循、测试和调试.
一个普适性的算法可以根据不同的输入产生不同的结果. 比如说, 为智能恒温器设计的算法, 可以根据一天中不同的时间、家里有多少人、以及当前的耗电量来改变温度.
对算法进行测试时, 需要尽可能穷尽所有可能的输入, 来测试和评估算法的准确性和稳健性.
# Grade 12 ( 14-18岁 ) 要掌握的程度
People evaluate and select algorithms based on performance, reusability, and ease of implementation. Knowledge of common algorithms improves how people develop software, secure data, and store information.
Some algorithms may be easier to implement in a particular programming language, work faster, require less memory to store data, and be applicable in a wider variety of situations than other algorithms. Algorithms used to search and sort data are common in a variety of software applications. Encryption algorithms are used to secure data, and compression algorithms make data storage more efficient. At this level, analysis may involve simple calculations of steps. Analysis using sophisticated mathematical notation to classify algorithm performance, such as Big-O notation, is not expected.
Crosscutting Concepts: Abstraction; Privacy and Security Connections Within Framework: 9–12.Data and Analysis.Storage; 9–12.Networks and the Internet.Cybersecurity
评估和选择算法时, 我们通常会考察算法的性能、可复用性、实施的便利性. 常用的有效的算法, 提升了人们开发软件、保护数据、存储信息的效率.
用于搜索和排序的算法在各种软件应用中都很常见. 加密的算法用于保护数据的安全, 而压缩算法则用于提升数据存储的效率.
需要注意的是, 有些算法更容易在特定的编程语言中实现, 有些算法的计算速度更快, 有些算法占用更少的内存来存储数据, 有些算法比其他算法能够适用于更多的情况.
对于这个阶段的学生, 需要能够分析涉及简单计算步骤的算法, 但并不要求使用复杂的数学符号对算法的性能进行分析(比如Big-O符号).
"伪代码 (pseudo-code)": 是指模仿代码的形式来描述程序的运行逻辑, 但是使用的是符合人类阅读习惯的写法, 而不是真正的编程语言. 也就是说, 伪代码只能用来描述思路, 但是不能用来运行. 它的目的是辅助算法设计阶段的思考, 因为在这个阶段, 需要关注的是思路, 而不是具体实现. 而“伪代码”可以让我们不用纠结于具体的代码实现. 下面是一个例子:
↩︎function 求最大值(a, b) 如果 a >= b a → 最大 否则 b → 最大
1
2
3
4
5