avatar
Articles
57
Tags
48
Categories
11

Home
Archives
Tags
Categories
About
Oscar-Ge
Home
Archives
Tags
Categories
About

Oscar-Ge

CS 61A lect9 tree recusion
Created2024-04-05|CS 61A
CS61A lect9 tree recusion• Each cascade frame is from a different call to cascade.• Until the Return value appears, that call has not completed.• Any statement can appear before or after the recursive call.Write a function that prints an inverse cascade:1121231234123121 12345678910def inverse_cascade(n): grow(n) print(n) shrink(n)def f_then_g(f, g, n): if n: f(n) g(n)grow = lambda n: f_then_g(grow, print, n//10) shrink = lambda n: f_then_g(print, shrink, n//10) tr ...
CS 61A lect8 recursion
Created2024-04-05|CS 61A
CS61A lect8: recusionThe Anatomy of a Recursive FunctionThe def statement header is similar to other functions• Conditional statements check for base cases• Base cases are evaluated without recursive calls• Recursive cases are evaluated with recursive calls Iteration is a special case of recursion.
CS 61A lect6 code standards
Created2024-04-05|CS 61A
CS61A lect6 code standardsChoosing NamesNames typically don’t matter for correctnessbut they matter a lot for compositionNames should convey the meaning or purpose of the values to which they are bound.The type of value bound to the name is best documented in a function’s docstring.Function names typically convey their effect (print), their behavior (triple), or the value returned (abs)Which Values Deserve a NameRepeated compound expressionsMeaningful parts of complex expressionsMore Naming Tips ...
CS 61A lect5
Created2024-04-05|CS 61A
CS61A lect5Environments for Higher-Order Functions 12345def apply_twice(f, x): return f(f(x))def square(x): return x * xresult = apply_twice(square, 2) Applying a user-defined function:• Create a new frame• Bind formal parameters (f & x) to arguments• Execute the body: return f(f(x))Nested Def Statements 12345def make_adder(n): def adder(k): return k+n return adderadd_three=make_adder(3) Every user-defined function has a parent frame (often global)• The parent of a function is t ...
CS 61A lect4
Created2024-04-05|CS 61A
CS61A lect412345678def fib(n): """Compute the nth Fibonacci number, for N >= 1.""" pred, curr = 0, 1 # 0th and 1st Fibonacci numbers k = 1 # curr is the kth Fibonacci number while k < n: pred, curr = curr, pred + curr k = k + 1 return curr Describing FunctionsA function’s domain is the set of all inputs it might possibly take as arguments.A function’s range is the set of output values it might possibly return.A pure function’s behavior is the relationship i ...
CS 61A lect3
Created2024-04-05|CS 61A
CS61A lect3None Indicates that Nothing is Returned:The special value None represents nothing in PythonA function that does not explicitly return a value will return NoneCareful: None is not displayed by the interpreter as the value of an expressionexample:print(print(1), print(2))12None None Miscellaneous Python Featuresinterept:python3 -i xx.pymultiple return valuesdoctests:write inputs in the 注释!for example:""">>>q, r=divide_exact(5, 3)>>>q201>>>r3&quo ...
CS 61A lect2
Created2024-04-05|CS 61A
CS61A lect2Anatomy of a Call Expression:operator, operandadd ( 2 , 3 ) Operator Operand Operand Operators and operands are also expressions Evaluation procedure for call expressions: Evaluate the operator and then the operand subexpressions Apply the function that is the value of the operator to the arguments that are the values of the operands Execution rule for assignment statements: Evaluate all expressions to the right of = from left to right. Bind all names to the left of = to ...
1…56
avatar
Oscar
Articles
57
Tags
48
Categories
11
Follow Me
Announcement
This is my Blog
Recent Post
Untitled2024-09-12
Untitled2024-09-12
web2024-09-12
CSAPP-chap5- Optimizing Program Performance2024-09-02
typst-learning2024-09-02
Categories
  • Algs1
  • CS 1884
  • CS 61A11
  • CS 61B14
  • CS 61C6
  • CS106L4
  • CS110L2
  • CSAPP4
Tags
Scheme python Math Java BST MST C project2 BasicC Algs matlab EE vim Graph RBT X86-64 Shortest_path CS110L ICS 61C System Assembly Git class Linear Algebra Rust GDB Iterators CPU debugging Basic linux AI CSAPP functions BTree 61B CS 61A CS sorting
Archives
  • September 20245
  • August 20245
  • July 20242
  • June 202410
  • May 20249
  • April 202426
Info
Article :
57
UV :
PV :
Last Update :
©2020 - 2024 By Oscar
Framework Hexo|Theme Butterfly