网站大量收购闲置独家精品文档,联系QQ:2885784924

北京大学计算概论课件第十二讲 数组.ppt

北京大学计算概论课件第十二讲 数组.ppt

  1. 1、本文档共37页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Lesson 12 Arrays 2007.11.7 Objectives: About the Fibonacci sequence One-Dimensional Arrays Array Initialization Arrays as Function Arguments Case Study: Computing Averages and Standard Deviations Two-Dimensional Arrays Fibonacci Numbers One pair rabbit give birth to a new pair baby rabbits each year The baby rabbits need to wait one year to bear new baby fn+1 = fn + fn-1 f0 = 1 f1 = 1 Fibonacci Numbers in Nature Compute the Fibonacci numbers recursively int fib(int n) { if (n = 2) return 1; else return fib(n-1) + fib(n-2); } Time complexity of the recursive algorithm The growth rate of the computing time with the problem size Use iterative algorithm Use the Golden Ratio: (1+ sqr(5))/2 F(n) = round ( pow (1+sqr(5)) / 2, n) / sqr(5) ) By recursive powering By recursive powering (cont.) Arrays: Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in data type Aggregate data type: data type with two main characteristics Its values can be decomposed into individual data elements, each of which is either atomic or another Aggregate data type It provides an access scheme for locating individual data elements within the data structure Name + space + access scheme Arrays A set of data items with same type Stored in consecutive memory Fixed in size throughout program —— not dynamic Create a one-dimensional array #define NUMELS 5 int grades[NUMELS]; To access an element Format: arrayname[ index value ] First element at position 0 Use a subscripted variable Subscripted variables can be used anywhere scalar variables are valid grades[0] = 98; grades[1] = grades[0] - 11; Any expression that evaluates an integer may be used as a subscript #define NUMELS 5 total = 0; for (i = 0; i NUMELS; i++) total = total + grades[i]; Input and Output of Array Values Array elements can be assigned values by: using assignme

您可能关注的文档

文档评论(0)

ormition + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档