From e8559a3694aab705c957d354e1e2d0c3fe4df6b2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 14 Aug 2023 14:14:23 +0000 Subject: [PATCH] deploy: 58c2f1910c25222a6f7be735f072d17d34c850a0 --- 404.html | 4 ++-- assets/js/{aa540d67.61c37acd.js => aa540d67.04cf9097.js} | 2 +- .../{runtime~main.b4c9a6bf.js => runtime~main.3e2505d3.js} | 2 +- blog.html | 4 ++-- blog/2022/09/22/new-start.html | 4 ++-- blog/2023/01/08/learning-plan.html | 4 ++-- blog/archive.html | 4 ++-- blog/tags.html | 4 ++-- blog/tags/learning.html | 4 ++-- "blog/tags/\351\232\250\347\255\206.html" | 4 ++-- docs/collection/React.html | 4 ++-- docs/collection/front-end.html | 4 ++-- docs/collection/intro.html | 4 ++-- docs/collection/session-and-cookie.html | 4 ++-- docs/collection/web.html | 4 ++-- docs/notes/Git/git-basic-1.html | 4 ++-- docs/notes/HTML/metadata.html | 4 ++-- docs/notes/MySQL/install-mysql.html | 4 ++-- docs/notes/coding-style-guide/html-and-css.html | 4 ++-- docs/notes/coding-style-guide/javascript.html | 4 ++-- docs/notes/coding-style-guide/react.html | 4 ++-- docs/notes/data-structure/binary-tree-traversal.html | 4 ++-- docs/notes/data-structure/priority-queue.html | 4 ++-- docs/notes/data-structure/recursion.html | 6 +++--- docs/notes/data-structure/stack-and-queue.html | 4 ++-- docs/notes/data-structure/tree-and-binary-tree.html | 4 ++-- docs/notes/intro.html | 4 ++-- docs/notes/react/use-effect.html | 4 ++-- .../execution-contexts-and-lexical-Environments.html" | 4 ++-- .../objects-and-functions-part-1.html" | 4 ++-- .../objects-and-functions-part-2.html" | 4 ++-- .../types-and-operators.html" | 4 ++-- .../writing-a-good-pull-request.html" | 4 ++-- index.html | 4 ++-- 34 files changed, 67 insertions(+), 67 deletions(-) rename assets/js/{aa540d67.61c37acd.js => aa540d67.04cf9097.js} (99%) rename assets/js/{runtime~main.b4c9a6bf.js => runtime~main.3e2505d3.js} (98%) diff --git a/404.html b/404.html index 37c4bee..17df435 100644 --- a/404.html +++ b/404.html @@ -10,13 +10,13 @@ - +
Skip to main content

Page Not Found

We could not find what you were looking for.

Please contact the owner of the site that linked you to the original URL and let them know their link is broken.

- + \ No newline at end of file diff --git a/assets/js/aa540d67.61c37acd.js b/assets/js/aa540d67.04cf9097.js similarity index 99% rename from assets/js/aa540d67.61c37acd.js rename to assets/js/aa540d67.04cf9097.js index 92e0295..cd171c7 100644 --- a/assets/js/aa540d67.61c37acd.js +++ b/assets/js/aa540d67.04cf9097.js @@ -1 +1 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[2983],{3905:(a,e,t)=>{t.d(e,{Zo:()=>i,kt:()=>c});var s=t(7294);function m(a,e,t){return e in a?Object.defineProperty(a,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):a[e]=t,a}function n(a,e){var t=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(a,e).enumerable}))),t.push.apply(t,s)}return t}function p(a){for(var e=1;e=0||(m[t]=a[t]);return m}(a,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);for(s=0;s=0||Object.prototype.propertyIsEnumerable.call(a,t)&&(m[t]=a[t])}return m}var N=s.createContext({}),l=function(a){var e=s.useContext(N),t=e;return a&&(t="function"==typeof a?a(e):p(p({},e),a)),t},i=function(a){var e=l(a.components);return s.createElement(N.Provider,{value:e},a.children)},k={inlineCode:"code",wrapper:function(a){var e=a.children;return s.createElement(s.Fragment,{},e)}},o=s.forwardRef((function(a,e){var t=a.components,m=a.mdxType,n=a.originalType,N=a.parentName,i=r(a,["components","mdxType","originalType","parentName"]),o=l(t),c=m,h=o["".concat(N,".").concat(c)]||o[c]||k[c]||n;return t?s.createElement(h,p(p({ref:e},i),{},{components:t})):s.createElement(h,p({ref:e},i))}));function c(a,e){var t=arguments,m=e&&e.mdxType;if("string"==typeof a||m){var n=t.length,p=new Array(n);p[0]=o;var r={};for(var N in e)hasOwnProperty.call(e,N)&&(r[N]=e[N]);r.originalType=a,r.mdxType="string"==typeof a?a:m,p[1]=r;for(var l=2;l{t.r(e),t.d(e,{assets:()=>N,contentTitle:()=>p,default:()=>k,frontMatter:()=>n,metadata:()=>r,toc:()=>l});var s=t(7462),m=(t(7294),t(3905));const n={sidebar_position:0,title:"Recursion \u905e\u8ff4",date:new Date("2023-03-21T00:00:00.000Z")},p=void 0,r={unversionedId:"notes/data-structure/recursion",id:"notes/data-structure/recursion",title:"Recursion \u905e\u8ff4",description:"\ud83d\udc33 \u905e\u8ff4\u7684\u7a2e\u985e",source:"@site/docs/notes/data-structure/recursion.md",sourceDirName:"notes/data-structure",slug:"/notes/data-structure/recursion",permalink:"/notes/docs/notes/data-structure/recursion",draft:!1,editUrl:"https://github.com/SimoneCheng/notes/tree/main/docs/notes/data-structure/recursion.md",tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,title:"Recursion \u905e\u8ff4",date:"2023-03-21T00:00:00.000Z"},sidebar:"notes",previous:{title:"React",permalink:"/notes/docs/notes/coding-style-guide/react"},next:{title:"Stack and Queue \u5806\u758a\u8207\u4f47\u5217",permalink:"/notes/docs/notes/data-structure/stack-and-queue"}},N={},l=[{value:"\ud83d\udc33 \u905e\u8ff4\u7684\u7a2e\u985e",id:"-\u905e\u8ff4\u7684\u7a2e\u985e",level:2},{value:"\ud83e\udd80 Direct Recursion",id:"-direct-recursion",level:3},{value:"\ud83e\udd80 Indirect Recursion",id:"-indirect-recursion",level:3},{value:"\ud83e\udd80 Tail Recursion",id:"-tail-recursion",level:3},{value:"\ud83d\udc33 Recursion v.s. Iteration(Non-recusrion)",id:"-recursion-vs-iterationnon-recusrion",level:2},{value:"\u793a\u610f\u5716",id:"\u793a\u610f\u5716",level:4},{value:"\u6bd4\u8f03\u8868",id:"\u6bd4\u8f03\u8868",level:4},{value:"\ud83d\udc33 \u984c\u76ee\u7df4\u7fd2",id:"-\u984c\u76ee\u7df4\u7fd2",level:2},{value:"\ud83e\udd80 Factorial N! \u968e\u4e58",id:"-factorial-n-\u968e\u4e58",level:3},{value:"Question 1: Write an Interative function Fac(N) or pseudo code for N!",id:"question-1-write-an-interative-function-facn-or-pseudo-code-for-n",level:4},{value:"Question 2: Write a Recursive function Fac(N) or pseudo code for N!",id:"question-2-write-a-recursive-function-facn-or-pseudo-code-for-n",level:4},{value:"\ud83e\udd80 Fibonacci Number",id:"-fibonacci-number",level:3},{value:"Definition",id:"definition",level:4},{value:"Question 1: Write a Recurisive function for Fib(N)",id:"question-1-write-a-recurisive-function-for-fibn",level:4},{value:"Quesiton 2: Write a Interative function for Fib(N)",id:"quesiton-2-write-a-interative-function-for-fibn",level:4},{value:"\ud83e\udd80 Greatest Common Divisor (GCD) \u6700\u5927\u516c\u56e0\u6578",id:"-greatest-common-divisor-gcd-\u6700\u5927\u516c\u56e0\u6578",level:3},{value:"Definition",id:"definition-1",level:4},{value:"Write the recursive code for GCD(A, B)",id:"write-the-recursive-code-for-gcda-b",level:4},{value:"\ud83e\udd80 Tower of Hanoi \u6cb3\u5167\u5854",id:"-tower-of-hanoi-\u6cb3\u5167\u5854",level:3},{value:"\u984c\u76ee\u6558\u8ff0",id:"\u984c\u76ee\u6558\u8ff0",level:4},{value:"\u89e3\u984c\u601d\u8def",id:"\u89e3\u984c\u601d\u8def",level:4},{value:"\u6cb3\u5167\u5854\u7684\u905e\u8ff4\u5b9a\u7fa9",id:"\u6cb3\u5167\u5854\u7684\u905e\u8ff4\u5b9a\u7fa9",level:4}],i={toc:l};function k(a){let{components:e,...t}=a;return(0,m.kt)("wrapper",(0,s.Z)({},i,t,{components:e,mdxType:"MDXLayout"}),(0,m.kt)("h2",{id:"-\u905e\u8ff4\u7684\u7a2e\u985e"},"\ud83d\udc33 \u905e\u8ff4\u7684\u7a2e\u985e"),(0,m.kt)("p",null,"\u5982\u679c\u4e00\u500b function \u88e1\u9762\u6709 self-calling \u7684\u6558\u8ff0\uff0c\u4fbf\u7a31\u70ba\u905e\u8ff4\uff0c\u905e\u8ff4\u6982\u7565\u53ef\u4ee5\u5206\u70ba\u4e09\u500b\u7a2e\u985e\uff0c\u5206\u5225\u662f\uff1a"),(0,m.kt)("ul",null,(0,m.kt)("li",{parentName:"ul"},"Direct Recursion"),(0,m.kt)("li",{parentName:"ul"},"Indirect Recursion"),(0,m.kt)("li",{parentName:"ul"},"Tail Recursion")),(0,m.kt)("p",null,"\u4e0b\u9762\u8209\u4e00\u4e9b\u7c21\u55ae\u7684\u4f8b\u5b50\u4f86\u8aaa\u660e\u9019\u4e09\u500b\u905e\u8ff4\u3002"),(0,m.kt)("h3",{id:"-direct-recursion"},"\ud83e\udd80 Direct Recursion"),(0,m.kt)("p",null,"Direct Recursion\uff0c\u76f4\u63a5\u905e\u8ff4\uff0c\u61c9\u8a72\u883b\u597d\u7406\u89e3\u7684\u3002\u5982\u679c\u67d0\u500b function \u5728 function \u5167\u90e8\u547c\u53eb\u81ea\u5df1\uff0c\u5c31\u53ef\u4ee5\u7a31\u70ba\u76f4\u63a5\u905e\u8ff4\u3002\u53ef\u4ee5\u53c3\u8003\u4e0b\u9762\u7684 psuedo code\uff1a"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-c"},"void directRecursionFunction()\n{\n // some code...\n\n directRecursionFunction();\n\n // some code...\n}\n")),(0,m.kt)("h3",{id:"-indirect-recursion"},"\ud83e\udd80 Indirect Recursion"),(0,m.kt)("p",null,"Indirect Recursion\uff0c\u9593\u63a5\u905e\u8ff4\uff0c\u610f\u601d\u662f\u6307\u591a\u500b module \u4e4b\u9593\uff0c\u5f7c\u6b64\u4e92\u76f8\u547c\u53eb\uff0c\u5f62\u6210 calling cycle\u3002\u4f8b\u5982\uff1a\u5047\u8a2d\u76ee\u524d\u6709\u4e09\u500b function\uff1a",(0,m.kt)("inlineCode",{parentName:"p"},"module A"),"\u3001",(0,m.kt)("inlineCode",{parentName:"p"},"module B"),"\u3001",(0,m.kt)("inlineCode",{parentName:"p"},"module C"),"\uff0c\u9019\u4e09\u500b function \u5f7c\u6b64\u4e92\u76f8\u547c\u53eb\uff0c\u4fbf\u6703\u5f62\u6210\u9593\u63a5\u905e\u8ff4\uff0c\u5982\u4e0b\u5716\u3002"),(0,m.kt)("mermaid",{value:"flowchart LR\n A[module A] --\x3e B[module B]\n B --\x3e C[module C]\n C --\x3e A"}),(0,m.kt)("admonition",{type:"note"},(0,m.kt)("p",{parentName:"admonition"},"\u50cf\u4e0a\u9762\u90a3\u7a2e function \u4e92\u76f8 call \u4f86 call \u53bb\uff0c\u4e92\u76f8\u9ad8\u5ea6\u4f9d\u8cf4\u7684\u72c0\u6cc1\uff08\u9ad8\u8026\u5408\uff09\uff0c\u76e1\u91cf\u4e0d\u8981\u5728\u5be6\u969b\u958b\u767c\u4e2d\u5beb\u51fa\u4f86\uff0c\u6703\u5f88\u53ef\u6015\u3002")),(0,m.kt)("h3",{id:"-tail-recursion"},"\ud83e\udd80 Tail Recursion"),(0,m.kt)("p",null,"Tail Recursion\uff0c\u5c3e\u7aef\u905e\u8ff4\uff0c\u5176\u5be6\u662f\u76f4\u63a5\u905e\u8ff4\u7684\u4e00\u7a2e\uff0c\u53ea\u662f\u5728 recursion \u4e4b\u5f8c\uff0c\u4e0b\u4e00\u500b\u53ef\u57f7\u884c\u7684\u6558\u8ff0\u5c31\u662f END \u6558\u8ff0\u3002\u6703\u7279\u5225\u628a\u9019\u500b\u7a2e\u985e\u5e16\u51fa\u4f86\u662f\u56e0\u70ba\u9019\u7a2e\u5730\u56de\u53ef\u4ee5\u5728 compiler \u88e1\u9762\u505a\u5230\u6700\u4f73\u5316\u3002\uff08\u6700\u4f73\u5316\u7684\u610f\u601d\uff0c\u67d0\u7a2e\u7a0b\u5ea6\u4e0a\u53ef\u4ee5\u7406\u89e3\u6210\u300c\u5c07\u905e\u8ff4\u6539\u6210\u975e\u905e\u8ff4\u300d\uff09"),(0,m.kt)("h2",{id:"-recursion-vs-iterationnon-recusrion"},"\ud83d\udc33 Recursion v.s. Iteration(Non-recusrion)"),(0,m.kt)("ul",null,(0,m.kt)("li",{parentName:"ul"},"\u4efb\u4f55\u554f\u984c\u7684\u89e3\u6cd5\u5fc5\u5b9a\u53ef\u4ee5\u7528\u5169\u7a2e\u6f14\u7b97\u6cd5\u53bb\u89e3\u6c7a\uff1a\u905e\u8ff4\u8207\u975e\u905e\u8ff4\u3002"),(0,m.kt)("li",{parentName:"ul"},"\u905e\u8ff4\u8207\u975e\u905e\u8ff4\u6f14\u7b97\u6cd5\u5169\u8005\u53ef\u4ee5\u4e92\u76f8\u8f49\u63db",(0,m.kt)("ul",{parentName:"li"},(0,m.kt)("li",{parentName:"ul"},"\u905e\u8ff4\u6539\u70ba\u975e\u905e\u8ff4\uff0c\u6709\u6a19\u6e96 SOP"),(0,m.kt)("li",{parentName:"ul"},"\u975e\u905e\u8ff4\u6539\u56de\u905e\u8ff4\uff0c\u6c92\u6709\u6a19\u6e96 SOP\uff08\u9700\u8981\u9748\u611f\uff09")))),(0,m.kt)("h4",{id:"\u793a\u610f\u5716"},"\u793a\u610f\u5716"),(0,m.kt)("mermaid",{value:"graph BT\n B[Problem]\n A[Recustive Algo] --\x3e B\n C[Non-recursive Algo] --\x3e B\n A -. \u8981\u4fee\u6539\u7684\u8a71\u6709SOP .-> C\n C -. \u5fc5\u5b58\u5728,\u4f46\u6c92\u6709SOP .-> A"}),(0,m.kt)("h4",{id:"\u6bd4\u8f03\u8868"},"\u6bd4\u8f03\u8868"),(0,m.kt)("table",null,(0,m.kt)("thead",{parentName:"table"},(0,m.kt)("tr",{parentName:"thead"},(0,m.kt)("th",{parentName:"tr",align:null}),(0,m.kt)("th",{parentName:"tr",align:null},"\u905e\u8ff4"),(0,m.kt)("th",{parentName:"tr",align:null},"\u975e\u905e\u8ff4"))),(0,m.kt)("tbody",{parentName:"table"},(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"\u7a0b\u5f0f\u78bc"),(0,m.kt)("td",{parentName:"tr",align:null},"\u8f03\u7cbe\u7c21"),(0,m.kt)("td",{parentName:"tr",align:null},"\u8f03\u5197\u9577")),(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"\u5340\u57df\u8b8a\u6578\u3001\u66ab\u5b58\u8b8a\u6578"),(0,m.kt)("td",{parentName:"tr",align:null},"\u4f7f\u7528\u5f88\u5c11\u6216\u662f\u6c92\u6709"),(0,m.kt)("td",{parentName:"tr",align:null},"\u4f7f\u7528\u91cf\u591a")),(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"\u8868\u9054\u554f\u984c\u7684\u80fd\u529b"),(0,m.kt)("td",{parentName:"tr",align:null},"powerful"),(0,m.kt)("td",{parentName:"tr",align:null},"weak")),(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"\u9664\u932f"),(0,m.kt)("td",{parentName:"tr",align:null},"\u56f0\u96e3"),(0,m.kt)("td",{parentName:"tr",align:null},"\u5bb9\u6613")),(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"\u7a0b\u5f0f\u57f7\u884c\u6642\u9593"),(0,m.kt)("td",{parentName:"tr",align:null},"\u8f03\u4e45\uff0c\u6bd4\u8f03\u6c92\u6709\u6548\u7387"),(0,m.kt)("td",{parentName:"tr",align:null},"\u8f03\u77ed\uff0c\u8f03\u6709\u6548\u7387")),(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"memory stack \u7a7a\u9593"),(0,m.kt)("td",{parentName:"tr",align:null},"\u9700\u8981\u984d\u5916\u7684 stack \u7a7a\u9593\u652f\u6301\uff0c\u6240\u4ee5\u57f7\u884c\u6642\u9700\u8981\u8f03\u591a\u7684\u52d5\u614b\u7a7a\u9593"),(0,m.kt)("td",{parentName:"tr",align:null},"\u7121\u9700 stack support")))),(0,m.kt)("h2",{id:"-\u984c\u76ee\u7df4\u7fd2"},"\ud83d\udc33 \u984c\u76ee\u7df4\u7fd2"),(0,m.kt)("h3",{id:"-factorial-n-\u968e\u4e58"},"\ud83e\udd80 Factorial N! \u968e\u4e58"),(0,m.kt)("h4",{id:"question-1-write-an-interative-function-facn-or-pseudo-code-for-n"},"Question 1: Write an Interative function Fac(N) or pseudo code for N!"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function fac(n) {\n let result = 1;\n for (let i = 1; i <= n; i++>) {\n result = result * i;\n }\n return result;\n}\n")),(0,m.kt)("h4",{id:"question-2-write-a-recursive-function-facn-or-pseudo-code-for-n"},"Question 2: Write a Recursive function Fac(N) or pseudo code for N!"),(0,m.kt)("p",null,"\u5148\u628a\u968e\u4e58\u7684\u905e\u8ff4\u6578\u5b78\u5b9a\u7fa9\u5beb\u51fa\u4f86\uff1a"),(0,m.kt)("div",{className:"math math-display"},(0,m.kt)("span",{parentName:"div",className:"katex-display"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"!"),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mrow",{parentName:"mrow"},(0,m.kt)("mo",{parentName:"mrow",fence:"true"},"{"),(0,m.kt)("mtable",{parentName:"mrow",rowspacing:"0.36em",columnalign:"left left",columnspacing:"1em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"i"),(0,m.kt)("mi",{parentName:"mrow"},"f"),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",mathvariant:"normal"},"\u2260"),(0,m.kt)("mn",{parentName:"mrow"},"0"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"!"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"i"),(0,m.kt)("mi",{parentName:"mrow"},"f"),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},">"),(0,m.kt)("mn",{parentName:"mrow"},"0")))))))),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"n! = \\begin{cases} 1,\\ if\\ n \\ne 0 \\\\ (n-1)! * n,\\ if\\ n > 0 \\end{cases}")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"0.6944em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},"!"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}})),(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"3em",verticalAlign:"-1.25em"}}),(0,m.kt)("span",{parentName:"span",className:"minner"},(0,m.kt)("span",{parentName:"span",className:"mopen delimcenter",style:{top:"0em"}},(0,m.kt)("span",{parentName:"span",className:"delimsizing size4"},"{")),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-l"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.69em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.69em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"i"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.10764em"}},"f"),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},(0,m.kt)("span",{parentName:"span",className:"mrel"},(0,m.kt)("span",{parentName:"span",className:"mord vbox"},(0,m.kt)("span",{parentName:"span",className:"thinbox"},(0,m.kt)("span",{parentName:"span",className:"rlap"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"0.8889em",verticalAlign:"-0.1944em"}}),(0,m.kt)("span",{parentName:"span",className:"inner"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mrel"},"\ue020"))),(0,m.kt)("span",{parentName:"span",className:"fix"}))))),(0,m.kt)("span",{parentName:"span",className:"mrel"},"=")),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"0"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.25em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")!"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"i"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.10764em"}},"f"),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},">"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"0")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.19em"}},(0,m.kt)("span",{parentName:"span"}))))))),(0,m.kt)("span",{parentName:"span",className:"mclose nulldelimiter"}))))))),(0,m.kt)("p",null,"\u7136\u5f8c\u518d\u5beb\u51fa\u905e\u8ff4\u7684\u7a0b\u5f0f\u78bc\uff1a"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function fac(n) {\n if (n === 0) {\n return 1;\n } else {\n return fac(n-1) * n;\n }\n}\n")),(0,m.kt)("admonition",{type:"tip"},(0,m.kt)("p",{parentName:"admonition"},"\u89e3\u905e\u8ff4\u76f8\u95dc\u554f\u984c\u7684\u8a23\u7ac5\uff1a\u5148\u60f3\u51fa\u905e\u8ff4\u7684\u6578\u5b78\u5b9a\u7fa9\uff0c\u518d\u628a\u6578\u5b78\u5b9a\u7fa9\u8f49\u63db\u6210\u7a0b\u5f0f\u78bc\uff01")),(0,m.kt)("h3",{id:"-fibonacci-number"},"\ud83e\udd80 Fibonacci Number"),(0,m.kt)("h4",{id:"definition"},"Definition"),(0,m.kt)("div",{className:"math math-display"},(0,m.kt)("span",{parentName:"div",className:"katex-display"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mo",{parentName:"mrow",fence:"true"},"{"),(0,m.kt)("mtable",{parentName:"mrow",rowspacing:"0.36em",columnalign:"left left",columnspacing:"1em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("msub",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"msub"},"F"),(0,m.kt)("mn",{parentName:"msub"},"0")),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"0"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("msub",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"msub"},"F"),(0,m.kt)("mn",{parentName:"msub"},"1")),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"1"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("msub",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"msub"},"F"),(0,m.kt)("mi",{parentName:"msub"},"n")),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("msub",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"msub"},"F"),(0,m.kt)("mrow",{parentName:"msub"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("msub",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"msub"},"F"),(0,m.kt)("mrow",{parentName:"msub"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"2"))),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"f"),(0,m.kt)("mi",{parentName:"mrow"},"o"),(0,m.kt)("mi",{parentName:"mrow"},"r"),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2265"),(0,m.kt)("mn",{parentName:"mrow"},"2"))))))),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"\\begin{cases} F_{0} = 0 \\\\ F_{1} = 1 \\\\ F_{n} = F_{n-1} + F_{n-2},\\ for\\ n \\ge 2 \\end{cases}")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"4.32em",verticalAlign:"-1.91em"}}),(0,m.kt)("span",{parentName:"span",className:"minner"},(0,m.kt)("span",{parentName:"span",className:"mopen"},(0,m.kt)("span",{parentName:"span",className:"delimsizing mult"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"2.35em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.2em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.15em"}}),(0,m.kt)("span",{parentName:"span",className:"delimsizinginner delim-size4"},(0,m.kt)("span",{parentName:"span"},"\u23a9"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.192em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.15em"}}),(0,m.kt)("span",{parentName:"span",style:{height:"0.316em",width:"0.8889em"}},(0,m.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"0.8889em",height:"0.316em",style:{width:"0.8889em"},viewBox:"0 0 888.89 316",preserveAspectRatio:"xMinYMin"},(0,m.kt)("path",{parentName:"svg",d:"M384 0 H504 V316 H384z M384 0 H504 V316 H384z"})))),(0,m.kt)("span",{parentName:"span",style:{top:"-3.15em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.15em"}}),(0,m.kt)("span",{parentName:"span",className:"delimsizinginner delim-size4"},(0,m.kt)("span",{parentName:"span"},"\u23a8"))),(0,m.kt)("span",{parentName:"span",style:{top:"-4.292em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.15em"}}),(0,m.kt)("span",{parentName:"span",style:{height:"0.316em",width:"0.8889em"}},(0,m.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"0.8889em",height:"0.316em",style:{width:"0.8889em"},viewBox:"0 0 888.89 316",preserveAspectRatio:"xMinYMin"},(0,m.kt)("path",{parentName:"svg",d:"M384 0 H504 V316 H384z M384 0 H504 V316 H384z"})))),(0,m.kt)("span",{parentName:"span",style:{top:"-4.6em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.15em"}}),(0,m.kt)("span",{parentName:"span",className:"delimsizinginner delim-size4"},(0,m.kt)("span",{parentName:"span"},"\u23a7")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.85em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-l"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"2.41em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-4.41em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"F"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.3011em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.55em",marginLeft:"-0.1389em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"0"))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.15em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"0"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.97em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"F"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.3011em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.55em",marginLeft:"-0.1389em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.15em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"))),(0,m.kt)("span",{parentName:"span",style:{top:"-1.53em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"F"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.1514em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.55em",marginLeft:"-0.1389em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.15em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"F"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.3011em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.55em",marginLeft:"-0.1389em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.2083em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"F"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.3011em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.55em",marginLeft:"-0.1389em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"2"))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.2083em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.10764em"}},"f"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.02778em"}},"or"),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"\u2265"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.91em"}},(0,m.kt)("span",{parentName:"span"}))))))),(0,m.kt)("span",{parentName:"span",className:"mclose nulldelimiter"}))))))),(0,m.kt)("h4",{id:"question-1-write-a-recurisive-function-for-fibn"},"Question 1: Write a Recurisive function for Fib(N)"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function fib(n) {\n if (n === 0) {\n return 0;\n }\n if (n === 1) {\n return 1;\n }\n return fib(n-1) + fib(n-2);\n}\n")),(0,m.kt)("h4",{id:"quesiton-2-write-a-interative-function-for-fibn"},"Quesiton 2: Write a Interative function for Fib(N)"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function fib(n) {\n if (n === 0) {\n return 0;\n } else if (n === 1) {\n return 1;\n } else {\n let a = 0;\n let b = 1;\n let c;\n for (let i = 2; i <= n; i++) {\n c = a + b;\n a = b;\n b = c;\n }\n return c;\n }\n}\n")),(0,m.kt)("h3",{id:"-greatest-common-divisor-gcd-\u6700\u5927\u516c\u56e0\u6578"},"\ud83e\udd80 Greatest Common Divisor (GCD) \u6700\u5927\u516c\u56e0\u6578"),(0,m.kt)("h4",{id:"definition-1"},"Definition"),(0,m.kt)("p",null,"\u7528\u8f3e\u8f49\u76f8\u9664\u6cd5\u4f86\u8a08\u7b97\u5169\u500b\u6578\u5b57\uff08A, B\uff09\u7684\u6700\u5927\u516c\u56e0\u6578\uff0c\u5b9a\u7fa9\u5982\u4e0b\uff1a"),(0,m.kt)("div",{className:"math math-display"},(0,m.kt)("span",{parentName:"div",className:"katex-display"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mo",{parentName:"mrow",fence:"true"},"{"),(0,m.kt)("mtable",{parentName:"mrow",rowspacing:"0.36em",columnalign:"left left",columnspacing:"1em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mi",{parentName:"mrow"},"B"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"i"),(0,m.kt)("mi",{parentName:"mrow"},"f"),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"A"),(0,m.kt)("mspace",{parentName:"mrow"}),(0,m.kt)("mspace",{parentName:"mrow",width:"0.6667em"}),(0,m.kt)("mrow",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"m"),(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"o"),(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"d")),(0,m.kt)("mtext",{parentName:"mrow"},"\u2009"),(0,m.kt)("mtext",{parentName:"mrow"},"\u2009"),(0,m.kt)("mi",{parentName:"mrow"},"B"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"0"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mi",{parentName:"mrow"},"G"),(0,m.kt)("mi",{parentName:"mrow"},"C"),(0,m.kt)("mi",{parentName:"mrow"},"D"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"B"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mi",{parentName:"mrow"},"A"),(0,m.kt)("mspace",{parentName:"mrow"}),(0,m.kt)("mspace",{parentName:"mrow",width:"0.6667em"}),(0,m.kt)("mrow",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"m"),(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"o"),(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"d")),(0,m.kt)("mtext",{parentName:"mrow"},"\u2009"),(0,m.kt)("mtext",{parentName:"mrow"},"\u2009"),(0,m.kt)("mi",{parentName:"mrow"},"B"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"o"),(0,m.kt)("mi",{parentName:"mrow"},"t"),(0,m.kt)("mi",{parentName:"mrow"},"h"),(0,m.kt)("mi",{parentName:"mrow"},"e"),(0,m.kt)("mi",{parentName:"mrow"},"r"),(0,m.kt)("mi",{parentName:"mrow"},"w"),(0,m.kt)("mi",{parentName:"mrow"},"i"),(0,m.kt)("mi",{parentName:"mrow"},"s"),(0,m.kt)("mi",{parentName:"mrow"},"e"))))))),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"\\begin{cases} B,\\ if\\ (A \\mod B) = 0 \\\\ GCD(B, A \\mod B),\\ otherwise \\end{cases}")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"3em",verticalAlign:"-1.25em"}}),(0,m.kt)("span",{parentName:"span",className:"minner"},(0,m.kt)("span",{parentName:"span",className:"mopen delimcenter",style:{top:"0em"}},(0,m.kt)("span",{parentName:"span",className:"delimsizing size4"},"{")),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-l"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.69em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.69em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.05017em"}},"B"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"i"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.10764em"}},"f"),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"A"),(0,m.kt)("span",{parentName:"span",className:"mspace allowbreak"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.6667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathrm"},"mod"))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.05017em"}},"B"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"0"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.25em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.07153em"}},"GC"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.02778em"}},"D"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.05017em"}},"B"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"A"),(0,m.kt)("span",{parentName:"span",className:"mspace allowbreak"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.6667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathrm"},"mod"))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.05017em"}},"B"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"o"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"t"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"h"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.02778em"}},"er"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.02691em"}},"w"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"i"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"se")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.19em"}},(0,m.kt)("span",{parentName:"span"}))))))),(0,m.kt)("span",{parentName:"span",className:"mclose nulldelimiter"}))))))),(0,m.kt)("h4",{id:"write-the-recursive-code-for-gcda-b"},"Write the recursive code for GCD(A, B)"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function gcd(a, b) {\n if (a % b === 0) return b;\n return gcd(b, a % b);\n}\n")),(0,m.kt)("h3",{id:"-tower-of-hanoi-\u6cb3\u5167\u5854"},"\ud83e\udd80 Tower of Hanoi \u6cb3\u5167\u5854"),(0,m.kt)("h4",{id:"\u984c\u76ee\u6558\u8ff0"},"\u984c\u76ee\u6558\u8ff0"),(0,m.kt)("p",null,"\u6709\u4e09\u500b\u67f1\u5b50\uff0c\u5047\u8a2d\u5206\u5225\u53eb\u505a A\u3001B\u3001C\uff0c\u5176\u4e2d A \u67f1\u5b50\u4e0a\u6709 n \u500b\u5927\u5c0f\u4e0d\u540c\u7684\u76e4\u5b50\uff0c\u9019\u4e9b\u76e4\u5b50\u5f9e\u4e0a\u5230\u4e0b\u6309\u7167\u5927\u5c0f\u6392\u653e\uff0c\u6700\u4e0a\u9762\u7684\u76e4\u5b50\u6700\u5c0f\uff0c\u6700\u4e0b\u9762\u7684\u76e4\u5b50\u6700\u5927\uff0c\u73fe\u5728\u8981\u628a\u9019\u4e9b\u76e4\u5b50\u5f9e A \u67f1\u5b50\u79fb\u5230 C \u67f1\u5b50\uff0c\u4f46\u5fc5\u9808\u9075\u5b88\u4ee5\u4e0b\u898f\u5247\uff1a"),(0,m.kt)("ol",null,(0,m.kt)("li",{parentName:"ol"},"\u6bcf\u6b21\u53ea\u80fd\u79fb\u52d5\u4e00\u500b\u76e4\u5b50"),(0,m.kt)("li",{parentName:"ol"},"\u5927\u7684\u76e4\u5b50\u4e0d\u80fd\u653e\u5728\u5c0f\u7684\u76e4\u5b50\u4e0a\u9762")),(0,m.kt)("p",null,"\u8acb\u628a\u6240\u6709\u7684\u79fb\u52d5\u6b65\u9a5f\u90fd print \u51fa\u4f86\u3002"),(0,m.kt)("h4",{id:"\u89e3\u984c\u601d\u8def"},"\u89e3\u984c\u601d\u8def"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre"}," A B C\n\n \u2502 \u2502 \u2502\n \u2502 \u2502 \u2502\n \u2502 \u2502 \u2502\n1 \u250c\u2500\u253c\u2500\u2510 \u2502 \u2502\n2 \u250c\u253c\u253c\u253c\u253c\u253c\u2510 \u2502 \u2502\n3 \u250c\u253c\u253c\u253c\u253c\u253c\u253c\u253c\u2510 \u2502 \u2502\n \u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500 \u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\n")),(0,m.kt)("p",null,"\u5148\u5f9e\u4f8b\u5b50\u958b\u59cb\u60f3\uff0c\u5047\u8a2d\u76ee\u524d\u6709 A\u3001B\u3001C \u4e09\u500b\u67f1\u5b50\uff0c\u7136\u5f8c\u6709 3 \u500b\u76e4\u5b50\u5728 A \u67f1\u5b50\u4e0a\u9762\uff0c\u5247\u6b65\u9a5f\u5982\u4e0b\uff1a"),(0,m.kt)("hr",null),(0,m.kt)("ol",null,(0,m.kt)("li",{parentName:"ol"},"move disk 1 from A to C"),(0,m.kt)("li",{parentName:"ol"},"move disk 2 from A to B"),(0,m.kt)("li",{parentName:"ol"},"move disk 1 from C to B")),(0,m.kt)("hr",null),(0,m.kt)("ol",{start:4},(0,m.kt)("li",{parentName:"ol"},"move disk 3 from A to C")),(0,m.kt)("hr",null),(0,m.kt)("ol",{start:5},(0,m.kt)("li",{parentName:"ol"},"move disk 1 from B to A"),(0,m.kt)("li",{parentName:"ol"},"move disk 2 from B to C"),(0,m.kt)("li",{parentName:"ol"},"move disk 1 from A to C")),(0,m.kt)("hr",null),(0,m.kt)("p",null,"\u628a\u6b65\u9a5f\u5206\u6210\u4e09\u500b\u5340\u584a\u4f86\u770b\uff1a"),(0,m.kt)("ol",null,(0,m.kt)("li",{parentName:"ol"},"\u7b2c 1. ~ 3. \u6b65\u9a5f\u662f\u628a 1 ~ 2 \u865f\u7684\u76e4\u5b50\u90fd\u5148\u5f9e A \u67f1\u5b50\u79fb\u5230 B \u67f1\u5b50"),(0,m.kt)("li",{parentName:"ol"},"\u7b2c 4. \u6b65\u9a5f\u662f\u628a\u6700\u5f8c\u4e00\u500b\u7b2c 3 \u865f\u76e4\u5b50\u76f4\u63a5\u5f9e A \u67f1\u5b50\u79fb\u5230 C \u67f1\u5b50"),(0,m.kt)("li",{parentName:"ol"},"\u63a5\u4e0b\u4f86\u662f\u628a B \u67f1\u5b50\u4e0a\u7684\u76e4\u5b50\u90fd\u79fb\u5230 C \u67f1\u5b50")),(0,m.kt)("p",null,"\u4f8b\u5916\u60c5\u6cc1\uff1a\u5982\u679c\u53ea\u6709\u4e00\u500b\u76e4\u5b50\u7684\u8a71\uff0c\u5c31\u76f4\u63a5\u5f9e A \u67f1\u5b50\u642c\u5230 C \u67f1\u5b50\u5c31\u53ef\u4ee5\u4e86\u3002"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function hanoi(n, from, to, via) {\n if (n === 1) {\n console.log(`move disk 1 from ${from} to ${to}`);\n } else {\n hanoi(n - 1, from, via, to); // \u5148\u628a n - 1 \u500b\u76e4\u5b50\u90fd\u79fb\u5230\u4e2d\u9593\u7684\u67f1\u5b50\n console.log(`move disk ${n} from ${from} to ${to}`); // \u628a\u6700\u4e0b\u9762\u7684\u76e4\u5b50\u79fb\u5230\u76ee\u6a19\u67f1\u5b50\n hanoi(n - 1, via, to, from); // \u518d\u628a\u5269\u4e0b\u7684 n - 1 \u500b\u76e4\u5b50\u79fb\u5230\u76ee\u6a19\u67f1\u5b50\n }\n}\n")),(0,m.kt)("h4",{id:"\u6cb3\u5167\u5854\u7684\u905e\u8ff4\u5b9a\u7fa9"},"\u6cb3\u5167\u5854\u7684\u905e\u8ff4\u5b9a\u7fa9"),(0,m.kt)("p",null,"\u628a\u4e0a\u9762\u63d0\u5230\u7684\u6b65\u9a5f\u7528\u6578\u5b78\u5f0f\u4f86\u8868\u793a\uff0c",(0,m.kt)("span",{parentName:"p",className:"math math-inline"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"T(n)")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")")))))," \u8868\u793a\u79fb\u52d5 n \u500b\u76e4\u5b50\u6642\u7a0b\u5f0f\u6240\u9700\u7684\u57f7\u884c\u6b21\u6578\uff0c\u5982\u679c\u89e3\u51fa ",(0,m.kt)("span",{parentName:"p",className:"math math-inline"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"T(n)")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")")))))," \u5c31\u8868\u793a\u89e3\u51fa\u4e86\u9019\u500b function \u7684\u6642\u9593\u8907\u96dc\u5ea6\uff1a"),(0,m.kt)("div",{className:"math math-display"},(0,m.kt)("span",{parentName:"div",className:"katex-display"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mtable",{parentName:"semantics",rowspacing:"0.16em",columnspacing:"1em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mtable",{parentName:"mstyle",rowspacing:"0.25em",columnalign:"right left",columnspacing:"0em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0\u4e14\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"1"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1")))))))))),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"\\begin{equation*} \\begin{split} T(n) &= T(n - 1) + 1 + T(n - 1),\\ \u4e14\\ T(1) = 1\\\\ &= 2T(n - 1) + 1 \\end{split} \\end{equation*}")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"3em",verticalAlign:"-1.25em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-c"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.75em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.75em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.75em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-r"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.75em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.91em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.41em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"}))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.25em"}},(0,m.kt)("span",{parentName:"span"}))))),(0,m.kt)("span",{parentName:"span",className:"col-align-l"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.75em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.91em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord cjk_fallback"},"\u4e14"),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.41em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.25em"}},(0,m.kt)("span",{parentName:"span"})))))))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.25em"}},(0,m.kt)("span",{parentName:"span"})))))))))))),(0,m.kt)("p",null,"\u89e3 ",(0,m.kt)("span",{parentName:"p",className:"math math-inline"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"T(n)")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))))),"\uff0c\u7528\u5c55\u958b\u4ee3\u5165\u6cd5\uff1a"),(0,m.kt)("div",{className:"math math-display"},(0,m.kt)("span",{parentName:"div",className:"katex-display"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mtable",{parentName:"semantics",rowspacing:"0.16em",columnspacing:"1em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mtable",{parentName:"mstyle",rowspacing:"0.25em",columnalign:"right left",columnspacing:"0em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"["),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"]"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"4"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"3"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"4"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"["),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"3"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"]"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"3"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"8"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"3"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"7"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"16"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"4"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"15"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mi",{parentName:"msup"},"n")),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow"},"\u2248"),(0,m.kt)("mi",{parentName:"mrow"},"O"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mi",{parentName:"msup"},"n")),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")))))))))),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"\\begin{equation*} \\begin{split} T(n) &= 2 * T(n - 1) + 1\\\\ &= 2 * [2 * T(n - 2) + 1] + 1\\\\ &= 4 * T(n - 2) + 3\\\\ &= 4 * [2 * T(n - 3) + 1] + 3\\\\ &= 8 * T(n - 3) + 7\\\\ &= 16 * T(n - 4) + 15\\\\ &= 2^{n-1} * T(n - (n - 1)) + (2^{n-1} - 1)\\\\ &= 2^{n-1} * T(1) + (2^{n-1} - 1)\\\\ &= 2^{n-1} + (2^{n-1} - 1)\\\\ &= 2^n - 1 \\approx O(2^n) \\end{split} \\end{equation*}")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"15.0723em",verticalAlign:"-7.2862em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-c"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.7862em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-9.7862em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"9.7862em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-r"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.7862em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-9.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))),(0,m.kt)("span",{parentName:"span",style:{top:"-8.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"-6.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"-5.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"-3.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"-2.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"-0.9221em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"0.6021em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"2.1262em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"3.6262em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"}))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.2862em"}},(0,m.kt)("span",{parentName:"span"}))))),(0,m.kt)("span",{parentName:"span",className:"col-align-l"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.7862em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-9.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"))),(0,m.kt)("span",{parentName:"span",style:{top:"-8.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"["),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},"]"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"))),(0,m.kt)("span",{parentName:"span",style:{top:"-6.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"4"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"3"))),(0,m.kt)("span",{parentName:"span",style:{top:"-5.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"4"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"["),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"3"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},"]"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"3"))),(0,m.kt)("span",{parentName:"span",style:{top:"-3.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"8"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"3"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"7"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"16"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"4"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"15"))),(0,m.kt)("span",{parentName:"span",style:{top:"-0.9221em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},"))"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))),(0,m.kt)("span",{parentName:"span",style:{top:"0.6021em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))),(0,m.kt)("span",{parentName:"span",style:{top:"2.1262em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))),(0,m.kt)("span",{parentName:"span",style:{top:"3.6262em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.7144em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n")))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"\u2248"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.02778em"}},"O"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.7144em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n")))))))),(0,m.kt)("span",{parentName:"span",className:"mclose"},")")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.2862em"}},(0,m.kt)("span",{parentName:"span"})))))))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.2862em"}},(0,m.kt)("span",{parentName:"span"})))))))))))))}k.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[2983],{3905:(a,e,t)=>{t.d(e,{Zo:()=>i,kt:()=>c});var s=t(7294);function m(a,e,t){return e in a?Object.defineProperty(a,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):a[e]=t,a}function n(a,e){var t=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);e&&(s=s.filter((function(e){return Object.getOwnPropertyDescriptor(a,e).enumerable}))),t.push.apply(t,s)}return t}function p(a){for(var e=1;e=0||(m[t]=a[t]);return m}(a,e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);for(s=0;s=0||Object.prototype.propertyIsEnumerable.call(a,t)&&(m[t]=a[t])}return m}var N=s.createContext({}),l=function(a){var e=s.useContext(N),t=e;return a&&(t="function"==typeof a?a(e):p(p({},e),a)),t},i=function(a){var e=l(a.components);return s.createElement(N.Provider,{value:e},a.children)},k={inlineCode:"code",wrapper:function(a){var e=a.children;return s.createElement(s.Fragment,{},e)}},o=s.forwardRef((function(a,e){var t=a.components,m=a.mdxType,n=a.originalType,N=a.parentName,i=r(a,["components","mdxType","originalType","parentName"]),o=l(t),c=m,h=o["".concat(N,".").concat(c)]||o[c]||k[c]||n;return t?s.createElement(h,p(p({ref:e},i),{},{components:t})):s.createElement(h,p({ref:e},i))}));function c(a,e){var t=arguments,m=e&&e.mdxType;if("string"==typeof a||m){var n=t.length,p=new Array(n);p[0]=o;var r={};for(var N in e)hasOwnProperty.call(e,N)&&(r[N]=e[N]);r.originalType=a,r.mdxType="string"==typeof a?a:m,p[1]=r;for(var l=2;l{t.r(e),t.d(e,{assets:()=>N,contentTitle:()=>p,default:()=>k,frontMatter:()=>n,metadata:()=>r,toc:()=>l});var s=t(7462),m=(t(7294),t(3905));const n={sidebar_position:0,title:"Recursion \u905e\u8ff4",date:new Date("2023-03-21T00:00:00.000Z")},p=void 0,r={unversionedId:"notes/data-structure/recursion",id:"notes/data-structure/recursion",title:"Recursion \u905e\u8ff4",description:"\ud83d\udc33 \u905e\u8ff4\u7684\u7a2e\u985e",source:"@site/docs/notes/data-structure/recursion.md",sourceDirName:"notes/data-structure",slug:"/notes/data-structure/recursion",permalink:"/notes/docs/notes/data-structure/recursion",draft:!1,editUrl:"https://github.com/SimoneCheng/notes/tree/main/docs/notes/data-structure/recursion.md",tags:[],version:"current",sidebarPosition:0,frontMatter:{sidebar_position:0,title:"Recursion \u905e\u8ff4",date:"2023-03-21T00:00:00.000Z"},sidebar:"notes",previous:{title:"React",permalink:"/notes/docs/notes/coding-style-guide/react"},next:{title:"Stack and Queue \u5806\u758a\u8207\u4f47\u5217",permalink:"/notes/docs/notes/data-structure/stack-and-queue"}},N={},l=[{value:"\ud83d\udc33 \u905e\u8ff4\u7684\u7a2e\u985e",id:"-\u905e\u8ff4\u7684\u7a2e\u985e",level:2},{value:"\ud83e\udd80 Direct Recursion",id:"-direct-recursion",level:3},{value:"\ud83e\udd80 Indirect Recursion",id:"-indirect-recursion",level:3},{value:"\ud83e\udd80 Tail Recursion",id:"-tail-recursion",level:3},{value:"\ud83d\udc33 Recursion v.s. Iteration(Non-recusrion)",id:"-recursion-vs-iterationnon-recusrion",level:2},{value:"\u793a\u610f\u5716",id:"\u793a\u610f\u5716",level:4},{value:"\u6bd4\u8f03\u8868",id:"\u6bd4\u8f03\u8868",level:4},{value:"\ud83d\udc33 \u984c\u76ee\u7df4\u7fd2",id:"-\u984c\u76ee\u7df4\u7fd2",level:2},{value:"\ud83e\udd80 Factorial N! \u968e\u4e58",id:"-factorial-n-\u968e\u4e58",level:3},{value:"Question 1: Write an Interative function Fac(N) or pseudo code for N!",id:"question-1-write-an-interative-function-facn-or-pseudo-code-for-n",level:4},{value:"Question 2: Write a Recursive function Fac(N) or pseudo code for N!",id:"question-2-write-a-recursive-function-facn-or-pseudo-code-for-n",level:4},{value:"\ud83e\udd80 Fibonacci Number",id:"-fibonacci-number",level:3},{value:"Definition",id:"definition",level:4},{value:"Question 1: Write a Recurisive function for Fib(N)",id:"question-1-write-a-recurisive-function-for-fibn",level:4},{value:"Quesiton 2: Write a Interative function for Fib(N)",id:"quesiton-2-write-a-interative-function-for-fibn",level:4},{value:"\ud83e\udd80 Greatest Common Divisor (GCD) \u6700\u5927\u516c\u56e0\u6578",id:"-greatest-common-divisor-gcd-\u6700\u5927\u516c\u56e0\u6578",level:3},{value:"Definition",id:"definition-1",level:4},{value:"Write the recursive code for GCD(A, B)",id:"write-the-recursive-code-for-gcda-b",level:4},{value:"\ud83e\udd80 Tower of Hanoi \u6cb3\u5167\u5854",id:"-tower-of-hanoi-\u6cb3\u5167\u5854",level:3},{value:"\u984c\u76ee\u6558\u8ff0",id:"\u984c\u76ee\u6558\u8ff0",level:4},{value:"\u89e3\u984c\u601d\u8def",id:"\u89e3\u984c\u601d\u8def",level:4},{value:"\u6cb3\u5167\u5854\u7684\u905e\u8ff4\u5b9a\u7fa9",id:"\u6cb3\u5167\u5854\u7684\u905e\u8ff4\u5b9a\u7fa9",level:4}],i={toc:l};function k(a){let{components:e,...t}=a;return(0,m.kt)("wrapper",(0,s.Z)({},i,t,{components:e,mdxType:"MDXLayout"}),(0,m.kt)("h2",{id:"-\u905e\u8ff4\u7684\u7a2e\u985e"},"\ud83d\udc33 \u905e\u8ff4\u7684\u7a2e\u985e"),(0,m.kt)("p",null,"\u5982\u679c\u4e00\u500b function \u88e1\u9762\u6709 self-calling \u7684\u6558\u8ff0\uff0c\u4fbf\u7a31\u70ba\u905e\u8ff4\uff0c\u905e\u8ff4\u6982\u7565\u53ef\u4ee5\u5206\u70ba\u4e09\u500b\u7a2e\u985e\uff0c\u5206\u5225\u662f\uff1a"),(0,m.kt)("ul",null,(0,m.kt)("li",{parentName:"ul"},"Direct Recursion"),(0,m.kt)("li",{parentName:"ul"},"Indirect Recursion"),(0,m.kt)("li",{parentName:"ul"},"Tail Recursion")),(0,m.kt)("p",null,"\u4e0b\u9762\u8209\u4e00\u4e9b\u7c21\u55ae\u7684\u4f8b\u5b50\u4f86\u8aaa\u660e\u9019\u4e09\u500b\u905e\u8ff4\u3002"),(0,m.kt)("h3",{id:"-direct-recursion"},"\ud83e\udd80 Direct Recursion"),(0,m.kt)("p",null,"Direct Recursion\uff0c\u76f4\u63a5\u905e\u8ff4\uff0c\u61c9\u8a72\u883b\u597d\u7406\u89e3\u7684\u3002\u5982\u679c\u67d0\u500b function \u5728 function \u5167\u90e8\u547c\u53eb\u81ea\u5df1\uff0c\u5c31\u53ef\u4ee5\u7a31\u70ba\u76f4\u63a5\u905e\u8ff4\u3002\u53ef\u4ee5\u53c3\u8003\u4e0b\u9762\u7684 psuedo code\uff1a"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-c"},"void directRecursionFunction()\n{\n // some code...\n\n directRecursionFunction();\n\n // some code...\n}\n")),(0,m.kt)("h3",{id:"-indirect-recursion"},"\ud83e\udd80 Indirect Recursion"),(0,m.kt)("p",null,"Indirect Recursion\uff0c\u9593\u63a5\u905e\u8ff4\uff0c\u610f\u601d\u662f\u6307\u591a\u500b module \u4e4b\u9593\uff0c\u5f7c\u6b64\u4e92\u76f8\u547c\u53eb\uff0c\u5f62\u6210 calling cycle\u3002\u4f8b\u5982\uff1a\u5047\u8a2d\u76ee\u524d\u6709\u4e09\u500b function\uff1a",(0,m.kt)("inlineCode",{parentName:"p"},"module A"),"\u3001",(0,m.kt)("inlineCode",{parentName:"p"},"module B"),"\u3001",(0,m.kt)("inlineCode",{parentName:"p"},"module C"),"\uff0c\u9019\u4e09\u500b function \u5f7c\u6b64\u4e92\u76f8\u547c\u53eb\uff0c\u4fbf\u6703\u5f62\u6210\u9593\u63a5\u905e\u8ff4\uff0c\u5982\u4e0b\u5716\u3002"),(0,m.kt)("mermaid",{value:"flowchart LR\n A[module A] --\x3e B[module B]\n B --\x3e C[module C]\n C --\x3e A"}),(0,m.kt)("admonition",{type:"note"},(0,m.kt)("p",{parentName:"admonition"},"\u50cf\u4e0a\u9762\u90a3\u7a2e function \u4e92\u76f8 call \u4f86 call \u53bb\uff0c\u4e92\u76f8\u9ad8\u5ea6\u4f9d\u8cf4\u7684\u72c0\u6cc1\uff08\u9ad8\u8026\u5408\uff09\uff0c\u76e1\u91cf\u4e0d\u8981\u5728\u5be6\u969b\u958b\u767c\u4e2d\u5beb\u51fa\u4f86\uff0c\u6703\u5f88\u53ef\u6015\u3002")),(0,m.kt)("h3",{id:"-tail-recursion"},"\ud83e\udd80 Tail Recursion"),(0,m.kt)("p",null,"Tail Recursion\uff0c\u5c3e\u7aef\u905e\u8ff4\uff0c\u5176\u5be6\u662f\u76f4\u63a5\u905e\u8ff4\u7684\u4e00\u7a2e\uff0c\u53ea\u662f\u5728 recursion \u4e4b\u5f8c\uff0c\u4e0b\u4e00\u500b\u53ef\u57f7\u884c\u7684\u6558\u8ff0\u5c31\u662f END \u6558\u8ff0\u3002\u6703\u7279\u5225\u628a\u9019\u500b\u7a2e\u985e\u5206\u51fa\u4f86\u662f\u56e0\u70ba\u9019\u7a2e\u905e\u8ff4\u53ef\u4ee5\u5728 compiler \u88e1\u9762\u505a\u5230\u6700\u4f73\u5316\u3002\uff08\u6700\u4f73\u5316\u7684\u610f\u601d\uff0c\u67d0\u7a2e\u7a0b\u5ea6\u4e0a\u53ef\u4ee5\u7406\u89e3\u6210\u300c\u5c07\u905e\u8ff4\u6539\u6210\u975e\u905e\u8ff4\u300d\uff09"),(0,m.kt)("h2",{id:"-recursion-vs-iterationnon-recusrion"},"\ud83d\udc33 Recursion v.s. Iteration(Non-recusrion)"),(0,m.kt)("ul",null,(0,m.kt)("li",{parentName:"ul"},"\u4efb\u4f55\u554f\u984c\u7684\u89e3\u6cd5\u5fc5\u5b9a\u53ef\u4ee5\u7528\u5169\u7a2e\u6f14\u7b97\u6cd5\u53bb\u89e3\u6c7a\uff1a\u905e\u8ff4\u8207\u975e\u905e\u8ff4\u3002"),(0,m.kt)("li",{parentName:"ul"},"\u905e\u8ff4\u8207\u975e\u905e\u8ff4\u6f14\u7b97\u6cd5\u5169\u8005\u53ef\u4ee5\u4e92\u76f8\u8f49\u63db",(0,m.kt)("ul",{parentName:"li"},(0,m.kt)("li",{parentName:"ul"},"\u905e\u8ff4\u6539\u70ba\u975e\u905e\u8ff4\uff0c\u6709\u6a19\u6e96 SOP"),(0,m.kt)("li",{parentName:"ul"},"\u975e\u905e\u8ff4\u6539\u56de\u905e\u8ff4\uff0c\u6c92\u6709\u6a19\u6e96 SOP\uff08\u9700\u8981\u9748\u611f\uff09")))),(0,m.kt)("h4",{id:"\u793a\u610f\u5716"},"\u793a\u610f\u5716"),(0,m.kt)("mermaid",{value:"graph BT\n B[Problem]\n A[Recustive Algo] --\x3e B\n C[Non-recursive Algo] --\x3e B\n A -. \u8981\u4fee\u6539\u7684\u8a71\u6709SOP .-> C\n C -. \u5fc5\u5b58\u5728,\u4f46\u6c92\u6709SOP .-> A"}),(0,m.kt)("h4",{id:"\u6bd4\u8f03\u8868"},"\u6bd4\u8f03\u8868"),(0,m.kt)("table",null,(0,m.kt)("thead",{parentName:"table"},(0,m.kt)("tr",{parentName:"thead"},(0,m.kt)("th",{parentName:"tr",align:null}),(0,m.kt)("th",{parentName:"tr",align:null},"\u905e\u8ff4"),(0,m.kt)("th",{parentName:"tr",align:null},"\u975e\u905e\u8ff4"))),(0,m.kt)("tbody",{parentName:"table"},(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"\u7a0b\u5f0f\u78bc"),(0,m.kt)("td",{parentName:"tr",align:null},"\u8f03\u7cbe\u7c21"),(0,m.kt)("td",{parentName:"tr",align:null},"\u8f03\u5197\u9577")),(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"\u5340\u57df\u8b8a\u6578\u3001\u66ab\u5b58\u8b8a\u6578"),(0,m.kt)("td",{parentName:"tr",align:null},"\u4f7f\u7528\u5f88\u5c11\u6216\u662f\u6c92\u6709"),(0,m.kt)("td",{parentName:"tr",align:null},"\u4f7f\u7528\u91cf\u591a")),(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"\u8868\u9054\u554f\u984c\u7684\u80fd\u529b"),(0,m.kt)("td",{parentName:"tr",align:null},"powerful"),(0,m.kt)("td",{parentName:"tr",align:null},"weak")),(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"\u9664\u932f"),(0,m.kt)("td",{parentName:"tr",align:null},"\u56f0\u96e3"),(0,m.kt)("td",{parentName:"tr",align:null},"\u5bb9\u6613")),(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"\u7a0b\u5f0f\u57f7\u884c\u6642\u9593"),(0,m.kt)("td",{parentName:"tr",align:null},"\u8f03\u4e45\uff0c\u6bd4\u8f03\u6c92\u6709\u6548\u7387"),(0,m.kt)("td",{parentName:"tr",align:null},"\u8f03\u77ed\uff0c\u8f03\u6709\u6548\u7387")),(0,m.kt)("tr",{parentName:"tbody"},(0,m.kt)("td",{parentName:"tr",align:null},"memory stack \u7a7a\u9593"),(0,m.kt)("td",{parentName:"tr",align:null},"\u9700\u8981\u984d\u5916\u7684 stack \u7a7a\u9593\u652f\u6301\uff0c\u6240\u4ee5\u57f7\u884c\u6642\u9700\u8981\u8f03\u591a\u7684\u52d5\u614b\u7a7a\u9593"),(0,m.kt)("td",{parentName:"tr",align:null},"\u7121\u9700 stack support")))),(0,m.kt)("h2",{id:"-\u984c\u76ee\u7df4\u7fd2"},"\ud83d\udc33 \u984c\u76ee\u7df4\u7fd2"),(0,m.kt)("h3",{id:"-factorial-n-\u968e\u4e58"},"\ud83e\udd80 Factorial N! \u968e\u4e58"),(0,m.kt)("h4",{id:"question-1-write-an-interative-function-facn-or-pseudo-code-for-n"},"Question 1: Write an Interative function Fac(N) or pseudo code for N!"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function fac(n) {\n let result = 1;\n for (let i = 1; i <= n; i++>) {\n result = result * i;\n }\n return result;\n}\n")),(0,m.kt)("h4",{id:"question-2-write-a-recursive-function-facn-or-pseudo-code-for-n"},"Question 2: Write a Recursive function Fac(N) or pseudo code for N!"),(0,m.kt)("p",null,"\u5148\u628a\u968e\u4e58\u7684\u905e\u8ff4\u6578\u5b78\u5b9a\u7fa9\u5beb\u51fa\u4f86\uff1a"),(0,m.kt)("div",{className:"math math-display"},(0,m.kt)("span",{parentName:"div",className:"katex-display"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"!"),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mrow",{parentName:"mrow"},(0,m.kt)("mo",{parentName:"mrow",fence:"true"},"{"),(0,m.kt)("mtable",{parentName:"mrow",rowspacing:"0.36em",columnalign:"left left",columnspacing:"1em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"i"),(0,m.kt)("mi",{parentName:"mrow"},"f"),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",mathvariant:"normal"},"\u2260"),(0,m.kt)("mn",{parentName:"mrow"},"0"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"!"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"i"),(0,m.kt)("mi",{parentName:"mrow"},"f"),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},">"),(0,m.kt)("mn",{parentName:"mrow"},"0")))))))),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"n! = \\begin{cases} 1,\\ if\\ n \\ne 0 \\\\ (n-1)! * n,\\ if\\ n > 0 \\end{cases}")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"0.6944em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},"!"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}})),(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"3em",verticalAlign:"-1.25em"}}),(0,m.kt)("span",{parentName:"span",className:"minner"},(0,m.kt)("span",{parentName:"span",className:"mopen delimcenter",style:{top:"0em"}},(0,m.kt)("span",{parentName:"span",className:"delimsizing size4"},"{")),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-l"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.69em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.69em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"i"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.10764em"}},"f"),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},(0,m.kt)("span",{parentName:"span",className:"mrel"},(0,m.kt)("span",{parentName:"span",className:"mord vbox"},(0,m.kt)("span",{parentName:"span",className:"thinbox"},(0,m.kt)("span",{parentName:"span",className:"rlap"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"0.8889em",verticalAlign:"-0.1944em"}}),(0,m.kt)("span",{parentName:"span",className:"inner"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mrel"},"\ue020"))),(0,m.kt)("span",{parentName:"span",className:"fix"}))))),(0,m.kt)("span",{parentName:"span",className:"mrel"},"=")),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"0"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.25em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")!"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"i"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.10764em"}},"f"),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},">"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"0")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.19em"}},(0,m.kt)("span",{parentName:"span"}))))))),(0,m.kt)("span",{parentName:"span",className:"mclose nulldelimiter"}))))))),(0,m.kt)("p",null,"\u7136\u5f8c\u518d\u5beb\u51fa\u905e\u8ff4\u7684\u7a0b\u5f0f\u78bc\uff1a"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function fac(n) {\n if (n === 0) {\n return 1;\n } else {\n return fac(n-1) * n;\n }\n}\n")),(0,m.kt)("admonition",{type:"tip"},(0,m.kt)("p",{parentName:"admonition"},"\u89e3\u905e\u8ff4\u76f8\u95dc\u554f\u984c\u7684\u8a23\u7ac5\uff1a\u5148\u60f3\u51fa\u905e\u8ff4\u7684\u6578\u5b78\u5b9a\u7fa9\uff0c\u518d\u628a\u6578\u5b78\u5b9a\u7fa9\u8f49\u63db\u6210\u7a0b\u5f0f\u78bc\uff01")),(0,m.kt)("h3",{id:"-fibonacci-number"},"\ud83e\udd80 Fibonacci Number"),(0,m.kt)("h4",{id:"definition"},"Definition"),(0,m.kt)("div",{className:"math math-display"},(0,m.kt)("span",{parentName:"div",className:"katex-display"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mo",{parentName:"mrow",fence:"true"},"{"),(0,m.kt)("mtable",{parentName:"mrow",rowspacing:"0.36em",columnalign:"left left",columnspacing:"1em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("msub",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"msub"},"F"),(0,m.kt)("mn",{parentName:"msub"},"0")),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"0"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("msub",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"msub"},"F"),(0,m.kt)("mn",{parentName:"msub"},"1")),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"1"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("msub",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"msub"},"F"),(0,m.kt)("mi",{parentName:"msub"},"n")),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("msub",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"msub"},"F"),(0,m.kt)("mrow",{parentName:"msub"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("msub",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"msub"},"F"),(0,m.kt)("mrow",{parentName:"msub"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"2"))),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"f"),(0,m.kt)("mi",{parentName:"mrow"},"o"),(0,m.kt)("mi",{parentName:"mrow"},"r"),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2265"),(0,m.kt)("mn",{parentName:"mrow"},"2"))))))),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"\\begin{cases} F_{0} = 0 \\\\ F_{1} = 1 \\\\ F_{n} = F_{n-1} + F_{n-2},\\ for\\ n \\ge 2 \\end{cases}")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"4.32em",verticalAlign:"-1.91em"}}),(0,m.kt)("span",{parentName:"span",className:"minner"},(0,m.kt)("span",{parentName:"span",className:"mopen"},(0,m.kt)("span",{parentName:"span",className:"delimsizing mult"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"2.35em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.2em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.15em"}}),(0,m.kt)("span",{parentName:"span",className:"delimsizinginner delim-size4"},(0,m.kt)("span",{parentName:"span"},"\u23a9"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.192em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.15em"}}),(0,m.kt)("span",{parentName:"span",style:{height:"0.316em",width:"0.8889em"}},(0,m.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"0.8889em",height:"0.316em",style:{width:"0.8889em"},viewBox:"0 0 888.89 316",preserveAspectRatio:"xMinYMin"},(0,m.kt)("path",{parentName:"svg",d:"M384 0 H504 V316 H384z M384 0 H504 V316 H384z"})))),(0,m.kt)("span",{parentName:"span",style:{top:"-3.15em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.15em"}}),(0,m.kt)("span",{parentName:"span",className:"delimsizinginner delim-size4"},(0,m.kt)("span",{parentName:"span"},"\u23a8"))),(0,m.kt)("span",{parentName:"span",style:{top:"-4.292em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.15em"}}),(0,m.kt)("span",{parentName:"span",style:{height:"0.316em",width:"0.8889em"}},(0,m.kt)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"0.8889em",height:"0.316em",style:{width:"0.8889em"},viewBox:"0 0 888.89 316",preserveAspectRatio:"xMinYMin"},(0,m.kt)("path",{parentName:"svg",d:"M384 0 H504 V316 H384z M384 0 H504 V316 H384z"})))),(0,m.kt)("span",{parentName:"span",style:{top:"-4.6em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.15em"}}),(0,m.kt)("span",{parentName:"span",className:"delimsizinginner delim-size4"},(0,m.kt)("span",{parentName:"span"},"\u23a7")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.85em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-l"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"2.41em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-4.41em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"F"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.3011em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.55em",marginLeft:"-0.1389em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"0"))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.15em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"0"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.97em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"F"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.3011em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.55em",marginLeft:"-0.1389em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.15em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"))),(0,m.kt)("span",{parentName:"span",style:{top:"-1.53em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"F"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.1514em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.55em",marginLeft:"-0.1389em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.15em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"F"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.3011em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.55em",marginLeft:"-0.1389em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.2083em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"F"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.3011em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-2.55em",marginLeft:"-0.1389em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"2"))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.2083em"}},(0,m.kt)("span",{parentName:"span"})))))),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.10764em"}},"f"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.02778em"}},"or"),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"\u2265"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.91em"}},(0,m.kt)("span",{parentName:"span"}))))))),(0,m.kt)("span",{parentName:"span",className:"mclose nulldelimiter"}))))))),(0,m.kt)("h4",{id:"question-1-write-a-recurisive-function-for-fibn"},"Question 1: Write a Recurisive function for Fib(N)"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function fib(n) {\n if (n === 0) {\n return 0;\n }\n if (n === 1) {\n return 1;\n }\n return fib(n-1) + fib(n-2);\n}\n")),(0,m.kt)("h4",{id:"quesiton-2-write-a-interative-function-for-fibn"},"Quesiton 2: Write a Interative function for Fib(N)"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function fib(n) {\n if (n === 0) {\n return 0;\n } else if (n === 1) {\n return 1;\n } else {\n let a = 0;\n let b = 1;\n let c;\n for (let i = 2; i <= n; i++) {\n c = a + b;\n a = b;\n b = c;\n }\n return c;\n }\n}\n")),(0,m.kt)("h3",{id:"-greatest-common-divisor-gcd-\u6700\u5927\u516c\u56e0\u6578"},"\ud83e\udd80 Greatest Common Divisor (GCD) \u6700\u5927\u516c\u56e0\u6578"),(0,m.kt)("h4",{id:"definition-1"},"Definition"),(0,m.kt)("p",null,"\u7528\u8f3e\u8f49\u76f8\u9664\u6cd5\u4f86\u8a08\u7b97\u5169\u500b\u6578\u5b57\uff08A, B\uff09\u7684\u6700\u5927\u516c\u56e0\u6578\uff0c\u5b9a\u7fa9\u5982\u4e0b\uff1a"),(0,m.kt)("div",{className:"math math-display"},(0,m.kt)("span",{parentName:"div",className:"katex-display"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mo",{parentName:"mrow",fence:"true"},"{"),(0,m.kt)("mtable",{parentName:"mrow",rowspacing:"0.36em",columnalign:"left left",columnspacing:"1em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mi",{parentName:"mrow"},"B"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"i"),(0,m.kt)("mi",{parentName:"mrow"},"f"),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"A"),(0,m.kt)("mspace",{parentName:"mrow"}),(0,m.kt)("mspace",{parentName:"mrow",width:"0.6667em"}),(0,m.kt)("mrow",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"m"),(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"o"),(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"d")),(0,m.kt)("mtext",{parentName:"mrow"},"\u2009"),(0,m.kt)("mtext",{parentName:"mrow"},"\u2009"),(0,m.kt)("mi",{parentName:"mrow"},"B"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"0"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"false"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mi",{parentName:"mrow"},"G"),(0,m.kt)("mi",{parentName:"mrow"},"C"),(0,m.kt)("mi",{parentName:"mrow"},"D"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"B"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mi",{parentName:"mrow"},"A"),(0,m.kt)("mspace",{parentName:"mrow"}),(0,m.kt)("mspace",{parentName:"mrow",width:"0.6667em"}),(0,m.kt)("mrow",{parentName:"mrow"},(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"m"),(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"o"),(0,m.kt)("mi",{parentName:"mrow",mathvariant:"normal"},"d")),(0,m.kt)("mtext",{parentName:"mrow"},"\u2009"),(0,m.kt)("mtext",{parentName:"mrow"},"\u2009"),(0,m.kt)("mi",{parentName:"mrow"},"B"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"o"),(0,m.kt)("mi",{parentName:"mrow"},"t"),(0,m.kt)("mi",{parentName:"mrow"},"h"),(0,m.kt)("mi",{parentName:"mrow"},"e"),(0,m.kt)("mi",{parentName:"mrow"},"r"),(0,m.kt)("mi",{parentName:"mrow"},"w"),(0,m.kt)("mi",{parentName:"mrow"},"i"),(0,m.kt)("mi",{parentName:"mrow"},"s"),(0,m.kt)("mi",{parentName:"mrow"},"e"))))))),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"\\begin{cases} B,\\ if\\ (A \\mod B) = 0 \\\\ GCD(B, A \\mod B),\\ otherwise \\end{cases}")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"3em",verticalAlign:"-1.25em"}}),(0,m.kt)("span",{parentName:"span",className:"minner"},(0,m.kt)("span",{parentName:"span",className:"mopen delimcenter",style:{top:"0em"}},(0,m.kt)("span",{parentName:"span",className:"delimsizing size4"},"{")),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-l"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.69em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.69em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.05017em"}},"B"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"i"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.10764em"}},"f"),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"A"),(0,m.kt)("span",{parentName:"span",className:"mspace allowbreak"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.6667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathrm"},"mod"))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.05017em"}},"B"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"0"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.25em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.008em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.07153em"}},"GC"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.02778em"}},"D"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.05017em"}},"B"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"A"),(0,m.kt)("span",{parentName:"span",className:"mspace allowbreak"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.6667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathrm"},"mod"))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.05017em"}},"B"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"o"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"t"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"h"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.02778em"}},"er"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.02691em"}},"w"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"i"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"se")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.19em"}},(0,m.kt)("span",{parentName:"span"}))))))),(0,m.kt)("span",{parentName:"span",className:"mclose nulldelimiter"}))))))),(0,m.kt)("h4",{id:"write-the-recursive-code-for-gcda-b"},"Write the recursive code for GCD(A, B)"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function gcd(a, b) {\n if (a % b === 0) return b;\n return gcd(b, a % b);\n}\n")),(0,m.kt)("h3",{id:"-tower-of-hanoi-\u6cb3\u5167\u5854"},"\ud83e\udd80 Tower of Hanoi \u6cb3\u5167\u5854"),(0,m.kt)("h4",{id:"\u984c\u76ee\u6558\u8ff0"},"\u984c\u76ee\u6558\u8ff0"),(0,m.kt)("p",null,"\u6709\u4e09\u500b\u67f1\u5b50\uff0c\u5047\u8a2d\u5206\u5225\u53eb\u505a A\u3001B\u3001C\uff0c\u5176\u4e2d A \u67f1\u5b50\u4e0a\u6709 n \u500b\u5927\u5c0f\u4e0d\u540c\u7684\u76e4\u5b50\uff0c\u9019\u4e9b\u76e4\u5b50\u5f9e\u4e0a\u5230\u4e0b\u6309\u7167\u5927\u5c0f\u6392\u653e\uff0c\u6700\u4e0a\u9762\u7684\u76e4\u5b50\u6700\u5c0f\uff0c\u6700\u4e0b\u9762\u7684\u76e4\u5b50\u6700\u5927\uff0c\u73fe\u5728\u8981\u628a\u9019\u4e9b\u76e4\u5b50\u5f9e A \u67f1\u5b50\u79fb\u5230 C \u67f1\u5b50\uff0c\u4f46\u5fc5\u9808\u9075\u5b88\u4ee5\u4e0b\u898f\u5247\uff1a"),(0,m.kt)("ol",null,(0,m.kt)("li",{parentName:"ol"},"\u6bcf\u6b21\u53ea\u80fd\u79fb\u52d5\u4e00\u500b\u76e4\u5b50"),(0,m.kt)("li",{parentName:"ol"},"\u5927\u7684\u76e4\u5b50\u4e0d\u80fd\u653e\u5728\u5c0f\u7684\u76e4\u5b50\u4e0a\u9762")),(0,m.kt)("p",null,"\u8acb\u628a\u6240\u6709\u7684\u79fb\u52d5\u6b65\u9a5f\u90fd print \u51fa\u4f86\u3002"),(0,m.kt)("h4",{id:"\u89e3\u984c\u601d\u8def"},"\u89e3\u984c\u601d\u8def"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre"}," A B C\n\n \u2502 \u2502 \u2502\n \u2502 \u2502 \u2502\n \u2502 \u2502 \u2502\n1 \u250c\u2500\u253c\u2500\u2510 \u2502 \u2502\n2 \u250c\u253c\u253c\u253c\u253c\u253c\u2510 \u2502 \u2502\n3 \u250c\u253c\u253c\u253c\u253c\u253c\u253c\u253c\u2510 \u2502 \u2502\n \u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500 \u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\n")),(0,m.kt)("p",null,"\u5148\u5f9e\u4f8b\u5b50\u958b\u59cb\u60f3\uff0c\u5047\u8a2d\u76ee\u524d\u6709 A\u3001B\u3001C \u4e09\u500b\u67f1\u5b50\uff0c\u7136\u5f8c\u6709 3 \u500b\u76e4\u5b50\u5728 A \u67f1\u5b50\u4e0a\u9762\uff0c\u5247\u6b65\u9a5f\u5982\u4e0b\uff1a"),(0,m.kt)("hr",null),(0,m.kt)("ol",null,(0,m.kt)("li",{parentName:"ol"},"move disk 1 from A to C"),(0,m.kt)("li",{parentName:"ol"},"move disk 2 from A to B"),(0,m.kt)("li",{parentName:"ol"},"move disk 1 from C to B")),(0,m.kt)("hr",null),(0,m.kt)("ol",{start:4},(0,m.kt)("li",{parentName:"ol"},"move disk 3 from A to C")),(0,m.kt)("hr",null),(0,m.kt)("ol",{start:5},(0,m.kt)("li",{parentName:"ol"},"move disk 1 from B to A"),(0,m.kt)("li",{parentName:"ol"},"move disk 2 from B to C"),(0,m.kt)("li",{parentName:"ol"},"move disk 1 from A to C")),(0,m.kt)("hr",null),(0,m.kt)("p",null,"\u628a\u6b65\u9a5f\u5206\u6210\u4e09\u500b\u5340\u584a\u4f86\u770b\uff1a"),(0,m.kt)("ol",null,(0,m.kt)("li",{parentName:"ol"},"\u7b2c 1. ~ 3. \u6b65\u9a5f\u662f\u628a 1 ~ 2 \u865f\u7684\u76e4\u5b50\u90fd\u5148\u5f9e A \u67f1\u5b50\u79fb\u5230 B \u67f1\u5b50"),(0,m.kt)("li",{parentName:"ol"},"\u7b2c 4. \u6b65\u9a5f\u662f\u628a\u6700\u5f8c\u4e00\u500b\u7b2c 3 \u865f\u76e4\u5b50\u76f4\u63a5\u5f9e A \u67f1\u5b50\u79fb\u5230 C \u67f1\u5b50"),(0,m.kt)("li",{parentName:"ol"},"\u63a5\u4e0b\u4f86\u662f\u628a B \u67f1\u5b50\u4e0a\u7684\u76e4\u5b50\u90fd\u79fb\u5230 C \u67f1\u5b50")),(0,m.kt)("p",null,"\u4f8b\u5916\u60c5\u6cc1\uff1a\u5982\u679c\u53ea\u6709\u4e00\u500b\u76e4\u5b50\u7684\u8a71\uff0c\u5c31\u76f4\u63a5\u5f9e A \u67f1\u5b50\u642c\u5230 C \u67f1\u5b50\u5c31\u53ef\u4ee5\u4e86\u3002"),(0,m.kt)("pre",null,(0,m.kt)("code",{parentName:"pre",className:"language-js"},"function hanoi(n, from, to, via) {\n if (n === 1) {\n console.log(`move disk 1 from ${from} to ${to}`);\n } else {\n hanoi(n - 1, from, via, to); // \u5148\u628a n - 1 \u500b\u76e4\u5b50\u90fd\u79fb\u5230\u4e2d\u9593\u7684\u67f1\u5b50\n console.log(`move disk ${n} from ${from} to ${to}`); // \u628a\u6700\u4e0b\u9762\u7684\u76e4\u5b50\u79fb\u5230\u76ee\u6a19\u67f1\u5b50\n hanoi(n - 1, via, to, from); // \u518d\u628a\u5269\u4e0b\u7684 n - 1 \u500b\u76e4\u5b50\u79fb\u5230\u76ee\u6a19\u67f1\u5b50\n }\n}\n")),(0,m.kt)("h4",{id:"\u6cb3\u5167\u5854\u7684\u905e\u8ff4\u5b9a\u7fa9"},"\u6cb3\u5167\u5854\u7684\u905e\u8ff4\u5b9a\u7fa9"),(0,m.kt)("p",null,"\u628a\u4e0a\u9762\u63d0\u5230\u7684\u6b65\u9a5f\u7528\u6578\u5b78\u5f0f\u4f86\u8868\u793a\uff0c",(0,m.kt)("span",{parentName:"p",className:"math math-inline"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"T(n)")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")")))))," \u8868\u793a\u79fb\u52d5 n \u500b\u76e4\u5b50\u6642\u7a0b\u5f0f\u6240\u9700\u7684\u57f7\u884c\u6b21\u6578\uff0c\u5982\u679c\u89e3\u51fa ",(0,m.kt)("span",{parentName:"p",className:"math math-inline"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"T(n)")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")")))))," \u5c31\u8868\u793a\u89e3\u51fa\u4e86\u9019\u500b function \u7684\u6642\u9593\u8907\u96dc\u5ea6\uff1a"),(0,m.kt)("div",{className:"math math-display"},(0,m.kt)("span",{parentName:"div",className:"katex-display"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mtable",{parentName:"semantics",rowspacing:"0.16em",columnspacing:"1em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mtable",{parentName:"mstyle",rowspacing:"0.25em",columnalign:"right left",columnspacing:"0em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow",separator:"true"},","),(0,m.kt)("mtext",{parentName:"mrow"},"\xa0\u4e14\xa0"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"1"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1")))))))))),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"\\begin{equation*} \\begin{split} T(n) &= T(n - 1) + 1 + T(n - 1),\\ \u4e14\\ T(1) = 1\\\\ &= 2T(n - 1) + 1 \\end{split} \\end{equation*}")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"3em",verticalAlign:"-1.25em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-c"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.75em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.75em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3.75em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-r"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.75em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.91em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.41em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"}))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.25em"}},(0,m.kt)("span",{parentName:"span"}))))),(0,m.kt)("span",{parentName:"span",className:"col-align-l"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.75em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.91em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mpunct"},","),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.1667em"}}),(0,m.kt)("span",{parentName:"span",className:"mord cjk_fallback"},"\u4e14"),(0,m.kt)("span",{parentName:"span",className:"mspace"},"\xa0"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.41em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.25em"}},(0,m.kt)("span",{parentName:"span"})))))))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"1.25em"}},(0,m.kt)("span",{parentName:"span"})))))))))))),(0,m.kt)("p",null,"\u89e3 ",(0,m.kt)("span",{parentName:"p",className:"math math-inline"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mrow",{parentName:"semantics"},(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"T(n)")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"1em",verticalAlign:"-0.25em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))))),"\uff0c\u7528\u5c55\u958b\u4ee3\u5165\u6cd5\uff1a"),(0,m.kt)("div",{className:"math math-display"},(0,m.kt)("span",{parentName:"div",className:"katex-display"},(0,m.kt)("span",{parentName:"span",className:"katex"},(0,m.kt)("span",{parentName:"span",className:"katex-mathml"},(0,m.kt)("math",{parentName:"span",xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},(0,m.kt)("semantics",{parentName:"math"},(0,m.kt)("mtable",{parentName:"semantics",rowspacing:"0.16em",columnspacing:"1em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mtable",{parentName:"mstyle",rowspacing:"0.25em",columnalign:"right left",columnspacing:"0em"},(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"["),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"]"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"4"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"3"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"4"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"["),(0,m.kt)("mn",{parentName:"mrow"},"2"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"3"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"]"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"3"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"8"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"3"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"7"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("mn",{parentName:"mrow"},"16"),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"4"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mn",{parentName:"mrow"},"15"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"\u2217"),(0,m.kt)("mi",{parentName:"mrow"},"T"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"+"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mrow",{parentName:"msup"},(0,m.kt)("mi",{parentName:"mrow"},"n"),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"))),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")"))))),(0,m.kt)("mtr",{parentName:"mtable"},(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"}))),(0,m.kt)("mtd",{parentName:"mtr"},(0,m.kt)("mstyle",{parentName:"mtd",scriptlevel:"0",displaystyle:"true"},(0,m.kt)("mrow",{parentName:"mstyle"},(0,m.kt)("mrow",{parentName:"mrow"}),(0,m.kt)("mo",{parentName:"mrow"},"="),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mi",{parentName:"msup"},"n")),(0,m.kt)("mo",{parentName:"mrow"},"\u2212"),(0,m.kt)("mn",{parentName:"mrow"},"1"),(0,m.kt)("mo",{parentName:"mrow"},"\u2248"),(0,m.kt)("mi",{parentName:"mrow"},"O"),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},"("),(0,m.kt)("msup",{parentName:"mrow"},(0,m.kt)("mn",{parentName:"msup"},"2"),(0,m.kt)("mi",{parentName:"msup"},"n")),(0,m.kt)("mo",{parentName:"mrow",stretchy:"false"},")")))))))))),(0,m.kt)("annotation",{parentName:"semantics",encoding:"application/x-tex"},"\\begin{equation*} \\begin{split} T(n) &= 2 * T(n - 1) + 1\\\\ &= 2 * [2 * T(n - 2) + 1] + 1\\\\ &= 4 * T(n - 2) + 3\\\\ &= 4 * [2 * T(n - 3) + 1] + 3\\\\ &= 8 * T(n - 3) + 7\\\\ &= 16 * T(n - 4) + 15\\\\ &= 2^{n-1} * T(n - (n - 1)) + (2^{n-1} - 1)\\\\ &= 2^{n-1} * T(1) + (2^{n-1} - 1)\\\\ &= 2^{n-1} + (2^{n-1} - 1)\\\\ &= 2^n - 1 \\approx O(2^n) \\end{split} \\end{equation*}")))),(0,m.kt)("span",{parentName:"span",className:"katex-html","aria-hidden":"true"},(0,m.kt)("span",{parentName:"span",className:"base"},(0,m.kt)("span",{parentName:"span",className:"strut",style:{height:"15.0723em",verticalAlign:"-7.2862em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-c"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.7862em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-9.7862em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"9.7862em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mtable"},(0,m.kt)("span",{parentName:"span",className:"col-align-r"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.7862em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-9.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))),(0,m.kt)("span",{parentName:"span",style:{top:"-8.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"-6.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"-5.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"-3.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"-2.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"-0.9221em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"0.6021em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"2.1262em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"})),(0,m.kt)("span",{parentName:"span",style:{top:"3.6262em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"}))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.2862em"}},(0,m.kt)("span",{parentName:"span"}))))),(0,m.kt)("span",{parentName:"span",className:"col-align-l"},(0,m.kt)("span",{parentName:"span",className:"vlist-t vlist-t2"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.7862em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-9.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"))),(0,m.kt)("span",{parentName:"span",style:{top:"-8.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"["),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},"]"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"))),(0,m.kt)("span",{parentName:"span",style:{top:"-6.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"4"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"3"))),(0,m.kt)("span",{parentName:"span",style:{top:"-5.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"4"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"["),(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"3"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},"]"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"3"))),(0,m.kt)("span",{parentName:"span",style:{top:"-3.9462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"8"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"3"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"7"))),(0,m.kt)("span",{parentName:"span",style:{top:"-2.4462em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"16"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"4"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"15"))),(0,m.kt)("span",{parentName:"span",style:{top:"-0.9221em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal"},"n"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},"))"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))),(0,m.kt)("span",{parentName:"span",style:{top:"0.6021em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2217"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.13889em"}},"T"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))),(0,m.kt)("span",{parentName:"span",style:{top:"2.1262em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"+"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.8641em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n"),(0,m.kt)("span",{parentName:"span",className:"mbin mtight"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mord mtight"},"1"))))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mclose"},")"))),(0,m.kt)("span",{parentName:"span",style:{top:"3.6262em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"3em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"}),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"="),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.7144em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n")))))))),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mbin"},"\u2212"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2222em"}}),(0,m.kt)("span",{parentName:"span",className:"mord"},"1"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mrel"},"\u2248"),(0,m.kt)("span",{parentName:"span",className:"mspace",style:{marginRight:"0.2778em"}}),(0,m.kt)("span",{parentName:"span",className:"mord mathnormal",style:{marginRight:"0.02778em"}},"O"),(0,m.kt)("span",{parentName:"span",className:"mopen"},"("),(0,m.kt)("span",{parentName:"span",className:"mord"},(0,m.kt)("span",{parentName:"span",className:"mord"},"2"),(0,m.kt)("span",{parentName:"span",className:"msupsub"},(0,m.kt)("span",{parentName:"span",className:"vlist-t"},(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"0.7144em"}},(0,m.kt)("span",{parentName:"span",style:{top:"-3.113em",marginRight:"0.05em"}},(0,m.kt)("span",{parentName:"span",className:"pstrut",style:{height:"2.7em"}}),(0,m.kt)("span",{parentName:"span",className:"sizing reset-size6 size3 mtight"},(0,m.kt)("span",{parentName:"span",className:"mord mathnormal mtight"},"n")))))))),(0,m.kt)("span",{parentName:"span",className:"mclose"},")")))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.2862em"}},(0,m.kt)("span",{parentName:"span"})))))))))),(0,m.kt)("span",{parentName:"span",className:"vlist-s"},"\u200b")),(0,m.kt)("span",{parentName:"span",className:"vlist-r"},(0,m.kt)("span",{parentName:"span",className:"vlist",style:{height:"7.2862em"}},(0,m.kt)("span",{parentName:"span"})))))))))))))}k.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/runtime~main.b4c9a6bf.js b/assets/js/runtime~main.3e2505d3.js similarity index 98% rename from assets/js/runtime~main.b4c9a6bf.js rename to assets/js/runtime~main.3e2505d3.js index 37fb140..e6f9687 100644 --- a/assets/js/runtime~main.b4c9a6bf.js +++ b/assets/js/runtime~main.3e2505d3.js @@ -1 +1 @@ -(()=>{"use strict";var e,a,f,t,r,c={},d={};function o(e){var a=d[e];if(void 0!==a)return a.exports;var f=d[e]={id:e,loaded:!1,exports:{}};return c[e].call(f.exports,f,f.exports,o),f.loaded=!0,f.exports}o.m=c,o.c=d,e=[],o.O=(a,f,t,r)=>{if(!f){var c=1/0;for(i=0;i=r)&&Object.keys(o.O).every((e=>o.O[e](f[n])))?f.splice(n--,1):(d=!1,r0&&e[i-1][2]>r;i--)e[i]=e[i-1];e[i]=[f,t,r]},o.n=e=>{var a=e&&e.__esModule?()=>e.default:()=>e;return o.d(a,{a:a}),a},f=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,o.t=function(e,t){if(1&t&&(e=this(e)),8&t)return e;if("object"==typeof e&&e){if(4&t&&e.__esModule)return e;if(16&t&&"function"==typeof e.then)return e}var r=Object.create(null);o.r(r);var c={};a=a||[null,f({}),f([]),f(f)];for(var d=2&t&&e;"object"==typeof d&&!~a.indexOf(d);d=f(d))Object.getOwnPropertyNames(d).forEach((a=>c[a]=()=>e[a]));return c.default=()=>e,o.d(r,c),r},o.d=(e,a)=>{for(var f in a)o.o(a,f)&&!o.o(e,f)&&Object.defineProperty(e,f,{enumerable:!0,get:a[f]})},o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce(((a,f)=>(o.f[f](e,a),a)),[])),o.u=e=>"assets/js/"+({26:"af0f57d5",53:"935f2afb",454:"f8784811",530:"0611a146",740:"fd5fd460",758:"a39927ab",864:"1a180f84",1046:"38adfc85",1412:"d1391f9c",1894:"518bac9e",1970:"77ffd447",2140:"2fbcd73f",2174:"e8313e59",2535:"814f3328",2589:"1611ad79",2983:"aa540d67",3089:"a6aa9e1f",3118:"bd7ef403",3237:"1df93b7f",3452:"8b68a6d2",3510:"5474669c",3608:"9e4087bc",4013:"01a85c17",4622:"dd6a2964",4689:"6a33d469",5149:"cf3114e9",5428:"179ec9e4",5691:"8ce398a0",6092:"604b1fb7",6103:"ccc49370",6244:"4bfd6b2c",6382:"9e43cd3f",6760:"090ff3b4",6905:"6e322543",7020:"530f393a",7512:"331706a3",7747:"2b390c2a",7769:"ad89c064",7918:"17896441",8183:"6c6f591c",8529:"3d29ea00",8610:"6875c492",8896:"726eb122",9387:"07253b29",9514:"1be78505",9580:"49514728",9761:"3fc6ff32"}[e]||e)+"."+{26:"ad3fc248",53:"c2d03740",454:"39828d65",530:"d86ab442",740:"df520738",758:"e5518c9e",864:"b090d165",1046:"539ea4fc",1412:"a6eba4be",1894:"85d68832",1970:"815d783e",2140:"0e134a6e",2174:"a02781ea",2535:"aa0b94c3",2589:"a5f3388a",2983:"61c37acd",3089:"1e1af270",3118:"3b33d110",3237:"d3a3bcd5",3452:"82b2706f",3510:"bed4cc01",3608:"be63b627",4013:"41a6c642",4622:"01d432fd",4689:"e16a4d6b",4972:"82e9858b",5149:"ec9d92dc",5428:"d58f5430",5691:"46471f28",6048:"dac01f6b",6092:"0cb4f5b9",6103:"9e36d795",6244:"183a2ce7",6316:"33974301",6382:"aa91a91b",6760:"6f7af14d",6905:"3b2eedde",7020:"1ac1d35e",7512:"88ed0851",7724:"1ce576b3",7747:"79cf31cd",7769:"1a906b52",7824:"3bc3148a",7918:"6b40472a",8183:"340620d9",8529:"cf59380d",8610:"da158881",8896:"b275015c",9387:"229a8843",9487:"88148996",9514:"3b96b9e9",9580:"1f808c0a",9761:"6f9c3318"}[e]+".js",o.miniCssF=e=>{},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,a)=>Object.prototype.hasOwnProperty.call(e,a),t={},r="website:",o.l=(e,a,f,c)=>{if(t[e])t[e].push(a);else{var d,n;if(void 0!==f)for(var b=document.getElementsByTagName("script"),i=0;i{d.onerror=d.onload=null,clearTimeout(s);var r=t[e];if(delete t[e],d.parentNode&&d.parentNode.removeChild(d),r&&r.forEach((e=>e(f))),a)return a(f)},s=setTimeout(l.bind(null,void 0,{type:"timeout",target:d}),12e4);d.onerror=l.bind(null,d.onerror),d.onload=l.bind(null,d.onload),n&&document.head.appendChild(d)}},o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.p="/notes/",o.gca=function(e){return e={17896441:"7918",49514728:"9580",af0f57d5:"26","935f2afb":"53",f8784811:"454","0611a146":"530",fd5fd460:"740",a39927ab:"758","1a180f84":"864","38adfc85":"1046",d1391f9c:"1412","518bac9e":"1894","77ffd447":"1970","2fbcd73f":"2140",e8313e59:"2174","814f3328":"2535","1611ad79":"2589",aa540d67:"2983",a6aa9e1f:"3089",bd7ef403:"3118","1df93b7f":"3237","8b68a6d2":"3452","5474669c":"3510","9e4087bc":"3608","01a85c17":"4013",dd6a2964:"4622","6a33d469":"4689",cf3114e9:"5149","179ec9e4":"5428","8ce398a0":"5691","604b1fb7":"6092",ccc49370:"6103","4bfd6b2c":"6244","9e43cd3f":"6382","090ff3b4":"6760","6e322543":"6905","530f393a":"7020","331706a3":"7512","2b390c2a":"7747",ad89c064:"7769","6c6f591c":"8183","3d29ea00":"8529","6875c492":"8610","726eb122":"8896","07253b29":"9387","1be78505":"9514","3fc6ff32":"9761"}[e]||e,o.p+o.u(e)},(()=>{var e={1303:0,532:0};o.f.j=(a,f)=>{var t=o.o(e,a)?e[a]:void 0;if(0!==t)if(t)f.push(t[2]);else if(/^(1303|532)$/.test(a))e[a]=0;else{var r=new Promise(((f,r)=>t=e[a]=[f,r]));f.push(t[2]=r);var c=o.p+o.u(a),d=new Error;o.l(c,(f=>{if(o.o(e,a)&&(0!==(t=e[a])&&(e[a]=void 0),t)){var r=f&&("load"===f.type?"missing":f.type),c=f&&f.target&&f.target.src;d.message="Loading chunk "+a+" failed.\n("+r+": "+c+")",d.name="ChunkLoadError",d.type=r,d.request=c,t[1](d)}}),"chunk-"+a,a)}},o.O.j=a=>0===e[a];var a=(a,f)=>{var t,r,c=f[0],d=f[1],n=f[2],b=0;if(c.some((a=>0!==e[a]))){for(t in d)o.o(d,t)&&(o.m[t]=d[t]);if(n)var i=n(o)}for(a&&a(f);b{"use strict";var e,a,f,t,r,c={},d={};function o(e){var a=d[e];if(void 0!==a)return a.exports;var f=d[e]={id:e,loaded:!1,exports:{}};return c[e].call(f.exports,f,f.exports,o),f.loaded=!0,f.exports}o.m=c,o.c=d,e=[],o.O=(a,f,t,r)=>{if(!f){var c=1/0;for(i=0;i=r)&&Object.keys(o.O).every((e=>o.O[e](f[n])))?f.splice(n--,1):(d=!1,r0&&e[i-1][2]>r;i--)e[i]=e[i-1];e[i]=[f,t,r]},o.n=e=>{var a=e&&e.__esModule?()=>e.default:()=>e;return o.d(a,{a:a}),a},f=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,o.t=function(e,t){if(1&t&&(e=this(e)),8&t)return e;if("object"==typeof e&&e){if(4&t&&e.__esModule)return e;if(16&t&&"function"==typeof e.then)return e}var r=Object.create(null);o.r(r);var c={};a=a||[null,f({}),f([]),f(f)];for(var d=2&t&&e;"object"==typeof d&&!~a.indexOf(d);d=f(d))Object.getOwnPropertyNames(d).forEach((a=>c[a]=()=>e[a]));return c.default=()=>e,o.d(r,c),r},o.d=(e,a)=>{for(var f in a)o.o(a,f)&&!o.o(e,f)&&Object.defineProperty(e,f,{enumerable:!0,get:a[f]})},o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce(((a,f)=>(o.f[f](e,a),a)),[])),o.u=e=>"assets/js/"+({26:"af0f57d5",53:"935f2afb",454:"f8784811",530:"0611a146",740:"fd5fd460",758:"a39927ab",864:"1a180f84",1046:"38adfc85",1412:"d1391f9c",1894:"518bac9e",1970:"77ffd447",2140:"2fbcd73f",2174:"e8313e59",2535:"814f3328",2589:"1611ad79",2983:"aa540d67",3089:"a6aa9e1f",3118:"bd7ef403",3237:"1df93b7f",3452:"8b68a6d2",3510:"5474669c",3608:"9e4087bc",4013:"01a85c17",4622:"dd6a2964",4689:"6a33d469",5149:"cf3114e9",5428:"179ec9e4",5691:"8ce398a0",6092:"604b1fb7",6103:"ccc49370",6244:"4bfd6b2c",6382:"9e43cd3f",6760:"090ff3b4",6905:"6e322543",7020:"530f393a",7512:"331706a3",7747:"2b390c2a",7769:"ad89c064",7918:"17896441",8183:"6c6f591c",8529:"3d29ea00",8610:"6875c492",8896:"726eb122",9387:"07253b29",9514:"1be78505",9580:"49514728",9761:"3fc6ff32"}[e]||e)+"."+{26:"ad3fc248",53:"c2d03740",454:"39828d65",530:"d86ab442",740:"df520738",758:"e5518c9e",864:"b090d165",1046:"539ea4fc",1412:"a6eba4be",1894:"85d68832",1970:"815d783e",2140:"0e134a6e",2174:"a02781ea",2535:"aa0b94c3",2589:"a5f3388a",2983:"04cf9097",3089:"1e1af270",3118:"3b33d110",3237:"d3a3bcd5",3452:"82b2706f",3510:"bed4cc01",3608:"be63b627",4013:"41a6c642",4622:"01d432fd",4689:"e16a4d6b",4972:"82e9858b",5149:"ec9d92dc",5428:"d58f5430",5691:"46471f28",6048:"dac01f6b",6092:"0cb4f5b9",6103:"9e36d795",6244:"183a2ce7",6316:"33974301",6382:"aa91a91b",6760:"6f7af14d",6905:"3b2eedde",7020:"1ac1d35e",7512:"88ed0851",7724:"1ce576b3",7747:"79cf31cd",7769:"1a906b52",7824:"3bc3148a",7918:"6b40472a",8183:"340620d9",8529:"cf59380d",8610:"da158881",8896:"b275015c",9387:"229a8843",9487:"88148996",9514:"3b96b9e9",9580:"1f808c0a",9761:"6f9c3318"}[e]+".js",o.miniCssF=e=>{},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,a)=>Object.prototype.hasOwnProperty.call(e,a),t={},r="website:",o.l=(e,a,f,c)=>{if(t[e])t[e].push(a);else{var d,n;if(void 0!==f)for(var b=document.getElementsByTagName("script"),i=0;i{d.onerror=d.onload=null,clearTimeout(s);var r=t[e];if(delete t[e],d.parentNode&&d.parentNode.removeChild(d),r&&r.forEach((e=>e(f))),a)return a(f)},s=setTimeout(l.bind(null,void 0,{type:"timeout",target:d}),12e4);d.onerror=l.bind(null,d.onerror),d.onload=l.bind(null,d.onload),n&&document.head.appendChild(d)}},o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.p="/notes/",o.gca=function(e){return e={17896441:"7918",49514728:"9580",af0f57d5:"26","935f2afb":"53",f8784811:"454","0611a146":"530",fd5fd460:"740",a39927ab:"758","1a180f84":"864","38adfc85":"1046",d1391f9c:"1412","518bac9e":"1894","77ffd447":"1970","2fbcd73f":"2140",e8313e59:"2174","814f3328":"2535","1611ad79":"2589",aa540d67:"2983",a6aa9e1f:"3089",bd7ef403:"3118","1df93b7f":"3237","8b68a6d2":"3452","5474669c":"3510","9e4087bc":"3608","01a85c17":"4013",dd6a2964:"4622","6a33d469":"4689",cf3114e9:"5149","179ec9e4":"5428","8ce398a0":"5691","604b1fb7":"6092",ccc49370:"6103","4bfd6b2c":"6244","9e43cd3f":"6382","090ff3b4":"6760","6e322543":"6905","530f393a":"7020","331706a3":"7512","2b390c2a":"7747",ad89c064:"7769","6c6f591c":"8183","3d29ea00":"8529","6875c492":"8610","726eb122":"8896","07253b29":"9387","1be78505":"9514","3fc6ff32":"9761"}[e]||e,o.p+o.u(e)},(()=>{var e={1303:0,532:0};o.f.j=(a,f)=>{var t=o.o(e,a)?e[a]:void 0;if(0!==t)if(t)f.push(t[2]);else if(/^(1303|532)$/.test(a))e[a]=0;else{var r=new Promise(((f,r)=>t=e[a]=[f,r]));f.push(t[2]=r);var c=o.p+o.u(a),d=new Error;o.l(c,(f=>{if(o.o(e,a)&&(0!==(t=e[a])&&(e[a]=void 0),t)){var r=f&&("load"===f.type?"missing":f.type),c=f&&f.target&&f.target.src;d.message="Loading chunk "+a+" failed.\n("+r+": "+c+")",d.name="ChunkLoadError",d.type=r,d.request=c,t[1](d)}}),"chunk-"+a,a)}},o.O.j=a=>0===e[a];var a=(a,f)=>{var t,r,c=f[0],d=f[1],n=f[2],b=0;if(c.some((a=>0!==e[a]))){for(t in d)o.o(d,t)&&(o.m[t]=d[t]);if(n)var i=n(o)}for(a&&a(f);b - +
- + \ No newline at end of file diff --git a/blog/2022/09/22/new-start.html b/blog/2022/09/22/new-start.html index bd0e837..415e8a8 100644 --- a/blog/2022/09/22/new-start.html +++ b/blog/2022/09/22/new-start.html @@ -10,13 +10,13 @@ - +

網站搬家

· 3 min read
Simone

這篇想紀錄一下把網站從 docsify 搬到 docusaurus的過程。

最早最早想做這個網站的時候,主要只是想找個地方放自己的學習筆記。所以目的很單純:

  • 不需要 SEO,因為只有自己需要看
  • 有個地方可以存自己的筆記
  • 有分類的功能
  • 不管從哪台電腦都可以編輯自己的筆記
  • 有很多備份,不會不見

最一開始是選擇 HackMD 來當作存筆記的地方,剛好也符合上述的需求,但是隨著轉職中自學階段的筆記數量越來越多,到現在轉成功之後,覺得 HackMD 雖然可以一次匯出所有筆記,下載備份到電腦裡,但不會有資料夾的分類,會一次下載一包,這個部份是讓我比較困擾的地方。

為了解決上述的問題,所以之後選擇了用 GitHub + docsify,這個方式蠻好的符合了原本的需求,也解決了在 HackMD 上面遇到的問題,用了 git 簡直如魚得水。

但直到最近又有了新的想法,在公司用了 docusaurus 之後,發現與 docsify 相比, docusaurus 的客製化程度非常高:

  • 雖然目前沒有打算優化 SEO,但用了 docusaurus 之後,可以將優化 SEO 這件事放入未來優化的考量
  • 分類功能較進階,比較符合日後筆記越來越多的分類需求
  • 預設的模版就蠻好用了,要更進階也可以
  • 除了 markdown,也可以寫 mdx、react,可以高度客製化自己的筆記
  • 本來就是在 react 生態圈當中的我,用起來沒有任何困擾
  • docusaurus 官方文件寫得還不錯,遇到問題也不太會找不到解答

基於以上幾個理由,於是就趕快先趁筆記還不多的時候,先把網站搬家到 docusaurus 了。

當然 docusaurus 還有我最喜歡的功能(雖然很普通啦XD):

note
info
tip
caution
danger
Toggle me!
This is the detailed content

Nested toggle! Some surprise inside...
😲😲😲😲😲
- + \ No newline at end of file diff --git a/blog/2023/01/08/learning-plan.html b/blog/2023/01/08/learning-plan.html index 952c095..e7992fd 100644 --- a/blog/2023/01/08/learning-plan.html +++ b/blog/2023/01/08/learning-plan.html @@ -10,13 +10,13 @@ - +

Learning Plan

· 3 min read
Simone

想學的東西,記錄下來督促自己認真學習。

後端

Udemy 課程

  • NodeJS - The Complete Guide (MVC, REST APIs, GraphQL, Deno)
  • Microservices with Node JS and React
  • 有餘力的話,可以再看:Learn and Understand NodeJS

官方文件

實作

  • 實作一個 server
  • 實作一個 database

方向

  • DB
  • SQL
  • Docker、k8s
  • GCP、AWS

前端

官方文件

實作

方向

front end framework

  • React
    • React fiber
    • Under the Hood
  • Vue
  • Angular
  • Solid
  • Svelte

state management

(client state)

  • Redux
    • Middleware
      • redux-saga
      • redux-thunk
      • redux-observable
      • RxJS
    • Under the Hood
  • Zustand
  • Jotai
  • xState
  • ...

(server state)

  • react query
  • SWR

bundle tool

  • Webpack
  • parcel
  • gulp
  • Vite
  • SWC
  • tsup
  • rspack
  • esbuild
  • rollup
  • turbopack
  • ...

CSS 解決方案

(CSS-in-JS)

  • styled component
  • styled-jsx
  • ...

(static)

  • SCSS、SASS
  • css module
  • ....

(css style)

  • AVO css
  • CUBE css

other

  • JavaScript: Under the Hood
  • storybook
  • Next.js、Gastby.js
  • SEO
  • CI/CD
  • monorepo

訂閱平台

  • 考慮訂閱 packt 或 egghead.io。

CS 和原理

  • 線性代數
  • 離散數學
  • 演算法
  • 資料結構
  • 計算機結構與組織
  • 作業系統
  • 瀏覽器工作原理
  • 網路概論
  • Design Pattern
  • SSR、CSR
  • PWA
  • 打包工具的原理(tree-shaking)
  • 如何製作 UI Library
  • 如何設計前端架構
  • git 原理

其他

  • Leetcode
  • Vue
  • Vuex
  • Angular
  • Solid
  • Svelte
  • graphQL
  • Apollo

  • 重構 JavaScript

實作


之後有想到什麼的話再筆記起來。

- + \ No newline at end of file diff --git a/blog/archive.html b/blog/archive.html index 63a4bd2..b0b9430 100644 --- a/blog/archive.html +++ b/blog/archive.html @@ -10,13 +10,13 @@ - + - + \ No newline at end of file diff --git a/blog/tags.html b/blog/tags.html index fdadd13..25ab411 100644 --- a/blog/tags.html +++ b/blog/tags.html @@ -10,13 +10,13 @@ - + - + \ No newline at end of file diff --git a/blog/tags/learning.html b/blog/tags/learning.html index e6f07eb..b429f39 100644 --- a/blog/tags/learning.html +++ b/blog/tags/learning.html @@ -10,13 +10,13 @@ - +

One post tagged with "Learning"

View All Tags
- + \ No newline at end of file diff --git "a/blog/tags/\351\232\250\347\255\206.html" "b/blog/tags/\351\232\250\347\255\206.html" index 03d231c..1b65bb8 100644 --- "a/blog/tags/\351\232\250\347\255\206.html" +++ "b/blog/tags/\351\232\250\347\255\206.html" @@ -10,13 +10,13 @@ - +

One post tagged with "隨筆"

View All Tags
- + \ No newline at end of file diff --git a/docs/collection/React.html b/docs/collection/React.html index de03781..ba9cf8d 100644 --- a/docs/collection/React.html +++ b/docs/collection/React.html @@ -10,13 +10,13 @@ - +
- + \ No newline at end of file diff --git a/docs/collection/front-end.html b/docs/collection/front-end.html index 1e82a26..8808b56 100644 --- a/docs/collection/front-end.html +++ b/docs/collection/front-end.html @@ -10,13 +10,13 @@ - +

Front-End

🐳 Conference

namelink
You Gotta Love Frontendhttps://www.youtube.com/@YouGottaLoveFrontend/videos
JSConfhttps://www.youtube.com/@jsconf_/videos
International JavaScript Conferencehttps://www.youtube.com/@internationaljavascriptcon784/videos
ReactConfhttps://www.youtube.com/@reactconf8476/videos
React Conf 2021https://www.youtube.com/@user-wm2fy4kq4u/videos
ReactNexthttps://www.youtube.com/@ReactNext/videos
Ember Videoshttps://www.youtube.com/@EmberMeetupVideos/videos

🐳 Design Patterns

🐳 JavaScript

🐳 TypeScript

🐳 Functional Programming

🐳 訂閱平台

🐳 People

🐳 NewsLetter

🐳 Website

🐳 a11y

🐳 Twitter

wholinknotes
Evan Youhttps://twitter.com/youyuxiVue, Vite 作者
Guillaume Chauhttps://twitter.com/AkryumVue team, Vite 出現之前主要在做 Vue Cli, 現在主要在做 histoire
Sarah Drasnerhttps://twitter.com/sarah_edoVue core team, CSS-Tricks writer. SVG Animations 作者, VSCode night owl 作者
Ives van Hoornehttps://twitter.com/CompuIvesCode Sandbox 作者
Danhttps://twitter.com/dan_abramovReact 大神, React hook 關鍵人物
Egoisthttps://twitter.com/_egoistlily一堆好用工具的作者. tsup, cac
Anthony Fuhttps://twitter.com/antfu7一堆好用工具的作者. vitest, slidev, VueUse, UnoCss, icones 作者, i18n-ally 初版作者
MICHAEL JACKSONhttps://twitter.com/mjacksonReact Router, Remix
Ryan Florencehttps://twitter.com/ryanflorenceReact Router, Remix
Lea Verouhttps://twitter.com/LeaVerouCSS 大神, w3ctag 成員, CSS Secrets 作者
Mark Dalgleishhttps://twitter.com/markdalgleishvanilla-extract, RainbowKit
Rich Harrishttps://twitter.com/Rich_HarrisRollup, svelte 作者
Tanner Linsleyhttps://twitter.com/tannerlinsleyTanstack 作者, 多個 library, 其中最大宗的應該是 react-query 和 react-table, 最近在搞 framework agnostic
Poimandreshttps://twitter.com/pmndrs旗下有很多 library, 包括 react-spring, react-three-fiber, zustand, jotai 等等
Daishi Katohttps://twitter.com/dai_shijotai, valtio 作者
Evan Wallacehttps://twitter.com/evanwallaceesbuild 作者, figma cofounder
Donnyhttps://twitter.com/kdy1devswc 作者, next.js member, 最近好像在做 rust based type checker
Matt Pocockhttps://twitter.com/mattpocockuktypescript tip 系列文, 十分推薦使用或在學 ts 的朋友們追蹤
GitHub Trending for JS & TShttps://twitter.com/gh_trending_js
CSS Trickshttps://twitter.com/css
Sebastien Lorberhttps://twitter.com/sebastienlorberThisWeekInReact, React eco 懶人包
- + \ No newline at end of file diff --git a/docs/collection/intro.html b/docs/collection/intro.html index fc806a4..ee5bf82 100644 --- a/docs/collection/intro.html +++ b/docs/collection/intro.html @@ -10,13 +10,13 @@ - +

首頁

希望可以整理一些目前所學的相關 conference 資源或是任何網路自學資源。

尚未分類 ⬇️

🐳 Conference

🐳 People

🐳 Podcast

🐳 Other

🐳 Paper

🐳 資安

🐳 台灣

- + \ No newline at end of file diff --git a/docs/collection/session-and-cookie.html b/docs/collection/session-and-cookie.html index 6426b81..f7155f8 100644 --- a/docs/collection/session-and-cookie.html +++ b/docs/collection/session-and-cookie.html @@ -10,13 +10,13 @@ - + - + \ No newline at end of file diff --git a/docs/collection/web.html b/docs/collection/web.html index 9bb932d..027d802 100644 --- a/docs/collection/web.html +++ b/docs/collection/web.html @@ -10,13 +10,13 @@ - +
- + \ No newline at end of file diff --git a/docs/notes/Git/git-basic-1.html b/docs/notes/Git/git-basic-1.html index 68bdcec..960861d 100644 --- a/docs/notes/Git/git-basic-1.html +++ b/docs/notes/Git/git-basic-1.html @@ -10,13 +10,13 @@ - +

Git 基本原理、分支與分支合併

🐳 前言

因為在工作上大量的用到 git 這個版控工具,所以想好好了解自己每個用到的指令背後實際上發生了什麼事,上了一堂 udemy 的課,寫了一些小筆記。

筆記來源大部分參考自:https://www.udemy.com/course/git-basic/

🐳 Git Local 基本原理解析

🦀 Git 的設定

通常在看各式各樣的 git 教學的時候,會看到當使用者下載好 git 之後,教學的下一個步驟是在終端機打入以下指令:

git config --global user.email "[your email]"
git config --global user.name "[your name]"

這兩行的意思其實會在根目錄建立一個 global 的 git 設定檔(檔名是 .gitconfig),而且這個設定檔會自動帶入到每一個 git repository。除了這個 global 的 git 設定檔之外,每一個 git repository 裡面都有自己的 git 設定檔,可以進到該 repo 透過 git config --list 指令查看。

除了設定使用者之外,git config 其實還可以做非常多其他的設定,來達到 git 的客製化。

tip

git repository 會優先採用 local config 的設定,再使用 global config 的設定。

🦀 初始化代碼倉庫

建立一個 git repository 主要有兩種方法:

  • git clone 遠端的倉庫
  • 建立本地倉庫,再使用 git init

透過這兩種方式都可以發現 git repository 裡面出現了一個 .git 的資料夾,可以在終端機裡面透過 ls -a 這個指令看到這個資料夾,透過觀察這個資料夾的變化,可以很好地理解 git 是如何運作的。

首先先在這邊放上一個最基本的 .git 資料夾的架構,接下來會透過這個資料夾的變動來一一理解 git 如何運作。

.git
├── branches
├── config
├── description
├── HEAD
├── hooks
├── info
│   └── exclude
├── objects
│   ├── info
│   └── pack
└── refs
├── heads
└── tags

🦀 git add [file] 背後發生了什麼

當建立一個檔案,並將其透過 git add [檔名] 加入 tracked file 的時候,可以發現 .git 資料夾發生了變化,我們假設目前的變化如下:

.git
├── branches
├── config
├── description
├── HEAD
├── hooks
├── info
│   └── exclude
├── index // 多了這個
├── objects
| ├── 54 // 多了這個
│   │   └── 7fe984c2f69bd68e98fca67f99a5c14d1435aa // 多了這個
│   ├── info
│   └── pack
└── refs
├── heads
└── tags

可以發現 .git 裡面的 objects 資料夾中多了另外一串奇怪的數字,這一串數字是透過稱為 SHA1 的加密算法算出來的,如果要查看任何有關 objects 資料夾當中的東西的話,可以在終端機當中輸入以下指令:

git cat-file -t 547fe9 // 只取前六位即可
git cat-file -p 547fe9

-t: 查看該檔案的類型
-p: 查看該檔案的內容
-s: 查看該檔案的大小

在終端機下了上述這兩個指令之後,可以發現透過 git add [file] 之後,產生的 object 類型是 blob 而裡面的內容則是檔案裡面的文字內容,另外一個很重要的是,我們發現到這個 object 並沒有儲存檔名。(檔名會存在另外一個地方)

🦀 blob 對象與 SHA1 哈希

  • HASH 算法:將任意長度的輸入透過 HASH 算法變換成固定長度的輸出,常常被用來做加密。
  • 常見的 HASH 算法,括號當中的 bit 表示會輸出多少 bit 的字串:
    • MD5 (128 bit) (已被破解)
    • SHA1 (160 bit) (已被破解)
    • SHA256 (256 bit)
    • SHA512 (512 bit)

git add [file] 之後, git 會根據檔案的類型、大小、修改的內容來產生 HASH 值,然後存到 .git/objects 當中,同時也會壓縮內容。目前 git 算出 HASH 值的方式都是用 SHA1 算法。

🦀 Working Directory 和 Staging Area

git 的工作區大致上可以分成三種不同的類型來理解,分別是 Working Directory、Staging Area、git repository。如下圖所示:

在檔案尚未被 git 追蹤的時候,會停留在 Working Directory,任何需要被 git 控管的檔案都需要使用 git add [file] 這個指令,來將檔案加入到 Staging Area,最後透過撰寫 commit 存到 git repository 裡面。

在圖中可以看到,Staging Area 下面有一個 index 的字樣,沒錯,有關 Staging Area 的任何訊息都會被儲存在 .git/index 這個資料夾當中。我們可以透過以下指令去檢視目前在 index 的檔案有哪些:

git ls-files // 只顯示檔名
git ls-files -s // 顯示檔名、該檔案的權限、文件內容
tip

所以可以知道,前面提到的 blob object 只儲存文件內容,而文件的檔名會儲存在 index(索引區)。可以透過 git status 指令來觀察 Staging Area 和 Working Directory 的變化。

🦀 git commit 背後發生了什麼

將文件加入到 Staging Area 之後,接著要使用 git commit -m "message" 來生成 commit,生成 commit 的目的是為了將有修改的地方存到代碼倉庫(git repository)當中,那麼 commit 在生成的時候,究竟是生成了什麼呢?

生成一個 commit 之後,git 也會透過 SHA1 算法為每個 commit 算出一組編碼,這時候我們也可以運用上面提到的 git cat-file 指令去觀察 commit 的類型和內容。透過該指令我們可以知道 commit 的類型是 commit,而內容則是 tree 和作者資訊,如下圖範例:

tree 當中會儲存前面提到的 blob object,也就是說,tree 裡面存的是目前這個 commit 有修改到的所有檔案。再者,如果這個 commit 是接在另一個 commit 後面的話,除了 tree 之外,則會額外再多看到一個 parent,這個 parent 標示著這個 commit 是接在某個特定的 commit 之後。

除了觀察 commit 本身之外,我們也可以觀察有 commit 的分支,假設輸入以下指令:

cat .git/refs/heads/master

就可以看到這個 master 的分支最新的 commit 是哪一個。

另外 .git 當中還有一個資料夾稱作 HEAD,可以將 HEAD 想像成一個指針,這個 HEAD 的用途是用來指向目前所在的分支。可以透過以下指令去查看 .git/HEAD 的內容:

cat .git/HEAD

🦀 Commit History Tree

在前面的幾個部份當中,我們可以發現不管是使用 git addgit commit -m git 都會透過 SHA1 算法來生成一個 git object,而這些 object 都會指向各自關聯到的另外一個 git object,比如說新的 commit 會指向上一個 commit,以此類推,如果有很多個 commit 的話,我們就可以透過這樣的方式去知道整個 commit history。而每一個 commit 會指向該 commit 有修改到的檔案(blob object),透過這個指向,我們也可以知道每一個 commit 修改了什麼。

這樣子不斷指向的過程便會形成一個 commit history tree(如下圖),而我們也可以知道,這樣的結構就是 git 的版本概念。

🐳 Branch 和 HEAD

🦀 什麼是分支?什麼是HEAD?

在整個 git 版本控制的工作流程當中有一個非常重要的概念,就是分支,在程式開發的流程當中會不斷遇到建立分支、合併分支的過程,在開始講解基本操作之前,先來解釋一下到底什麼是分支?

翻翻 git 的官方文件後,我們可以看到 git 對分支的解釋:

Branches are named pointers to commits.

從以上敘述可以知道,分支只是一個指向某個 commit 的指針。此時我們就會知道如果要讓分支這個功能可以運作需要達成兩個條件:

  1. 要有一個地方可以儲存每個分支指向的哪個 commit 這件事情。 ➡️ 存在 .git/refs/heads/[branch 名稱] 裡面。
  2. 要有一個東西可以讓我們知道我們現在在哪一個分支上面。 ➡️ 透過 HEAD 來實現,也就是說只要看 HEAD 指向哪個分支,我們現在就在哪個分支。(HEAD 存在 .git/HEAD)

🦀 分支的基本操作

  1. git branch:查看目前有哪些分支。如果該分支前面出現 * 字號,表示那是現在所在的分支。
  2. git branch [branch 名稱]:創建分支。
  3. git checkout [branch 名稱]:切換現在的分支到另外一個分支。
  4. git branch -d [branch 名稱]:刪除分支。如果分支沒有 merge 的話,會出現無法刪除分支的提示訊息。
  5. git branch -D [branch 名稱]:強制刪除分支。就算分支沒有 merge 也可以刪除。
  6. git reflog:會記錄所有在 git 當中的操作,包括被刪除分支的 commit。
  7. git branch -m [舊 branch 名稱] [新 branch 名稱]:重新命名分支名稱。
  8. git checkout -b [branch 名稱]:創建分支並且切換到該分支。
caution

注意:如果現在所在的分支是想要刪除的分支的話,就不能刪除分支。要先移動到別的分支,才能刪除。

🦀 使用 git checkout 出特定的 commit

git checkout 除了可以用來切換分支之外,也可以用來找出某個特定的 commit。如果不小心刪除了某個分支,可以先用 git reflog 找到被刪除分支的 commit,然後再建立分支,就可以恢復被刪除的分支。如下步驟:

1. git reflog
2. git checkout [commit sha1值(六個字)]
3. git checkout -b [被刪除的 branch 名稱]

這個用法平常不太常用到,但在特殊情況下特別有用!

caution

刪除分支到底刪除了什麼? 刪除分支時,只會刪除分支這個指針,並不會刪除任何的 commit!

🦀 關於 git diff 這個命令

現在應該也比較少在用 git diff 這個指令了,因為 IDE 可以直接顯示檔案變動的情況,非常方便,但其實也可以透過在終端機打下指令 git diff 來查看 working directory 和 staging area 中文件之間的差別。

如果要查看 staging area 和 git repository 的差別的話,可以用 git diff --cache 來查看。

🐳 分支合併(Branch Merge)

當團隊裡的人在不同的分支開發完之後,會需要將所有的分支都合併在一起,才是一個完整的應用。此時合併分支時會有幾個不同的狀況。這個單元會一一介紹。

🦀 Fast Forward Merge

算是在合併分支的時候遇到的最簡單的一種。

假設目前有兩個分支,分別是 mater 和 bugfix。bugfix 是基於 master 最新的 commit 所創建的另外一個分支,我們在 bugfix 上新增了一個 commit。此時整個 branch 和 commit 的結構大致上如下圖所示:

在這樣的結構之下進行 git merge 的話,master branch 的指針會向右移動,會與 bugfix 位於同一個 commit,稱之為 fast forward merge。

小結

在這裡簡單總結符合 fast forward merge 的條件:分支 B 合併進 分支 A 的時候,分支 B 的第一個 commit 指向分支 A 最新的 commit。

🦀 3 Way Merge

3 Way Merge 是另外一種在合併分支的時候會遇到的狀況,這個狀況應該非常的常見。會發生這樣的狀況是因為:分支 B 合併進 分支 A 的時候,分支 B 的第一個 commit 沒有指向分支 A 最新的 commit。

實際上最常遇到的狀況是,自己從 master 另開新的 feature 分支來開發新的功能的時候,其他同事也會同時開發其他的功能,有可能他們先開發完成 merge 進 master,我自己的 feature 分支就會落後目前的 master 分支。這時候如果我開發完成要準備 merge 進 master,就會發生 3 Way Merge。

如下圖所示(bugfix 分支落後 master 分支一次 commit):

這個情況下,如果進行 merge 而且沒有衝突的話,會自動生成一個新的 commit,這個新的 commit 會同時指向兩個分支的上一個 commit,如下圖:

如果用一些 git GUI 工具的話,應該可以看到 branch 的分支圖。當如果一個 repo 很大的時候,有很多 3 way merge 的話,分支圖就會盤根錯節(很醜 👾),這種時候就是 git rebase 出場的時機了(稍後會寫到)!

🦀 3 Way Merge with Conflict

前面提到的 3 Way Merge 如果順順的,沒什麼意外發生的話,就會自動 merge,但如果兩個準備要合併的分支,兩個分支都有修改到同樣的地方的話,就會發生衝突,也就是 conflict。

如果發生衝突的話,可以按照終端機上的說明,一步一步解掉衝突。等到衝突全部解掉後,就可以 merge 了!

有衝突發生的當下可以在終端機打 git status 檢查是哪些檔案發生衝突,再去 vsCode 裡面把衝突解掉就可以了!

🦀 git rebase 是什麼?

git rebase 可以讓所在的分支,同步另外一個分支的最新 commit,比如說我現在在 feature 1 分支,並且 commit 了三次,此時這個分支落後 master 分支一個 commit。

使用 git rebase master 之後,就可以讓 feature 1 分支的三次 commit 接在 master 分支最新的 commit 之後,如此一來就可以進行 Fast Forward Merge。

caution

要特別注意的是使用 git rebase 也有可能會造成衝突,如果有衝突的話需要將衝突解掉才能 rebase。另外使用了 rebase 之後,在該分支上面的 commit 會全部重新計算,因為這幾個 commit 的第一個有了新的 parent commit,所以 commit tree 便重新算了一次,也就是說在該分支所建立的 commit 的 id 會不一樣,雖然每個 commit 的修改內容仍和先前相同。

🐳 參考資料

- + \ No newline at end of file diff --git a/docs/notes/HTML/metadata.html b/docs/notes/HTML/metadata.html index fd624c7..55fdcf4 100644 --- a/docs/notes/HTML/metadata.html +++ b/docs/notes/HTML/metadata.html @@ -10,13 +10,13 @@ - +

metadata、<meta> 知多少

🐳 前言

今天想要研究的主題是,網頁前端世界裡的三本柱 ── HTMLCSSJavaScript 之中的 HTML。雖然 HTML 並非如同 JavaScript 有很多程式語言相關的主題與議題能夠探討,但是也是有一些有趣的主題值得研究和探索。

之前在寫 side project 或是技術面試被問到該如何優化 SEO 時,當時只有辦法大概回答出可以透過 HTML 當中的 metadata 去優化 SEO,但是並不清楚 metadata 實際上有哪些用法,或是可以做到哪些事情,所以這次想要試著以一種更詳細和全面的角度來理解 HTML 當中會使用到的 metadata 和 <meta> 這兩個東西。(當然有機會的話,之後也想要寫一個 SEO 的系列文來理解 SEO 和知道如何優化它)

本文架構如下:

  • metadata 是什麼? → 首先會先定義 metadata 是什麼
  • metadata 有哪些? → 接著解釋 metadata 在 HTML 當中的應用
  • 淺談 <meta> → 最後會對 <meta> 這個用法做更深入的研究

你可能要有的先備知識:

  • 知道 HTML 是什麼
  • 了解 <head><body> 的差別

🐳 metadata 是什麼?

首先可以先從現有的網路資源當中,去尋找 metadata 的定義。在 MDN 文件當中,解釋了什麼是 metadata:

Metadata is — in its very simplest definition — data that describes data. For example, an HTML document is data, but HTML can also contain metadata in its <head> element that describes the document — for example who wrote it, and its summary.

直接翻譯的話,metadata 的意思就是「描述資料」的資料,這樣子聽起來可能還是一頭霧水,但如果我們以一個實際的例子來說明的話,可能會清楚許多。

假設現在有一個猜拳遊戲網頁的 HTML 檔,架構如下:

<!DOCTYPE html>
<html lang="zh-Hant-TW">
<head>
<!-- metadata, 使用者不會看到,但是會提供這個 HTML 檔相關的資訊,例如以下四行 -->
<meta charset="UTF-8">
<meta name="description" content="猜拳遊戲">
<link rel="stylesheet" href="style.css">
<title>Rock_Paper_Scissors Game</title>
</head>
<body>
<!-- 使用者會看到的內容 -->
<header></header>
<main></main>
<footer></footer>
</body>
</html>

通常在 <body> 這個標籤中會放滿希望讓使用者看到的畫面;另外將描述這個網頁的資訊,比如這個網頁的作者、這個網頁的用途、這個網頁的編碼方式、要套用的 css 檔、要套用的 JavaScript 檔等等,放在 <head> 這個標籤當中。

這些放在 <head> 當中的資訊,並且用來描述這個 HTML 網頁檔是要用來做什麼、或是要運行什麼東西,都可以稱之為 metadata。通常這些 metadata 的資訊會被搜尋引擎的爬蟲爬取並解析,於是我們可以在這裡很簡單地暴力推測:如果 metadata 寫得越完整,對 SEO 的幫助越大,也可以說是優化 SEO 的方法之一。

🐳 metadata 有哪些?

在上一個小節理解 metadata 的定義之後,那接下來的問題就是:實際上要如何在 HTML 當中寫出 metadata 呢?這也是本小節試圖回答和整理的問題。

🦀 <title>

在每個 HTML 檔的 <head> 當中,基本上一定都會有 <title> 這個標籤(tag),它的語法如下:

<title>Insert Title Here | Follow it with the Website Name if you Wish</title>

藉由 title 這個標籤,可以讓搜尋引擎知道這個網頁的名稱,並將它顯示在搜尋結果頁上面。或是也可以在瀏覽器的頁籤上看到 <title> 的內容,讓使用者知道自己目前在哪個網頁,比如說進到臉書首頁時,在瀏覽器頁籤上看到 Facebook 字樣,是因為 <title>Facebook</title> 的緣故。

<link> 這個標籤的用途蠻多元的,目前我自己最常用到的是將 CSS 檔引入到 HTML 當中,讓網頁上的元素可以套用樣式,除此之外還有一些其他的用途,例如:加入網頁的 Logo、用標準網址(Canonical URL)整合重複性的網址等等。

CSS 檔引入(Load Stylesheets)

平常在撰寫網頁時,除了需要 HTML 來建立網頁的架構,也會需要 CSS 來讓網頁上的內容套用美美的樣式,通常會將 CSS 樣式寫在另外一個檔案裡,再引入到 HTML 當中,可以使用以下語法來引入:

<link href="[fileName].css" rel="stylesheet">

加入網頁 Logo(Add a Favicon)

打開一個網頁時,頁籤上除了會顯示 <title> 中的網頁名稱之外,也會看到在網頁名稱前面有個小小的 Logo(叫做 favicon),這個小小的 Logo 可以透過以下方式來新增到網頁當中:

<link href="favicon.ico" rel="icon">

隨著網路不斷演進,目前客戶端有多種瀏覽器和設備,所以 favicon 為了演進的需要也提供的多種置入的方式,比如不一定要用 .ico 的格式, .png、.svg 也可以,每個瀏覽器或是設備當中看到的 favicon 最佳大小可能也不相同。由於本文學習和研究的重心主要是在 <meta> ,對這部分的內容可能不夠詳盡,若想深入了解的話,也許可以參考這則在 stackoverflow 上的討論:HTML 5 Favicon - Support?

標準網址 (Canonical URL)

假設目前有以下的網址:

http://www.example.com/
http://www.example.com/index.html
http://example.com/
http://example.com/index.html

但其實這些網址連到的都是同一個網頁,或是在不同網頁上提供相似度極高的內容(例如:行動版和電腦版的網頁,兩者是不同網址但內容幾乎相同)。Google 搜尋引擎便會將這些不同的網址視為相同網頁的重複版本,從中選出一個網址作為「標準」版本進行檢索,然後將其他網址判定為「重複」網址並降低搜尋引擎爬取的頻率。

如果我們沒有設定一個標準網址的話,Google 搜尋引擎本身就會自己幫我們決定一個標準網址。為了避免這件事情發生,我們其實可以透過以下語法來設定一個自己想要的標準網址:

<link rel="canonical" href="http://www.example.com/" />

這也是 <link> 的用途之一。有關標準網址相關資訊,可以參考 Google 搜尋中心的說明:整合重複的網址。更多有關 <link>詳細的屬性解說可以參考 MDN 文件:link: The External Resource Link elementLink types

🦀 <base>

<base> 標籤主要是控制網頁的連結屬性,可以指定網頁的連結根目錄,也可以指定網頁超連結的開啟方式,屬性有 href、target。我們可以直接來看以下兩個範例:

<html>
<head>
<title>這是標題</title>
<!-- HTML base href, target 範例設定 -->
<base href="https://www.example.com" target="_blank">
</head>
<body>
<a href="products">產品資訊</a>
<a href="about-us">關於我們</a>
<a href="faq">問與答</a>
</body>
</html>
<html>
<head>
<title>這是標題</title>
</head>
<body>
<a href="https://www.example.com/products" target="_blank">產品資訊</a>
<a href="https://www.example.com/about-us" target="_blank">關於我們</a>
<a href="https://www.example.com/faq" target="_blank">問與答</a>
</body>
</html>

以上兩個程式碼達成的效果其實是相同的。上面的程式碼有使用 <base>,直接指定整個網頁的連結開頭,還有這個網頁按下超連結時會使用開啟新分頁的方式,所以就不需要針對每一個 <a> 進行處理;下面的程式碼沒有使用 <base>,所以便會針對每一個 <a> 進行處理。

另外需要注意的是:只要有設定 <base>href,任何網頁中的連結都會被它給覆蓋過去。更多有關 <base> 的用法可以參考這些資源:base html 標籤是什麼? html tag 設定網頁連結 - SEAN 工作版base: The Document Base URL element - MDN

🦀 <script>

可以使用 <script> 這個標籤來引入 JavaScript,執行一些這個 HTML 網頁所需要的程式碼,比如 CDN 、Gooogle Analytics、網頁互動邏輯等等,可以使用以下兩種不同的方式引入:

// 方法一:直接將 JavaSript 寫在裡面
<script>
<!-- 要執行的 JavaScript -->
</script>

// 方法二:插入一個 JavaScript 檔
<script src="[folder_name]/[file_name].js"></script>

另外在使用 <script> 這個標籤時,可以特別注意某些屬性是怎麼使用的,比如說:deferasync 的差別type="module" 怎麼用等等。更多詳細的屬性解說可以參考 MDN 文件:script: The Script element

🦀 <meta>

除了上述使用到的標籤之外,可能也還有很多 metadata 需要寫進 HTML 檔裡,比如這個網頁的編碼方式、這個網頁的作者、這個網頁的描述等等,這些都可以使用 <meta> 這個標籤來實現。簡單來說,除了前面提到的標籤以及它們的用途之外,其他的 metadata 都可以寫在 <meta> 這個標籤中,在下一個部分會針對 <meta> 的屬性做更詳細的理解與介紹。

🐳 淺談 <meta>

在這個部分會一一介紹幾個 <meta> 當中常用到的 attribute,了解這些 attribute 的用途。

🦀 name、content

首先第一個登場的 attribute 就是 name 和 content。name 和 content 可以用來描述一個網站的資訊,像是這個網站的作者、這個網站的描述、圖片等等,通常這兩者可以寫在一起,比如下面的範例:

<meta name="author" content="Simone">
<meta name="description" content="This is my page">
<meta name="image" content="xxx.jpg">

這三行程式碼如果直接寫成中文的話,大概呈現的方式如下:

作者:Simone
網站描述:This is my page
圖片:xxx.jpg

同時,這些資訊也可以讓搜尋引擎查詢,讓搜尋引擎知道這個網頁到底是什麼樣的網頁。

另外有一個可能需要特別注意的地方:

<meta name="keywords" content="html, css, javascript">

以往 name 有一個 keywords 的寫法,表示這個網站會用到的關鍵字,提供搜尋引擎尋找,但目前 Google 有說搜尋引擎目前不會查詢 keywords 了。所以如果有需要的話,可以改成寫在 meta description 當中。

🦀 charset

charset 這個 attribute 是用來設定該網頁會用何種方式來進行編碼,比如以下的範例使用 utf-8 方式還進行編碼,也是目前網頁常用到的編碼方式。HTML5 預設的編碼方式也是 utf-8。(編碼的方式有非常多種,也許之後也可以寫筆記來研究研究)

<meta charset="utf-8">

🦀 http-equiv

http-equiv 會告訴瀏覽器該如何處理這份文件。

在對伺服器發出 request 之後,伺服器會回傳 reponse,通常 response 裡面會有 headers。在 meta 當中使用 http-equiv 時,http-equiv 所包含的資訊會類似於 reponse 傳回來的 headers,比如下面兩個範例的意思其實是差不多的:

<!-- metadata in HTML -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
// 伺服器回傳的 headers
Content-Type: text/html; charset=utf-8

所以 http-equiv 可以理解成 HTTP response headers equivalent,當中的 equiv 其實就是 equivalent 的意思。

不過,HTTP response 不是都會有 headers ?為什麼還要在 HTML 文件放入類似的資訊?有可能使用者無法直接獲得 HTTP response headers,所以就需要靠 http-equiv 的資訊了。

http-equiv 還有另外一個用法是 refresh,可以設定幾秒過後重新整理,或是幾秒過後重新導向某個網址,比如以下的程式碼:

<!-- 3 秒後重新整理頁面 -->
<meta http-equiv="refresh" content="3">

<!-- 5 秒後導向 http://www.example.com -->
<meta http-equiv="refresh" content="5; url=http://www.example.com">
caution

目前 HTML5 請直接使用 <meta charset="utf-8"><meta http-equiv="content-type" content="text/html; charset=UTF-8"> 是 HTML4 在用的。

🦀 Open Graph

平常在各個社群網站分享網址的時候,除了將一串網址貼到貼文上面之外,是不是還會看有一個區塊,上面會有你分享的網站的標題、敘述、圖片等等。

這部分就是用 Open Graph 辦到的,讓使用者在社群當中分享網站時,可以顯示美美的畫面,且只需要在 <meta> 當中寫下以下程式碼就可以辦到了:

<meta property="og:title" content="Open Graph protocol">
<meta property="og:type" content="website">
<meta property="og:url" content="https://ogp.me/">
<meta property="og:image" content="https://ogp.me/logo.png">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="300">
<meta property="og:image:height" content="300">
<meta property="og:image:alt" content="The Open Graph logo">
<meta property="og:description" content="The Open Graph protocol enables any web page to become a rich object in a social graph.">
info

Open Graph 的官方文件由此去:https://ogp.me/

🐳 結語

以上就是這次對 metadata、<meta> 的小小研究,透過這次的撰寫,得到的收穫大概是:對 metadata 和 <meta> 有更詳細的了解。同時也可以理解 metadata 當中對 SEO 有幫助的部分,例如:整合標準網址、將 <meta> 的 description 寫的詳細一點等等。

🐳 參考資源

- + \ No newline at end of file diff --git a/docs/notes/MySQL/install-mysql.html b/docs/notes/MySQL/install-mysql.html index 093f305..910fb20 100644 --- a/docs/notes/MySQL/install-mysql.html +++ b/docs/notes/MySQL/install-mysql.html @@ -10,13 +10,13 @@ - +

在 Ubuntu 安裝 MySQL

最近剛初學資料庫,在本地安裝 MySQL 的時候遇到太多坑了,所以紀錄一下安裝的方式。 💦

🐳 安裝環境

作業系統:linux Ubuntu 22.04

對滴沒綽,是在 linux 環境下安裝 MySQL 時遇到的坑們。

🐳 安裝 MySQL

在 linux 環境下安裝 MySQL 還蠻容易的,只要在終端機輸入:

$ sudo apt install mysql-server

等它安裝好之後,本地端就有資料庫了。但除了安裝資料庫之外,還需要針對剛裝好的資料庫做一些基本的設定。最基本的設定就是設定資料庫的密碼,畢竟資料庫裡面可能都會存放重要的資料,不能讓任何人都有權限可以進入。

通常搜尋網路上的 MySQL 安裝教學,會看到要使用下面的指令來設定密碼強度和密碼:

$ sudo mysql_secure_installation

如果上述的指令沒問題的話就可以順順地設定好密碼,再用密碼登入 MySQL 就可以了。但是在下了這個指令之後,我的電腦卻出現了下面的錯誤訊息,無法使用這個指令來設定密碼。

Output
... Failed! Error: SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method used doesn't store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters

這個時候需要改用另外一個方法來設定密碼:

  1. 首先先進到 MySQL
$ sudo mysql
  1. 進到 MySQL 之後,先將密碼預設成 password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
  1. 離開 MySQL
mysql> exit
  1. 開始密碼設定流程,密碼強度要符合選擇的才能設定
$ sudo mysql_secure_installation
  1. 密碼設定完成之後,就可以用以下指令進入 MySQL
$ mysql -u root -p

🐳 安裝 MySQL Workbench

MySQL Workbench 是一個官方提供的管理資料庫的 GUI 工具,在安裝這個工具的時候,也有遇到一些錯誤。

我最一開始安裝 MySQL Workbench 方式是透過 linux 的一個新的套件管理工具 snap 去安裝:

$ sudo snap install mysql-workbench-community

但安裝完之後,無法輸入密碼,就沒有辦法連到資料庫,所以有裝等於跟沒裝一樣。後來上網一查發現應該是 snap 和 apt 的底層運作原理不同,至於底層是如何運作的,這部分我就不太知道了。

於是把用 snap 安裝的 MySQL Workbench 砍了,改成用 apt 來安裝:

  1. 先去官方網站下載安裝包
  2. 在終端輸入以下指令:
$ cd ~/Downloads #中文的話是下載
$ sudo apt-get install ./mysql-workbench-community_8.0.20-1ubuntu20.04_amd64.deb #記得改成相對應的檔名
  1. 安裝完成後啟動 MySQL Workbench,應該就可以輸入密碼連上資料庫了!

🐳 參考資料

- + \ No newline at end of file diff --git a/docs/notes/coding-style-guide/html-and-css.html b/docs/notes/coding-style-guide/html-and-css.html index a1c93c4..716836a 100644 --- a/docs/notes/coding-style-guide/html-and-css.html +++ b/docs/notes/coding-style-guide/html-and-css.html @@ -10,13 +10,13 @@ - + - + \ No newline at end of file diff --git a/docs/notes/coding-style-guide/javascript.html b/docs/notes/coding-style-guide/javascript.html index 60584cb..6882a06 100644 --- a/docs/notes/coding-style-guide/javascript.html +++ b/docs/notes/coding-style-guide/javascript.html @@ -10,13 +10,13 @@ - + - + \ No newline at end of file diff --git a/docs/notes/coding-style-guide/react.html b/docs/notes/coding-style-guide/react.html index 3bb3bf1..391140d 100644 --- a/docs/notes/coding-style-guide/react.html +++ b/docs/notes/coding-style-guide/react.html @@ -10,13 +10,13 @@ - +

React

在寫 React 的時候要特別注意的 coding style(自己常常忘記),其他的就按照 javascript coding style guide 就可以了。

🐳 Rules

🦀 Quotes

Always use double quotes (") for JSX attributes, but single quotes (') for all other JS ans CSS.

eslint: jsx-quotes

why: Regular HTML attributes also typically use double quotes instead of single, so JSX attributes mirror this convention.

example:

// bad
<Foo bar='bar' />

// good
<Foo bar="bar" />
// bad
<Foo style={{ left: "20px" }} />

// good
<Foo style={{ left: '20px' }} />

🦀 Buttons

This rules enforces an explicit type attribute for all the button elements and checks that its value is valid per spec (i.e., is one of "button", "submit", and "reset").

eslint-plugin-react: button-has-type

why: The default value of type attribute for button HTML element is "submit" which is often not the desired behavior and may lead to unexpected page reloads.

example:

// bad
<button>Hello</button>

// good
<button type="button">Hello</button>

🦀 No inline function in jsx

Do not write a bind call or arrow function in a JSX prop.

eslint-plugin-react: jsx-no-bind

why: A bind call or arrow function in a JSX prop will create a brand new function on every single render. This is bad for performance, as it may cause unnecessary re-renders if a brand new function is passed as a prop to a component that uses reference equality check on the prop to determine if it should update.

note: 平常寫的時候應該是不需要這麼嚴格,比較要注意的是:如果已經把 event handler 封裝成 function 的話,就要特別檢查一下是不是可以避免寫 inline function。

example:

// bad
<Button onClick={(e) => console.log(e)}>Hello</Button>

// good
const handleClickButton = (e) => {
console.log(e);
}
<Button onClick={handleClickButton}>Hello</Button>
// bad
const handleChange = (e) => {
setValue(e.target.value);
console.log(e.target.value);
// ...
}
<input value="Hello" onChange={(e) => handleChange(e)} />

// good
const handleChange = (e) => {
setValue(e.target.value);
console.log(e.target.value);
// ...
}
<input value="Hello" onChange={handleChange} />

🐳 Resource

- + \ No newline at end of file diff --git a/docs/notes/data-structure/binary-tree-traversal.html b/docs/notes/data-structure/binary-tree-traversal.html index 5aa4b59..4dc4e9b 100644 --- a/docs/notes/data-structure/binary-tree-traversal.html +++ b/docs/notes/data-structure/binary-tree-traversal.html @@ -10,13 +10,13 @@ - +

Binary Tree Traversal 二元樹走訪

🐳 Definition 定義

在 leetcode 的教學當中,樹的定義如下:

A tree is a frequently-used data structure to simulate a hierarchical tree structure.

Each node of the tree will have a root value and a list of references to other nodes which are called child nodes. From graph view, a tree can also be defined as a directed acyclic graph which has N nodes and N-1 edges.

二元樹的定義如下:

A Binary Tree is one of the most typical tree structure. As the name suggests, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child.

簡單來說,如果將二元樹畫成圖的話,會長得像下面的樣子:

🐳 How to Traverse A Tree 遍歷二元樹

與二元樹相關最常見的 leetcode 題就是如何遍歷二元樹了,遍歷指的是在不重複的情況下,存取樹的所有節點。目前有四種方式可以遍歷二元樹:

🦀 Pre-order Traversal

Pre-order traversal is to visit the root first. Then traverse the left subtree. Finally, traverse the right subtree.

遍歷二元樹的順序:

用 javascript 來實作 Pre-order Traversal:

/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number[]}
*/

var preorderTraversal = function(root) {
const res = [];
helper(root, res);
return res;
};

const helper = (treeNode, res) => {
if (!treeNode) return;
res.push(treeNode.val);
helper(treeNode.left, res);
helper(treeNode.right, res);
};

🦀 In-order Traversal

In-order traversal is to traverse the left subtree first. Then visit the root. Finally, traverse the right subtree.

順序:

用 javascript 來實作 In-order Traversal:

/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number[]}
*/
var inorderTraversal = function(root) {
const res = [];
helper(root, res);
return res;
};

const helper = (treeNode, res) => {
if (!treeNode) return;
helper(treeNode.left, res);
res.push(treeNode.val);
helper(treeNode.right, res);
};

🦀 Post-order Traversal

Post-order traversal is to traverse the left subtree first. Then traverse the right subtree. Finally, visit the root.

順序:

用 javascript 來實作 Post-order Traversal:

/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number[]}
*/
var postorderTraversal = function(root) {
const res = [];
helper(root, res);
return res;
};

const helper = (treeNode, res) => {
if (!treeNode) return;
helper(treeNode.left, res);
helper(treeNode.right, res);
res.push(treeNode.val);
};
caution

樹(tree)裡面的每一個節點(node)都要按照上面提到的順序來遍歷才算完成。

🦀 Level Order Traversal

Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).

以下面的 Binary Tree 為例:

遍歷的順序會是:3 > 9 > 20 > 15 > 7

用 javascript 來實作 Level Order Traversal:

初步想法:
1. 用一個 array 當作 waiting list,表示處理節點的順序,要記得節點和節點的階層。
2. 用另外一個 array 來存處理好的節點。
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number[][]}
*/

var levelOrder = function(root) {
if (root === null || root.length === 0) {
return [];
}

const result = [];
const waitingList = [ { level: 0, node: root } ];

while (waitingList.length > 0) {
// 處理 waiting list 當前的節點
const currentNode = waitingList.shift();
const { level, node } = currentNode;
if (!result[level]) {
result[level] = [node.val];
} else {
result[level].push(node.val);
}

// 將當前節點的子節點加入 waiting list
if (node.left) {
waitingList.push({ level: level + 1, node: node.left });
}
if (node.right) {
waitingList.push({ level: level + 1, node: node.right });
}
}

return result;
};
info

除了使用遞迴來實作走訪二元樹之外,也可以使用 DFS(深度優先搜尋演算法)。但我還不會 DFS...

🐳 學習資源

- + \ No newline at end of file diff --git a/docs/notes/data-structure/priority-queue.html b/docs/notes/data-structure/priority-queue.html index 396fe4e..7c45d28 100644 --- a/docs/notes/data-structure/priority-queue.html +++ b/docs/notes/data-structure/priority-queue.html @@ -10,14 +10,14 @@ - + - + \ No newline at end of file diff --git a/docs/notes/data-structure/recursion.html b/docs/notes/data-structure/recursion.html index b7a800c..6b59652 100644 --- a/docs/notes/data-structure/recursion.html +++ b/docs/notes/data-structure/recursion.html @@ -10,13 +10,13 @@ - +
-

Recursion 遞迴

🐳 遞迴的種類

如果一個 function 裡面有 self-calling 的敘述,便稱為遞迴,遞迴概略可以分為三個種類,分別是:

  • Direct Recursion
  • Indirect Recursion
  • Tail Recursion

下面舉一些簡單的例子來說明這三個遞迴。

🦀 Direct Recursion

Direct Recursion,直接遞迴,應該蠻好理解的。如果某個 function 在 function 內部呼叫自己,就可以稱為直接遞迴。可以參考下面的 psuedo code:

void directRecursionFunction()
{
// some code...

directRecursionFunction();

// some code...
}

🦀 Indirect Recursion

Indirect Recursion,間接遞迴,意思是指多個 module 之間,彼此互相呼叫,形成 calling cycle。例如:假設目前有三個 function:module Amodule Bmodule C,這三個 function 彼此互相呼叫,便會形成間接遞迴,如下圖。

note

像上面那種 function 互相 call 來 call 去,互相高度依賴的狀況(高耦合),盡量不要在實際開發中寫出來,會很可怕。

🦀 Tail Recursion

Tail Recursion,尾端遞迴,其實是直接遞迴的一種,只是在 recursion 之後,下一個可執行的敘述就是 END 敘述。會特別把這個種類帖出來是因為這種地回可以在 compiler 裡面做到最佳化。(最佳化的意思,某種程度上可以理解成「將遞迴改成非遞迴」)

🐳 Recursion v.s. Iteration(Non-recusrion)

  • 任何問題的解法必定可以用兩種演算法去解決:遞迴與非遞迴。
  • 遞迴與非遞迴演算法兩者可以互相轉換
    • 遞迴改為非遞迴,有標準 SOP
    • 非遞迴改回遞迴,沒有標準 SOP(需要靈感)

示意圖

比較表

遞迴非遞迴
程式碼較精簡較冗長
區域變數、暫存變數使用很少或是沒有使用量多
表達問題的能力powerfulweak
除錯困難容易
程式執行時間較久,比較沒有效率較短,較有效率
memory stack 空間需要額外的 stack 空間支持,所以執行時需要較多的動態空間無需 stack support

🐳 題目練習

🦀 Factorial N! 階乘

Question 1: Write an Interative function Fac(N) or pseudo code for N!

function fac(n) {
let result = 1;
for (let i = 1; i <= n; i++>) {
result = result * i;
}
return result;
}

Question 2: Write a Recursive function Fac(N) or pseudo code for N!

先把階乘的遞迴數學定義寫出來:

n!={1, if n0(n1)!n, if n>0n! = \begin{cases} 1,\ if\ n \ne 0 \\ (n-1)! * n,\ if\ n > 0 \end{cases}

然後再寫出遞迴的程式碼:

function fac(n) {
if (n === 0) {
return 1;
} else {
return fac(n-1) * n;
}
}
tip

解遞迴相關問題的訣竅:先想出遞迴的數學定義,再把數學定義轉換成程式碼!

🦀 Fibonacci Number

Definition

{F0=0F1=1Fn=Fn1+Fn2, for n2\begin{cases} F_{0} = 0 \\ F_{1} = 1 \\ F_{n} = F_{n-1} + F_{n-2},\ for\ n \ge 2 \end{cases}

Question 1: Write a Recurisive function for Fib(N)

function fib(n) {
if (n === 0) {
return 0;
}
if (n === 1) {
return 1;
}
return fib(n-1) + fib(n-2);
}

Quesiton 2: Write a Interative function for Fib(N)

function fib(n) {
if (n === 0) {
return 0;
} else if (n === 1) {
return 1;
} else {
let a = 0;
let b = 1;
let c;
for (let i = 2; i <= n; i++) {
c = a + b;
a = b;
b = c;
}
return c;
}
}

🦀 Greatest Common Divisor (GCD) 最大公因數

Definition

用輾轉相除法來計算兩個數字(A, B)的最大公因數,定義如下:

{B, if (AmodB)=0GCD(B,AmodB), otherwise\begin{cases} B,\ if\ (A \mod B) = 0 \\ GCD(B, A \mod B),\ otherwise \end{cases}

Write the recursive code for GCD(A, B)

function gcd(a, b) {
if (a % b === 0) return b;
return gcd(b, a % b);
}

🦀 Tower of Hanoi 河內塔

題目敘述

有三個柱子,假設分別叫做 A、B、C,其中 A 柱子上有 n 個大小不同的盤子,這些盤子從上到下按照大小排放,最上面的盤子最小,最下面的盤子最大,現在要把這些盤子從 A 柱子移到 C 柱子,但必須遵守以下規則:

  1. 每次只能移動一個盤子
  2. 大的盤子不能放在小的盤子上面

請把所有的移動步驟都 print 出來。

解題思路

       A            B           C

│ │ │
│ │ │
│ │ │
1 ┌─┼─┐ │ │
2 ┌┼┼┼┼┼┐ │ │
3 ┌┼┼┼┼┼┼┼┐ │ │
─┴───────┴─ ────┴──── ────┴────

先從例子開始想,假設目前有 A、B、C 三個柱子,然後有 3 個盤子在 A 柱子上面,則步驟如下:


  1. move disk 1 from A to C
  2. move disk 2 from A to B
  3. move disk 1 from C to B

  1. move disk 3 from A to C

  1. move disk 1 from B to A
  2. move disk 2 from B to C
  3. move disk 1 from A to C

把步驟分成三個區塊來看:

  1. 第 1. ~ 3. 步驟是把 1 ~ 2 號的盤子都先從 A 柱子移到 B 柱子
  2. 第 4. 步驟是把最後一個第 3 號盤子直接從 A 柱子移到 C 柱子
  3. 接下來是把 B 柱子上的盤子都移到 C 柱子

例外情況:如果只有一個盤子的話,就直接從 A 柱子搬到 C 柱子就可以了。

function hanoi(n, from, to, via) {
if (n === 1) {
console.log(`move disk 1 from ${from} to ${to}`);
} else {
hanoi(n - 1, from, via, to); // 先把 n - 1 個盤子都移到中間的柱子
console.log(`move disk ${n} from ${from} to ${to}`); // 把最下面的盤子移到目標柱子
hanoi(n - 1, via, to, from); // 再把剩下的 n - 1 個盤子移到目標柱子
}
}

河內塔的遞迴定義

把上面提到的步驟用數學式來表示,T(n)T(n) 表示移動 n 個盤子時程式所需的執行次數,如果解出 T(n)T(n) 就表示解出了這個 function 的時間複雜度:

T(n)=T(n1)+1+T(n1), 且 T(1)=1=2T(n1)+1\begin{equation*} \begin{split} T(n) &= T(n - 1) + 1 + T(n - 1),\ 且\ T(1) = 1\\ &= 2T(n - 1) + 1 \end{split} \end{equation*}

T(n)T(n),用展開代入法:

T(n)=2T(n1)+1=2[2T(n2)+1]+1=4T(n2)+3=4[2T(n3)+1]+3=8T(n3)+7=16T(n4)+15=2n1T(n(n1))+(2n11)=2n1T(1)+(2n11)=2n1+(2n11)=2n1O(2n)\begin{equation*} \begin{split} T(n) &= 2 * T(n - 1) + 1\\ &= 2 * [2 * T(n - 2) + 1] + 1\\ &= 4 * T(n - 2) + 3\\ &= 4 * [2 * T(n - 3) + 1] + 3\\ &= 8 * T(n - 3) + 7\\ &= 16 * T(n - 4) + 15\\ &= 2^{n-1} * T(n - (n - 1)) + (2^{n-1} - 1)\\ &= 2^{n-1} * T(1) + (2^{n-1} - 1)\\ &= 2^{n-1} + (2^{n-1} - 1)\\ &= 2^n - 1 \approx O(2^n) \end{split} \end{equation*}
- +

Recursion 遞迴

🐳 遞迴的種類

如果一個 function 裡面有 self-calling 的敘述,便稱為遞迴,遞迴概略可以分為三個種類,分別是:

  • Direct Recursion
  • Indirect Recursion
  • Tail Recursion

下面舉一些簡單的例子來說明這三個遞迴。

🦀 Direct Recursion

Direct Recursion,直接遞迴,應該蠻好理解的。如果某個 function 在 function 內部呼叫自己,就可以稱為直接遞迴。可以參考下面的 psuedo code:

void directRecursionFunction()
{
// some code...

directRecursionFunction();

// some code...
}

🦀 Indirect Recursion

Indirect Recursion,間接遞迴,意思是指多個 module 之間,彼此互相呼叫,形成 calling cycle。例如:假設目前有三個 function:module Amodule Bmodule C,這三個 function 彼此互相呼叫,便會形成間接遞迴,如下圖。

note

像上面那種 function 互相 call 來 call 去,互相高度依賴的狀況(高耦合),盡量不要在實際開發中寫出來,會很可怕。

🦀 Tail Recursion

Tail Recursion,尾端遞迴,其實是直接遞迴的一種,只是在 recursion 之後,下一個可執行的敘述就是 END 敘述。會特別把這個種類分出來是因為這種遞迴可以在 compiler 裡面做到最佳化。(最佳化的意思,某種程度上可以理解成「將遞迴改成非遞迴」)

🐳 Recursion v.s. Iteration(Non-recusrion)

  • 任何問題的解法必定可以用兩種演算法去解決:遞迴與非遞迴。
  • 遞迴與非遞迴演算法兩者可以互相轉換
    • 遞迴改為非遞迴,有標準 SOP
    • 非遞迴改回遞迴,沒有標準 SOP(需要靈感)

示意圖

比較表

遞迴非遞迴
程式碼較精簡較冗長
區域變數、暫存變數使用很少或是沒有使用量多
表達問題的能力powerfulweak
除錯困難容易
程式執行時間較久,比較沒有效率較短,較有效率
memory stack 空間需要額外的 stack 空間支持,所以執行時需要較多的動態空間無需 stack support

🐳 題目練習

🦀 Factorial N! 階乘

Question 1: Write an Interative function Fac(N) or pseudo code for N!

function fac(n) {
let result = 1;
for (let i = 1; i <= n; i++>) {
result = result * i;
}
return result;
}

Question 2: Write a Recursive function Fac(N) or pseudo code for N!

先把階乘的遞迴數學定義寫出來:

n!={1, if n0(n1)!n, if n>0n! = \begin{cases} 1,\ if\ n \ne 0 \\ (n-1)! * n,\ if\ n > 0 \end{cases}

然後再寫出遞迴的程式碼:

function fac(n) {
if (n === 0) {
return 1;
} else {
return fac(n-1) * n;
}
}
tip

解遞迴相關問題的訣竅:先想出遞迴的數學定義,再把數學定義轉換成程式碼!

🦀 Fibonacci Number

Definition

{F0=0F1=1Fn=Fn1+Fn2, for n2\begin{cases} F_{0} = 0 \\ F_{1} = 1 \\ F_{n} = F_{n-1} + F_{n-2},\ for\ n \ge 2 \end{cases}

Question 1: Write a Recurisive function for Fib(N)

function fib(n) {
if (n === 0) {
return 0;
}
if (n === 1) {
return 1;
}
return fib(n-1) + fib(n-2);
}

Quesiton 2: Write a Interative function for Fib(N)

function fib(n) {
if (n === 0) {
return 0;
} else if (n === 1) {
return 1;
} else {
let a = 0;
let b = 1;
let c;
for (let i = 2; i <= n; i++) {
c = a + b;
a = b;
b = c;
}
return c;
}
}

🦀 Greatest Common Divisor (GCD) 最大公因數

Definition

用輾轉相除法來計算兩個數字(A, B)的最大公因數,定義如下:

{B, if (AmodB)=0GCD(B,AmodB), otherwise\begin{cases} B,\ if\ (A \mod B) = 0 \\ GCD(B, A \mod B),\ otherwise \end{cases}

Write the recursive code for GCD(A, B)

function gcd(a, b) {
if (a % b === 0) return b;
return gcd(b, a % b);
}

🦀 Tower of Hanoi 河內塔

題目敘述

有三個柱子,假設分別叫做 A、B、C,其中 A 柱子上有 n 個大小不同的盤子,這些盤子從上到下按照大小排放,最上面的盤子最小,最下面的盤子最大,現在要把這些盤子從 A 柱子移到 C 柱子,但必須遵守以下規則:

  1. 每次只能移動一個盤子
  2. 大的盤子不能放在小的盤子上面

請把所有的移動步驟都 print 出來。

解題思路

       A            B           C

│ │ │
│ │ │
│ │ │
1 ┌─┼─┐ │ │
2 ┌┼┼┼┼┼┐ │ │
3 ┌┼┼┼┼┼┼┼┐ │ │
─┴───────┴─ ────┴──── ────┴────

先從例子開始想,假設目前有 A、B、C 三個柱子,然後有 3 個盤子在 A 柱子上面,則步驟如下:


  1. move disk 1 from A to C
  2. move disk 2 from A to B
  3. move disk 1 from C to B

  1. move disk 3 from A to C

  1. move disk 1 from B to A
  2. move disk 2 from B to C
  3. move disk 1 from A to C

把步驟分成三個區塊來看:

  1. 第 1. ~ 3. 步驟是把 1 ~ 2 號的盤子都先從 A 柱子移到 B 柱子
  2. 第 4. 步驟是把最後一個第 3 號盤子直接從 A 柱子移到 C 柱子
  3. 接下來是把 B 柱子上的盤子都移到 C 柱子

例外情況:如果只有一個盤子的話,就直接從 A 柱子搬到 C 柱子就可以了。

function hanoi(n, from, to, via) {
if (n === 1) {
console.log(`move disk 1 from ${from} to ${to}`);
} else {
hanoi(n - 1, from, via, to); // 先把 n - 1 個盤子都移到中間的柱子
console.log(`move disk ${n} from ${from} to ${to}`); // 把最下面的盤子移到目標柱子
hanoi(n - 1, via, to, from); // 再把剩下的 n - 1 個盤子移到目標柱子
}
}

河內塔的遞迴定義

把上面提到的步驟用數學式來表示,T(n)T(n) 表示移動 n 個盤子時程式所需的執行次數,如果解出 T(n)T(n) 就表示解出了這個 function 的時間複雜度:

T(n)=T(n1)+1+T(n1), 且 T(1)=1=2T(n1)+1\begin{equation*} \begin{split} T(n) &= T(n - 1) + 1 + T(n - 1),\ 且\ T(1) = 1\\ &= 2T(n - 1) + 1 \end{split} \end{equation*}

T(n)T(n),用展開代入法:

T(n)=2T(n1)+1=2[2T(n2)+1]+1=4T(n2)+3=4[2T(n3)+1]+3=8T(n3)+7=16T(n4)+15=2n1T(n(n1))+(2n11)=2n1T(1)+(2n11)=2n1+(2n11)=2n1O(2n)\begin{equation*} \begin{split} T(n) &= 2 * T(n - 1) + 1\\ &= 2 * [2 * T(n - 2) + 1] + 1\\ &= 4 * T(n - 2) + 3\\ &= 4 * [2 * T(n - 3) + 1] + 3\\ &= 8 * T(n - 3) + 7\\ &= 16 * T(n - 4) + 15\\ &= 2^{n-1} * T(n - (n - 1)) + (2^{n-1} - 1)\\ &= 2^{n-1} * T(1) + (2^{n-1} - 1)\\ &= 2^{n-1} + (2^{n-1} - 1)\\ &= 2^n - 1 \approx O(2^n) \end{split} \end{equation*}
+ \ No newline at end of file diff --git a/docs/notes/data-structure/stack-and-queue.html b/docs/notes/data-structure/stack-and-queue.html index baa4fcb..f9d4333 100644 --- a/docs/notes/data-structure/stack-and-queue.html +++ b/docs/notes/data-structure/stack-and-queue.html @@ -10,13 +10,13 @@ - +

Stack and Queue 堆疊與佇列

🐳 寫在前面

這邊想要紀錄一些開始念資料結構之後的初步感想,讓未來的自己可以回顧。可能不一定是對的,但就是感想。

雖然不同的程式語言會因為不同的特性提供一些資料型態,比如 JavaScript 有 number, string, boolean, array, class 等等。資料結構比較像是一種以現有的資料型態去設計某種結構,該種結構之所以被設計出來可能是因為時間與空間上的效能考量,或是用來解決需求的問題。

所以學資料結構的時候,除了搞懂每個資料結構的長相、特性、刷題,更需要知道一些實際的應用情境,想要解決什麼樣的問題。

🐳 Array and Linked List

在理解什麼是 stack 跟 queue 之前,要先理解 array 和 linked list 這兩種不同的資料結構。因為 stack 和 queue 其實可以用 array 或是 lnked list 來實作。

array 應該就不用特別解釋了,但如果第一個學習的程式語言是 JavaScript,又沒有學過資料結構的話,可能不會遇到 linked list 這種資料結構。

以我目前的理解來說。C 語言的 array 在宣告的時候也要同時宣告長度,也就是說宣告了 array 需要用到的記憶體用量,所以 array 的長度會是固定的,沒有辦法動態調整。

如果想要使用 C 語言創造一個動態長度的陣列,可以拿取記憶體中任一的單一區塊來存放 data(稱為節點 node),亦即放入值和指標,然後用指標指向下個節點(node),串成一個鍵結串列,類似下圖的概念:

🦀 Array 和 Linked List 的簡單比較

arraylinked list
優點
  • random access:只要利用 index 即可在 O(1) 時間對 array 的資料做存取。
  • 較節省記憶體空間,linked list 需要多一個 pointer 來記錄下一個 node 的記憶體位置。
  • 新增或刪除資料較 array 簡單,只要對所有欲新增/刪除的 node 調整 pointer 即可(時間複雜度:O(1)),不需要如同 array 般搬動其餘元素。
  • linked list 的資料數量可以是動態的,不像 array 會有 resize 的問題。
缺點
  • 新增或刪除資料較麻煩,若要在第一個位置新增資料,就需要 O(n) 時間把 array 中所有元素往後移動。同理,若要刪除第一個位置的資料,也需要 O(n) 時間把 array 中剩餘的元素往前移動。
  • 若資料數量時常在改變,要時常調整矩陣的大小,會花費 O(n) 的時間在搬動資料。
  • linked list 沒有 index,若要找到特定 node,需要從頭開始找起,搜尋的時間複雜度為 O(n)
  • 需要額外的記憶體空間來儲存 pointer。

🐳 Stack 堆疊

Stack 和 Queue 都是可以用來加入資料、取回資料的抽象資料結構,只是他們加入資料和取回資料的 order 不同。

Stack 是採取 LIFO(last-in, first-out) 的方式。最後加入 stack 的資料會最先被讀取。加入資料的方式稱為 push,取回資料的方式稱為 pop。如下面的示意圖:

圖片來源:維基百科
圖片來源:維基百科

stack 的介面描述大致如下:

info

Stack ADT (abstract data type):

  • create(): create an empty stack
  • isFull(): return true if the stack is full, otherwise return false
  • isEmpty(): return true if the stack is empty, otherwise return false
  • push(new-item): add a new item to the top of the stack
  • pop(): remove the top element from the stack and return it to the caller
  • top(): return the top element of the stack without removing it

🦀 用 Array 來實作 Stack

class Stack {
constructor() {
this.items = [];
}

get isEmpty() {
return this.items.length === 0;
}

get stackSize() {
return this.items.length;
}

push = (item) => {
this.items.push(item);
};

pop = () => {
if (this.isEmpty) {
return null;
}
return this.items.pop();
};

top = () => {
return this.items[this.stackSize - 1];
};

// isFull 省略
// 因為 JavaScript 的 array size 動態的,所以沒有特別設計的話就不會 full
}

🦀 用 Linked List 來實作 Stack

// a linked list node
class Node {
constructor(data, next) {
this.data = data;
this.next = next;
}
}

// a stack using linked list
class Stack {
constructor() {
this.top = null;
this.size = 0;
}

get isEmpty() {
return this.size === 0;
}

push = (item) => {
const newNode = new Node(item, this.top);
this.top = newNode;
this.size++;
};

pop = () => {
if (this.isEmpty) {
return null;
}
const poppedNode = this.top;
const newTopNode = this.top.next;
poppedNode.next = null;
this.top = newTopNode;
this.size--;
return poppedNode.data;
};

getTop = () => {
if (this.isEmpty) {
return null;
}
return this.top.data;
};
}

🐳 Queue 佇列

Queue 存取資料的順序是採取先進先出的方式,也就是 first in first out(FIFO)。將資料存入 Queue 裡面稱為 enqueue,將資料從 Queue 中取出稱為 dequeue。概念如下圖所示:

圖片來源:維基百科
圖片來源:維基百科
info

Queue ADT:

  • enqueue(): adds an element to the rear of the queue
  • dequeue(): removes an element from the front of the queue
  • isEmpty(): determines whether the queue is empty
  • isFull(): determines whether the queue is full
  • first or front element: return the element at the front of the queue if it is not empty

🦀 用 Linear Array 來實作 Queue

class Queue {
constructor() {
this.items = [];
}

get isEmpty() {
return this.items.length === 0;
}

getFront = () => {
return this.items[0];
}

enqueue = (item) => {
this.items.push(item);
};

dequeue = () => {
this.items.shift();
};
}

🦀 用 Circular Array 來實作 Queue

class circularQueue {
constructor(arraySize) {
this.items = new Array(arraySize);
this.rear = this.items.length - 1;
this.front = 0;
this.size = 0;
}

get isEmpty() {
return this.size === 0;
}

get isFull() {
return this.size === this.items.length;
}

enQueue = (item) => {
if (this.isFull) return null;
this.rear = (this.rear + 1) % this.items.length;
this.items[this.rear] = value;
this.size++;
}

deQueue = () => {
if (this.isEmpty) return null;
this.front = (this.front + 1) % this.items.length;
this.size--;
}

getFront = () => {
return this.isEmpty ? -1 : this.items[this.front];
}

getRear = () => {
return this.isEmpty ? -1 : this.items[this.rear];
}
}

🦀 用 Linked List 來實作 Queue

class Node {
constructor(data, next) {
this.data = data;
this.next = next;
}
}

class Queue {
constructor() {
this.front = null;
this.rear = null;
this.size = 0;
}

get isEmpty() {
return this.size === 0;
}

enqueue = (item) => {
const newNode = new Node(item, null);
if (!this.front) {
this.front = newNode;
this.rear = newNode;
} else {
this.rear.next = newNode;
this.rear = newNode;
}
this.size++;
}

dequeue = () => {
if (!this.front) {
return null;
}
const dequeuedItem = this.front;
const nextItem = this.front.next;
if (this.front.data === this.rear.data) {
this.rear = null
}
this.front = nextItem;
this.size--;
return dequeuedItem.data;
}

getFront = () => {
return this.front.data;
}

getRear = () => {
return this.rear.data;
}
}

🐳 實際應用

🦀 前端

Stack

  • error call stack
  • 瀏覽器的歷史紀錄
  • 文本或是圖片編輯器的操作紀錄(可以用來做複製復原等等)
  • javascript call stack(javascript 用來處理函數執行的方法)

Queue

  • 瀏覽器的非同步處理(event queue / task queue)
  • 通知功能

🦀 其他

Stack

  • parse context-free languages
  • evaluate arithmetic expressions(infix, postfix, prefix)
  • function call, recursive call management
  • reverse the input data
  • traverse trees(preorder, inorder, postorder)
  • DFS graph traversal
  • eight queen problem
  • maze problem

Queue

  • OS 中的各種應用:ready queue、waiting queue、job queue、I/O Derive queue etc.
  • buffering
  • 基於佇列理論的計算機效能模擬
  • 圖形的 BFS
  • binary tree 的 level order traversal

🐳 Resource

- + \ No newline at end of file diff --git a/docs/notes/data-structure/tree-and-binary-tree.html b/docs/notes/data-structure/tree-and-binary-tree.html index 72658f8..892511d 100644 --- a/docs/notes/data-structure/tree-and-binary-tree.html +++ b/docs/notes/data-structure/tree-and-binary-tree.html @@ -10,13 +10,13 @@ - +

Tree and Binary Tree 樹與二元樹

🐳 Tree 樹

🦀 定義

  • 由至少一個 node 組成,不得為空。
  • 至少有一個特定 node 稱為 root。
  • 其餘 nodes 分為 T1T_{1} ~ TmT_{m} 個集合,稱為 subtree of root。

以下圖的 tree 為例說明用來描述 tree 的名詞:

  • node's degree:一個 node 擁有的 subtree(子樹)的個數。例如:A 的 degree 是 3,D 的 degree 是 2,J 的 degree 是 0。
  • root:樹中最上層的 node,也是唯一一個 parent 為 null 的 node。例如:A 是這個 tree 的 root。
  • leaf:沒有 child/subtree 的 node 稱為 leaf。例如:E、F、G、H、I、J 都是 leaf。
  • non-leaf:不是 leaf 的 node 稱為 non-leaf。例如:A、B、C、D 都是 non-leaf。
  • parent and child:以箭頭的指向來區分,被指向者為 child,指向者為 parent,例如:A 是 BCD 的 parent,BCD 是 A 的 children。
  • sibling:擁有相同 parent 的 node 們,互相稱為 sibling,例如:A 是 BCD 的 parent,所以 BCD 是 siblings。
  • ancestors:如圖中,以 F 的角度觀察,所有能夠以「指向 parent」的方式找到的 node,都稱為 F 的 ancestors,因此 AB 為 F 的 ancestors。
  • descendants:如圖中,以 A 的角度觀察,所有能夠以「parent 指向 child」的方式找到的 node,都稱為 A 的 descendant,因此整棵樹除了 A 以外皆為 A 的 descendant,以此類推。
  • node's level:root 的 level 為 0 或 1,其他 node 的 level 為其 parent 的 level 加一。
  • height:樹的高度,也就是 node's level 取最大值。
  • tree's degree:所有 node's degree 取最大值。
  • forest:由 tree 所形成的集合,可以為空。

🦀 Representations 樹的表示方法

use linked list to represent tree directly

用 linked list 來表示 tree,假設 trees degree=ktree's\ degree = k,node 的 structure 可以設計成:

以上面的 node structure 來表示下圖的 tree:

trees degree=3tree's\ degree = 3

會變成:

缺點

這個方法極度浪費記憶體空間。

WHY
假設 tree 有 n 個 nodetrees degree=k會需要準備 nk 條 links,其中只有 n1 條 links 非 nullnull link=nk(n1) 條浪費比例=nk(n1)nk,只有在 n=2 的時候浪費比例最少。\begin{align*} & 假設\ tree\ 有\ n\ 個\ node,tree's\ degree = k \\ & \therefore 會需要準備\ n * k\ 條 \ links,其中只有\ n - 1\ 條\ links\ 非\ null。 \\ & \therefore null\ link = nk - (n - 1)\ 條 \\ & \therefore 浪費比例 = \frac{nk - (n - 1)}{nk},只有在\ n = 2\ 的時候浪費比例最少。 \end{align*}

child-sibling

還是用 linked list 來表示 tree,但是換一個角度來重新設計 node structure,來解決前一個方法浪費記憶體空間的問題。

來重新設計 node structure 成如下圖的結構:

  1. child:pointer,指向 「left-most」 child
  2. sibling:pointer,指向 node 右邊的 sibling

現在以上面重新設計的 node structure 來表示下圖的 tree:

trees degree=3tree's\ degree = 3

會變成:

括號法

父點(子點...子點) 表示父與子點之間的組成關係,可以巢狀表示。

舉個例子,以括號法來表示下圖的 tree:

可以寫成:A(B(EF)C(G)D(HIJ))

🐳 Binary Tree 二元樹

🦀 定義

由至少一個 node 組成,可以為空,若不為空,則滿足:

  • 有 root 及左右子樹
  • 左右子樹也是 binary tree

🦀 Binary Tree 的三個定理

假設:root level = 1,【定理一】:

The ith level in a binary tree has at most 2i1 nodesThe\ i^{th}\ level\ in\ a\ binary\ tree\ has\ at\ most\ 2^{i-1}\ nodes

證明:用數學歸納法


假設:root level = 1,【定理二】:

The binary tree with height H, has at most 2H1 nodes, at least H nodes.The\ binary\ tree\ with\ height\ H,\ has\ at\ most\ 2^{H}-1\ nodes,\ at\ least\ H\ nodes.

證明:

(1)最多nodes,也就是每個節點長好長滿:節點數=20+21+...+2H1=1(12H)12=2H1(2)最少nodes,也就是每個level只有一個節點,所以節點數=H\begin{align*} &(1) 最多 nodes,也就是每個節點長好長滿:節點數 = 2^{0} + 2^{1} + ... + 2^{H-1} = \frac{1*(1-2^{H})}{1-2} = 2^{H} - 1\\ &(2) 最少 nodes,也就是每個 level 只有一個節點,所以節點數 = H \end{align*}

假設:root level = 1,【定理三】:

For a nonempty binary tree, if there are n0 leaves and n2 degree2 nodes, then n0 = n2 + 1For\ a\ non-empty\ binary\ tree,\ if\ there\ are\ n_0\ leaves\ and\ n_2\ degree-2\ nodes,\ then\ n_0\ =\ n_2\ +\ 1

證明:

n:node總數n0: degree0 之 node 數\(leaves數)n1: degree1 之 node 數n2: degree2 之 node 數B: branch(分支)總數則 {n=n0+n1+n2=B+1  (1)B=1n1+2n2  (2)將 (2) 式代入 (1) 式得:n0+n1+n2=1n1+2n2+1    n0=n2+1\begin{align*} &令\\ &n: node 總數\\ &n_0:\ degree-0\ 之\ node\ 數\(即 leaves 數)\\ &n_1:\ degree-1\ 之\ node\ 數\\ &n_2:\ degree-2\ 之\ node\ 數\\ &B:\ branch(分支)總數\\ \\ &則\ \begin{cases} n = n_0 + n_1 + n_2 = B + 1\ \ (1)\\ B = 1 * n_1 + 2 * n_2\ \ (2)\\ \end{cases} \\ &將\ (2)\ 式代入\ (1)\ 式得:n_0 + n_1 + n_2 = 1n_1 + 2n_2 + 1 \iff n_0 = n_2 + 1 \end{align*}

🦀 Binary Tree 的種類

種類定義
Skewed Binary Tree
  • Left-skewed Binary Tree: each non-leaf node has left-child only, without right child.
  • Right-skewed Binary Tree: each non-leaf node has right-child only, without left child.
  • 如果有 nn 個節點,則樹高為 nn。(if root level = 11)
Full Binary Tree
  • 具有最多節點的 Binary Tree
  • if the height is hh, and root level is 11, then Full Binary Tree has 2h12^{h-1} nodes.
Complete Binary Tree
  • 節點增長順序:由上而下,同一 level 由左而右。
  • 如果高度為 hh,則節點數大於 2h112^{h-1} - 1,小於等於 2h12^{h} - 1
Strict Binary Tree
  • Each non-leaf node will have two children. There is no degree-1 nodes exist.

🦀 Binary Tree Representations

有兩種表示二元樹的方法,分別是用 array 或是 linked list。下面表格是針對這兩種方式的優缺點比較:

ArrayLinked List
優點
  1. 容易存取左右子點與父點
  2. 對於 full/complete binary tree 可以充分利用記憶體空間,沒有浪費
  1. 容易增刪節點
  2. 如果是 skewed binary tree,用 linked list 會比用 array 節省記憶體空間
缺點
  1. 不容易增刪節點
  2. 如果是 skewed binary tree,用 array 來表示非常浪費記憶體空間。若高度為 HH,浪費的格數為 2H1H2^{H} - 1 - H
  1. 不容易存取父節點
  2. 可以參考 這邊

🐳 Resource

- + \ No newline at end of file diff --git a/docs/notes/intro.html b/docs/notes/intro.html index 461e34f..209359a 100644 --- a/docs/notes/intro.html +++ b/docs/notes/intro.html @@ -10,13 +10,13 @@ - +

首頁

關於筆記

這邊會紀錄一些技術相關的學習筆記。

主要會紀錄一些目前正在學習的東西,因為不是正式的部落格文章發表,所以寫法會比較隨興,可能也會有很多尚未完成的地方。

關於我

Hello! 👋 I’m Simone! 👻

目前還是個前端小菜鳥。

喜歡閱讀、看電影、宅在家打電動、研究和學習技術,曾經的夢想是像《過於喧囂的孤獨》裡的主角一樣,擁有一個書多到滿出來,如果地震一來可能會被書壓垮的房間。現在的夢想是希望自己每天都可以做快樂的事情。

- + \ No newline at end of file diff --git a/docs/notes/react/use-effect.html b/docs/notes/react/use-effect.html index ba9b515..e988bfa 100644 --- a/docs/notes/react/use-effect.html +++ b/docs/notes/react/use-effect.html @@ -10,13 +10,13 @@ - +

useEffect 的坑

child 的 useEffect 會先被執行,才執行 parent 的 useEffect

- + \ No newline at end of file diff --git "a/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/execution-contexts-and-lexical-Environments.html" "b/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/execution-contexts-and-lexical-Environments.html" index 9f62c5c..7d4a4b4 100644 --- "a/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/execution-contexts-and-lexical-Environments.html" +++ "b/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/execution-contexts-and-lexical-Environments.html" @@ -10,7 +10,7 @@ - + @@ -22,7 +22,7 @@ The simplest definition when talking about JavaScript.

🦀 JavaScript and 'undefined'

直接來看看兩個不同的例子:

// 範例一
var a;
console.log(a);

// 印出 undefined
// 範例二
console.log(a);

// 報錯:印出 Uncaught ReferenceError: a is not defined

我們可以知道範例一和範例二都印出了東西,但 undefined 和 is not defined 從英文字面上來看不是一樣的意思嗎?其實這兩者對 JavaScript 來說是兩個不一樣的東西。

undefined 在這裡的意思是:JavaScript 已經為這個變數預留了一個記憶體的位置,但因為這個變數還沒有被賦值,所以 JavaScript 就先暫時設了一個初始值給你,然後這個初始值叫做「undefined」。所以我們可以把 undefined 理解為「尚未設定的值」。

is not defined 的意思則是:JaveScript 在記憶體位置當中並沒有尋找到該變數,所以它就會報錯,告訴我們 Uncaught ReferenceError: a is not defined

🦀 Single Threaded 單執行緒

One command at a time.
Under the hood of the browser, maybe not.

JavaScript 是一個單執行緒的語言,也就是說 JavaScript 在執行的時候,一次只能做一件事情。但是如果我們是在 browser 這個環境之下執行 JavaScript,browser 本身可以幫我做到多執行緒的事情,但是就像開頭提到的 JavaScript 本身是一個單執行緒的語言。

🦀 Synchrnous Execution 同步執行

One at a time and in order.

JavaScript 是同步執行的,也就是說做完一件事情,才會做下一件事情,而且會按照事情排好的順序依序做下去。

🐳 The Global Environment and The Global Object

當 JavaScript 在執行的時候,它一定會在一個全域執行環境 (Global Environment) 當中執行,在這個環境當中會有一個全域物件 (Global Object),以及一個很特殊的 variable 「this」。

┌───────────────────────────────────────────────────────────┐
│ Execution Context(Global) │
│ ┌──────────────────┐ ┌───────────────────┐ │
│ │ │ │ │ │
│ │ Global Object │ │ this │ │
│ │ │ │ │ │
│ └──────────────────┘ └───────────────────┘ │
└───────────────────────────────────────────────────────────┘

當我們在瀏覽器中執行 JavaScript 時,瀏覽器是一個 runtime,所以此時 JavaScript 所在的 Global Execution Context,就是瀏覽器的全域環境,在這個環境裡有一個 Global Object 叫做「window」。當我們在這個全域環境當中直接打 console.log(this); 的時候,this 指的就是 window。至於當我們在 node.js 當中執行 JavaScript 時,此時的 Global Object 和 this 就會是 node.js 設定好的。

假設目前在瀏覽器中使用 var 宣告一個變數 a ,而且這個變數 a 等於 1 時,其實就是在瀏覽器當中的 Global Object 中建立一個 Name/Value Pair,所以可以透過 window.a 這個指令來找到剛才宣告的變數 a。如以下程式碼所示:

var a = 1;

a; // 1
window.a; // 1
caution

es6 新增了兩個新的宣告方式 const 以及 let,這兩個的用法與 var 不同,如果在全域環境使用 constlet,並不會在 Global Object 中建立一個 Name/Value Pair,避免了一些使用 var 會產生的問題。這三者的比較可能會之後再寫一篇筆記做更深入探討。

🐳 The Execution Context

🦀 Creation and Hoisting

在開始說明 JavaScript Engine 如何創建執行環境時,我們先來看看 JavaScript 的特殊現象「Hoisting」。首先來看看以下範例一的程式碼:

// 範例一
var a = 'Hello World!';

function b() {
console.log('Called b!');
}

b();
console.log(a);

將上述的程式碼執行之後,我們可以很輕鬆也如常的預期會先印出 Called b!,再印出 Hello World!,但如果我們把程式碼改成下面這樣呢?

// 範例二
b();
console.log(a);

var a = 'Hello World!';

function b() {
console.log('Called b!');
}

如果程式碼是從上到下,一行一行依序執行的話,照理來說在跑第一行的時候就會報錯,因為我們在尚未宣告變數和函數時,就對該變數或函數進行呼叫。但在 JavaScript 裡面卻不是這樣,將以上程式碼執行之後,JavaScript會幫我們印出:

Called b!
undefined

JavaScript 並沒有幫我們報錯,反而印出東西來,這是因為在這當中存在著「Hoisting」的現象。很多網路上對「Hoisting」的解釋大部分都是:想像 JavaScript Engine 將所寫的宣告的程式碼(但如果是宣告變數的話,只會提升宣告的變數,不會連同賦值的部分一起提升)提升到最上面的地方,比如想像範例二的程式碼變成如下:

funciton b() {
console.log('Called b!');
}

var a;

b();
console.log(a);

a = 'Hello World!';

所以我們才會得到印出 Called b!undefined 的結果。但其實 JavaScript Engine 並不會真的去調動你所寫的程式碼的位置,所以「想像 JavaScript Engine 將所寫的宣告的程式碼(但如果是宣告變數的話,只會提升宣告的變數,不會連同賦值的部分一起提升)提升到最上面的地方」這樣的描述雖然能夠解釋 Hoisting 這個現象,但它並沒有精確地去描述 JavaScript Engine 在 Hoisting 的時候實際上到底做了什麼。

所以 JavaScript Engine 到底做了什麼?在 Execution Context 被創建之後,除了同時創建了 Global Obeject、this 之外,還會同時先預留記憶體位置給變數與函式。

這個「先預留記憶體位置給變數與函式」的動作就是 Hoisting。但要特別注意的地方是:當宣告的 function 被 hoisted 的時候,除了 funciton 的名稱會被 hoisted,整個 funciton 裡面的 code 也會被 hoisted。但如果是使用 var 來宣告變數的時候,只有變數的名稱會被 hoisted,賦值這個動作並不會被 hoisted,然後 JavaScript Engine 會將所有被 hoisted variable 的初始值設為 undefined。

┌────────────────────────────────────────────────────────────────────────────────────┐
│ │
│ Execution Context is Created (Creation Phase) │
│ │
│ ┌────────────────────┐ ┌───────────────────┐ ┌──────────────────┐ │
│ │ Global │ │ │ │ Outer │ │
│ │ │ │ 'this' │ │ │ │
│ │ Object │ │ │ │ Environment │ │
│ └────────────────────┘ └───────────────────┘ └──────────────────┘ │
│ │
│ ┌───────────────────────────────────────────────────────────────────────┐ │
│ │ Set up Memory Space for Variables and Functions │ │
│ │ │ │
│ │ "Hoisting" │ │
│ └───────────────────────────────────────────────────────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────────────────────────────┘
caution

盡量在執行函數或使用變數之前先宣告他們,不要過度依賴於 Hoisting 的現象。因為你不知道你宣告的變數有沒有可能會變成 undefined。

🦀 Code Execution

JavaScript 在執行程式碼的時候就比較好理解了,不會有什麼 Hoisting 啦之類的奇怪的事情發生,就是我們寫好的程式碼會被 JavaScript Engine 在它該在的環境當中被一行一行的執行。但要特別注意的是,JavaScript 是單執行緒的語言喔。

┌────────────────────────────────────────────────────────────────────────────────────┐
│ │
│ Execution Context is Created (Execution Phase) │
│ │
│ ┌────────────────────┐ ┌───────────────────┐ ┌──────────────────┐ │
│ │ Global │ │ │ │ Outer │ │
│ │ │ │ 'this' │ │ │ │
│ │ Object │ │ │ │ Environment │ │
│ └────────────────────┘ └───────────────────┘ └──────────────────┘ │
│ │
│ ┌───────────────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ Runs Your Code │ │
│ │ │ │
│ └───────────────────────────────────────────────────────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────────────────────────────┘

🐳 Function Invocation and the Execution Stack(Call Stack)

nvocation: running a function
In JavaScript, we can use parenthesis() to invocate function.

當使用 JavaScript 呼叫函式的時候,底層做了什麼樣的事情?換句話說,函式被我們呼叫以後,JavaScript 是怎麼執行這些函式的?我們可以試著用以下的程式碼來舉例:

function b() {

}

function a() {
b();
}

a();

當我們開始執行以上的程式碼的時候,首先會先在 Execution Stack 裡面建立一個 Global Execution Context,接著當程式碼一行一行跑下來跑到 a() 然後執行 a 這個函式的時候,JavaScript 會為這個函數創建它的 Execution Context,並將它放到 Execution Stack(執行堆疊)當中,疊在 Global Execution Context 上面。

然後因為 a() 函式被執行了,連帶 a() 當中的 b() 也被執行,所以 JavaScript 也為 b() 函式創建了一個 Execution Context,而 b() 的 Execution Context 會疊在 a() 上面。

在 Execution Stack 當中函式的執行順序是由上往下執行的,也就是說,以此範例為例,會先執行 b()、在執行 a(),當 b() 執行完之後,b()就會離開執行堆疊(英文稱作 pop off),以此類推。

                   .
.
│ . │
│ . │
│ . │
│ . │
│ │
│ ┌─────────────────────────────────┐ │ ────► Execution Stack
│ │ b() │ │
│ │ Execution Context │ │
│ │ (create and execute) │ │
│ └─────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────┐ │
│ │ a() │ │
│ │ Execution Context │ │
│ │ (create and execute) │ │
│ └─────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────┐ │
│ │ Global Execution Context │ │
│ │ (created and code is executed) │ │
│ └─────────────────────────────────┘ │
│ │
└─────────────────────────────────────┘

🐳 Functions, Context, and Variables Environments

Variable Environment: where the variables live and how they realte to each other in memory

在每個 Execution Context 被創建之後,同時該 Execution Context 也會有一個自己的 Variable Environment。我們可以透過以下的程式碼為例,來說明 Variable Environment 在 JavaScript 中是如何被建立的。

function b() {
var myVar;
}

function a() {
var myVar = 2;
b();
}

var myVar = 1;
a();

當上述程式碼被執行之後,myVar 會是什麼值?程式碼執行後,JavaScript Engine 會分別在 Global、a()、b() 各自的 Execution Context 中各建立一個 Variable Environment,所以 myVar 在不同的 Execution Context 當中就會有不同的值,需要先觀察目前程式碼執行到哪邊,再去判斷 myVar 目前的值。如下圖:

│                                                        │
│ │
│ │
│ │
│ ┌───────────────────────────────────────────────┐ │ ───────► Execution Stack
│ │ b() │ │
│ │ │ │
│ │ Execution Context ┌─────────┐ │ │
│ │ │ myVar │ │ │
│ │ (create and execute) │undefined├─┼────┼──────┐
│ └───────────────────────────────────┴─────────┴─┘ │ │
│ │ │
│ ┌───────────────────────────────────────────────┐ │ │
│ │ a() │ │ │
│ │ │ │ │
│ │ Execution Context ┌───────┐ │ │ │
│ │ │ myVar │ │ │ │
│ │ (create and execute) │ 2 ├─┼────┼──────┼─────► Variable Environment
│ └─────────────────────────────────────┴───────┴─┘ │ │
│ │ │
│ ┌───────────────────────────────────────────────┐ │ │
│ │ │ │ │
│ │ Global Execution Context │ │ │
│ │ ┌───────┐ │ │ │
│ │ (created and code is executed) │ myVar │ │ │ │
│ │ │ 1 ├─┼────┼──────┘
│ └─────────────────────────────────────┴───────┴─┘ │
│ │
└────────────────────────────────────────────────────────┘

🐳 The Scope Chain

還記得我們在前面提到,程式碼執行之後,會為每個執行的函數建立自己的 Execution Context、自己的 Variable Environment。現在我們要談到,當程式碼執行後除了會建立上述提到的部分,還會建立一個 Outer Environment,意思就是指會建立一個對外的 Scope 參照。

總結來說,當一個 Execution Context 被建立的時候,裡面會有以下幾種東西:

  • Global Object
  • this
  • Hoisting
  • Outer Environment
  • Variable Environment

所以,建立一個對外的 Scope 參照是什麼意思?

如果用文字敘述來說明的話,指的是 JavaScript Engine 會去檢查該程式碼(比如說某個 function)的 Lexical Environment,也就是去檢查某個 funciton 的所在位置,再將該 function 所在位置的 variable environment 當作參照。

比如某個 function 是在全域環境中宣告的,那麼當 JavaScript Engine 在執行該 function 的時候,除了會建立 function 自己的 variable environment 之外,也會去參照這個 function 所在位置的 variable environment,也就是全域環境的 variable environment。

而上述提到的這種行為,便會導致一個稱為「Scope Chain」的現象發生。我們現在可以來看看以下幾個不同的程式碼,來更加了解 Scope Chain。


首先來觀察狀況一,b() 裡面的 console.log(myVar) 會印出什麼?

// 狀況一
function b() {
console.log(myVar);
}

function a() {
var myVar = 2;
b();
}

var myVar = 1;
a();

因為 b() 裡面並沒有宣告 myVar 這個變數,所以 JavaScript Engine 會藉由 Lexical Context 去檢查 function b 在哪個環境被宣告的,檢查之後發現是在全域,於是 JavaScript Engine 又在全域環境中檢查是不是有 myVar 這個變數,然後發現有,於是便印出 1


接下來來看看狀況二,在狀況二的程式碼中,b() 裡面的 console.log(myVar) 會印出什麼?

// 狀況二
function a() {
function b() {
console.log(myVar);
}

var myVar = 2;
b();
}

var myVar = 1;
a();

因為 b() 裡面並沒有宣告 myVar 這個變數,所以 JavaScript Engine 會藉由 Lexical Context 去檢查 function b 在哪個環境被宣告的,檢查之後發現是在 a function 裡面宣告的,於是 JavaScript Engine 又在 a function 的執行環境中檢查是不是有 myVar 這個變數,然後發現有,於是便印出


接下來來看看狀況三,在狀況三的程式碼中,b() 裡面的 console.log(myVar) 會印出什麼?

// 狀況三
function a() {
function b() {
console.log(myVar);
}
b();
}

var myVar = 1;
a();

因為 b() 裡面並沒有宣告 myVar 這個變數,所以 JavaScript Engine 會藉由 Lexical Context 去檢查 function b 在哪個環境被宣告的,檢查之後發現是在 a function 裡面宣告的,於是 JavaScript Engine 又在 a function 的執行環境中檢查是不是有 myVar 這個變數,然後發現沒有,於是又再繼續檢查 a funciton 是在哪個環境被宣告的,檢查之後發現是在全域環境,於是又再繼續檢查全域環境有沒有變數 myVar,然後終於發現有,於是便印出 1


從以上三個狀況中,可以看到以下幾個步驟:

  1. 某個函式被呼叫並執行
  2. JavaScript Engine 檢查該函式的 Lexical Context,確定它的 Outer Environment(也就是函式被宣告的環境)。
  3. 如果某個函式呼叫了一個自己的 Variable Environment 沒有的變數,JavaScript Engine 就會開始往 Outer Environment 的 Variable Environment 檢查有沒有那個變數。
  4. 一直重複步驟 3,直到找到那個變數,或是找到最後發現沒有那個變數

這種不斷地往 Outer Environment 尋找 Variable 的現象就稱為「Scope Chain」。

🐳 Scope, ES6, and let

Scope: where a variable is available in your code.

在 ES6 以前,若想要宣告一個變數,只有 var 可以用,但在 ES6 公布之後,目前有 varconstlet 可以用來宣告變數。

這三者之間也有些許不同。用 letconst 宣告變數後,那個變數所在的 Scope 是一個 block Scope(例如用{}圍起來就是一個 block),而用 var 則會將變數宣告在 Function Scope 當中。

varconstlet 都會有 Hoisting 的現象,只是使用 var 時,會給予變數一個 undefined 的初始值,但如果是 constlet 的話,則是會讓變數存在暫時死區無法使用,然後報錯。

varconstlet
作用域函式作用域區塊作用域區塊作用域
Hoistingundefined進入暫時死區,會報錯進入暫時死區,會報錯

🐳 What about Asynchronous Callbacks?

在前面的影片有提到 JavaScript 是一個單執行緒、同步的語言(一次只做一件事情),但是在瀏覽器當中卻可以做到非同步(一次做很多件事情),這到底是如何辦到的?是因為有瀏覽器這個執行的環境,它可以先做一些非同步的處理,然後再將處理好的函數一一丟到 JavaScript Engine 當中去執行。

瀏覽器處理非同步的過程有個專有名詞稱為 Event Loop,也許之後可以再寫一篇筆記來記錄瀏覽器當中的 Event Loop 是如何運作的。

- + \ No newline at end of file diff --git "a/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/objects-and-functions-part-1.html" "b/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/objects-and-functions-part-1.html" index fc6718b..09329c7 100644 --- "a/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/objects-and-functions-part-1.html" +++ "b/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/objects-and-functions-part-1.html" @@ -10,7 +10,7 @@ - + @@ -21,7 +21,7 @@ Immutable means it can't be changed.

🦀 Arguments

The parameters you pass to a function.
Jacascript gives you a keyword of the same name which contains them all.

🐳 Objects and Dot

在前面的影片當中有提到 object 是一對 key、value 的集合,那麼在記憶體當中,object 是如何儲存的呢?

一個 object 裡面的所有 property 會被存在各個記憶體位址,然後 object 所在的記憶體位址則會記得指向其他 property 被保存的記憶體位址。如下圖所示:

🐳 Funtcions are Objects

在 JavaScript 當中 function 就是 object 的一種,所以 function 擁有所有 object 的特性,但同時 function 也有一些自己的特點,例如: function 可以是匿名的,而且 function 有一段自己的 code(可以理解為 function 的其中一個 property 是 code),並且可以透過呼叫 () 來執行。如下圖所示:

所以其實這樣寫也是行得通的,因為 function 就是 object:

function greet() {
console.log("Hello!");
}

greet.lang = "english";

console.log(greet.lang);

🐳 Function Statements and Function Expressions

在 JavaScript 當中有兩種方式可以用來宣告 function,分別是:敘述式(function statement)和表達式(function expression)。

🦀 Function Statement 敘述式

敘述式的寫法如下:

function greeting() {
console.log('hi');
}

🦀 Function Expression 表達式

表達式的寫法如下:

const greeting = function() {
console.log('hi');
};

或是用箭頭函式:

const greeting = () => {
console.log('hi');
};

🦀 兩者之間的差別

來看看這兩段程式碼就可以很清楚的知道敘述式和表達式的差別:

greet();

function greet() {
console.log("hi!");
}
greet();

const greet = function() {
console.log("hi!");
};

把這兩段程式碼丟去執行的話,可以看到第一個部分的程式碼能夠成功執行並印出 "hi",因為在使用敘述式時,function 會被 hoisting,所以可以將執行的語法寫在宣告 function 之前。

但是在執行第二部分的程式碼時卻會出錯,因為雖然第二段的程式碼也會進行 hoisting,但被 hoisting 的只有變數本身而已,賦值這個動作並不會被 hoisting,所以在宣吿 greet 之前就呼叫執行它的話, greet 會進入暫時死區並且報錯(因為在這邊使用 const 的關係)。

從這個例子可以知道,敘述式和表達式的最大差別就是在 hoisting 的時候結果會不太一樣,而為了避免可能會產生報錯,盡量都在執行 function 之前先宣吿 function 才是比較好的選擇。

🐳 By Value and By Reference

🦀 By Value

目前有下列的程式碼:

const a = 1; // primitive value
b = a;

如果 a 這個變數的值是一個 primitive type(例如數字、字串、布林值等等)的話,當我們將 a 賦值給 b 的時候,其實是會將 a 的值複製出一個新的,然後將它儲存在另外一個新的記憶體區塊,再把新的記憶體區塊 reference 到 b,如下圖所示:

🦀 By Reference

接下來以下面的程式碼範例為例,來舉例什麼是 by reference

const a = { firstName: 'John', LastName: 'Walker' };
const b = a;

b.firstName = 'Ben';
console.log(b.firstName);
console.log(a.firstName); // a.firstName 會印出什麼?

從上述程式碼中可以知道,我們將 a 這個變數指向一個 object,然後再將 b 指向 a,最後去修改 b 這個 object 裡面的 property,但結果卻發現 a 裡面的 property 也被我們修改到了,也就是說我們不管是修改 b 或是修改 a 都會修改到同一個 object。

為什麼會發生上述這件事呢?是因為當資料型態是 reference type (object, array...) 的時候,JavaScript 是透過 by reference 去傳遞參數的,也就是如下圖所示:

其實 a 和 b 這兩個變數都指向同一個記憶體區塊(也就是 object 的所在位置),所以不管是透過 a 或 b 來修改 object,都是修改到同樣的東西。

小小結論

知道 by valueby reference 的差別,有助於程式開發和除錯。在這邊會討論到 by valueby reference 的差別主要是因為,當我們在進行程式開發或是除錯的時候,會需要處理非常多各式各樣的資料型態。當如果不小心改動的原本的資料時,可能會導致某些 function 出錯,此時知道 by valueby referenct 的差異可以更好的去避免改動到原始資料,降低產生 bug 的機率!

🐳 Objects, Funcitons, and this

前面的幾部影片有提到 function 在執行的時候,會有一個 funciton 自己的 execute content 和 variable environment,並透過 scope chain 去拿到 outer environment 的變數,除此之外還會有一個東西——叫做 this,接下來這個部分會特別針對 this 來做說明。

首先,先來看看幾個簡單的例子:

console.log(this);
function a() {
console.log(this);
}

a();
const b = funciton() {
console.log(this);
}

b();

如果我們將上述三個程式碼放到瀏覽器當中去執行的話,可以知道這三個印出來的東西都是 window,也就是說,按照上面的方式(寫在 function 當中然後直接執行,或是直接執行)去呼叫 this,它所指向的東西都是 window 這個 global object。

接下來我們試試用在 object 裡面建立 method 的方式來呼叫 this

const c = {
name: 'The c object',
log: function() {
console.log(this);
},
};

c.log();

當我們將上述的程式碼丟到瀏覽器的環境中執行時, this 會印出 c 這個 object,也就是說透過一個 object 來呼叫其中的 method 的話,此時的 this 會指向該 object。接下來我們繼續看看下一個範例:

const c = {
name: 'The c object',
log: function() {
console.log(this);

const setName = function(newName) {
this.name = newName;
}

setName('Update c object!');
console.log(this);
},
};

c.log();

按照上上一個程式碼範例的認知,如果在一個 object method 裡面呼叫 this,那麼 this 就會指向該 object,但當我們執行 c.log() 之後,裡面的 setName function 似乎並沒有成功地幫我們將 c.name 修改成新的名字。反而在 window 這個 global object 下面,找到了 window.name === 'Update c object'。也就是說 setName function 裡面的 this 是指向 window,並不是指向 object c。

為了要讓 this 能夠一直指向 object c,我們可以把程式碼修改成下面這樣:

const c = {
name: 'The c object',
log: function() {
const self = this; // 多加這一行,然後所有的 this 都改用 self
console.log(self);

const setName = function(newName) {
self.name = newName;
}

setName('Update c object!');
console.log(self);
},
};

c.log();

只要將 this 賦值給一個變數後,然後在其他所有有用到 this 的地方都改用該變數, 這樣寫在 c.log() 裡面的任何 function 都能夠透過 scope chain 去找到該變數指向的 this 了(也就是 object c)。

小小結論

如果在 function 裡面呼叫 this,然後在 global 當中執行,通常 this 會指向 window,如果是呼叫放在 object 當中的 function 的話,呼叫的 this 則會指向該 object,但如果是在 object 的 function 中還有另一個內部的 function,這個內部的 function 呼叫的 this 會指向 window,為了避免這樣的 bug,可以先在 object function 裡面的最上方將 this 賦值給某個變數(通常會寫成 const self = this)。

🐳 'arguments' and Spread

🦀 arguments

在開始說明什麼是 arguments 之前,我們先來看一個普通的 function:

function greet(firstName, lastName, language) {
console.log(firstName);
console.log(lastName);
console.log(language);
console.log('----------');
}

greet();
greet('John');
greet('John', 'Doe');
greet('John', 'Doe', 'en');

在上述的 function 當中,雖然 greet() 這個 function 需要傳三個變數進去,但如果少傳了任何一個,Javascript 並不會報錯,而是會將沒有傳入任何值的變數預設成 undefined。而這樣的特性也就表示,可以很簡單的對一個變數設置一個預設值,比如,如果沒有傳 language 這個變數進去的話,先將其預設值設成 'en',可以這樣寫:

function greet(firstName, lastName, language = 'en') {
console.log(firstName);
console.log(lastName);
console.log(language);
console.log('----------');
}

或是比較舊的寫法:

function greet(firstName, lastName, language) {
language = language || 'en';

console.log(firstName);
console.log(lastName);
console.log(language);
console.log('----------');
}

在一個 function 當中,除了傳進去的變數之外,Javascript 也提供了一個稱作 arguments 的變數來接收傳進來的所有變數。此時我們可以來把上述的 function 改造一下,將 arguments 加進去,然後看看會發生什麼事情:

function greet(firstName, lastName, language) {
console.log(firstName);
console.log(lastName);
console.log(language);
console.log(arguments); // 將 Javascript 內建的 arguments 加入
console.log('----------');
}

greet();
greet('John');
greet('John', 'Doe');
greet('John', 'Doe', 'en');

可以看到執行四遍的 greet() 分別印出了以下四個不同的 arguments

[]
['John']
['John', 'Doe']
['John', 'Doe', 'en']

從印出的結果當中可以知道 arguments 是一個可以收集所有傳進 function 的變數的類 array,為什麼會說它是類 array 是因為它長得很像 array,可以做到一些跟 array 很像的事情,但 array 的某些特性它沒有。

這時候我們就可以用 arguments 來做一些事情,比如可以檢查有沒有變數傳進來,如果沒有就報錯:

function greet(firstName, lastName, language) {
if (arguments.length === 0) {
console.log('Missing parameters');
return;
}
console.log(firstName);
console.log(lastName);
console.log(language);
console.log(arguments); // 將 Javascript 內建的 arguments 加入
console.log('----------');
}

🦀 spread

spread 簡單來說就是很常看到的 ...。而這個 ... 實際上有什麼用途呢?目前我所知道的用法主要有三個:

  1. 如果傳入某個 function 的變數可能是OO個和OO個以上,這個「以上」的部分可以用 ... 包起來。
  2. 可以用來解構 array。
  3. 可以用來解構 object。

廢話不多說,直接用實際的例子來看看:

function greet(firstName, lastName, language, ...others) {
console.log(firstName);
console.log(lastName);
console.log(language);
console.log(others);
}

greet('John', 'Doe', 'en', 1, 2, 3, 4);

在上述的例子,可以看到 others 這個變數印出了 [1, 2, 3, 4],這也就是說它將 firstName, lastName, language 之外的值都包在 others 這個 array 裡面,這也就是表示這個 function 可以傳入三個或三個以上的值。

接著來看看解構的例子:

const arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const arr2 = [...arr1];

在上述程式碼中,可以透過 ... 拿到 arr1 裡面的每個元素,然後再把它放到 arr2 來達到淺拷貝。用在 object 當中也是同樣的道理。如此一來便可以輕鬆達到淺拷貝。

- + \ No newline at end of file diff --git "a/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/objects-and-functions-part-2.html" "b/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/objects-and-functions-part-2.html" index 811aeb1..181b7a5 100644 --- "a/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/objects-and-functions-part-2.html" +++ "b/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/objects-and-functions-part-2.html" @@ -10,13 +10,13 @@ - +

Objects and Functions - Part 2

🐳 Concept Asides 名詞解釋

🦀 Function Overloading

在某些程式語言中,多個 function 可以有相同的命名,但是在 Javascript 當中,由於 function 也是 object,所以一個變數名稱只能對應到一個 function,也就是說 function 的命名不可以重複。

🦀 Syntax Parsers

- + \ No newline at end of file diff --git "a/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/types-and-operators.html" "b/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/types-and-operators.html" index 4b7e6b4..02adf10 100644 --- "a/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/types-and-operators.html" +++ "b/docs/notes/\345\205\213\346\234\215JS\347\232\204\345\245\207\346\200\252\351\203\250\345\210\206/types-and-operators.html" @@ -10,7 +10,7 @@ - + @@ -20,7 +20,7 @@ Generally, operators take two parameters and return one result.

當打出以下的程式碼時,我們會很直覺地認為會印出 7,但那是從人類的角度出發去做加減法,至於在 JavaScript Engine 當中是如何執行這段程式碼的?

var a = 3 + 4;
console.log(a);

其實對 JavaScript Engine 來說,他在背後做的事情比較像是這樣:

function +(a, b) {
return // add the two variable
}

// 三種不同的運算子表示方式 //
+3 4 // prefix notation
3 + 4 // infix notation
3 4+ // postfix notation

+ 其實是一個 JavaScript 裡面本來就有的 function,所以當我們寫了 + 時,就是呼叫這個 function ,然後將兩個變數傳進去做加法,然後回傳出一個新的值。只是這個 function 是寫在兩個變數中間,也就是 3 + 4,這樣將運算子寫在中間的表示方式稱為 infix notation。

總之,在 JavaScript 中,運算子其實是一種 function,傳入兩個值,然後會回傳一個值。

🦀 Coercion 強制轉型

Converting a value from one type to another.
This happens quite often in JavaScript because it's dynamically typed.

因為 JavaScript 是動態型別的語言,所以在程式執行的時候,它時不時會將寫好的變數或是值自動轉換型別,來看看以下簡易的範例:

const a = 1 + 2;
const b = 'Hello ' + 'World';

console.log(a);
console.log(b);

在上述例子當中, a 和 b 都是同型別相加,所以我們可以知道 a 會印出 3,b 會印出 Hello World。但如果是不同型別之間的相加呢?比如以下的範例:

const c = 1 + '2';
console.log(c);

在這個範例中,和其他程式語言不同,JavaScript 不會因為這兩個值的型別不同而報錯,反而會嘗試將這兩個值轉成相同的型別,所以此時數字 1 會被轉型成字串 1,然後再與字串 2 相加,最後會印出字串 12。這個現象就是 Coercison。理解在 JavaScript 中有這個現象後,更容易在撰寫程式的時候避免許多因為轉型造成的錯誤。

info

目前學到的轉型規則:當有兩個東西「相加」的時候,如果其中一個東西是字串,JavaScript 會嘗試將另一個東西也轉成字串。

🐳 Operator Precedence and Associativity

首先要來定義什麼是 Operator Precedence 和 Associativity:

Operator Precedence: which operator get called first.
Functions are called in order of precedence. (Higher precedence wins.)

Associativity: what order operator functions get called in: left-to-right or right-to-left, when functions have the same precedence.

簡單來說,當有多個運算子出現在一個運算式當中的時候,需要透過 Precedence 來決定要先執行哪個運算,如果每個運算子的優先順序都相同的話,再透過 Associativity 去決定是要從左到右或是從右到左執行優先級相同的運算子。

先來看看一個只需要用到 Precedence 的簡單範例:

var a = 3 + 4 * 5;
console.log(a);

在上述的程式碼當中,因為 * 的優先級比 + 高,所以 JavaScript Engine 會先做 * 再做 +

// 先做 *
var a = 3 + 20;

// 再做 +
var a = 23;

// 最後印出
23

JavaScript Engine 就是如上在執行運算子的運算,先將兩個值丟進一個運算的 function,然後回傳出一個新的值,再繼續做下一個運算子的運算,但也是因為這樣的運作方式,還有 JavaScript 本身是動態型別語言的關係,會導致一些奇怪的現象。

但在觀察這些奇怪的現象之前,先繼續來看看 Operator Precedence 和 Associativity 合在一起的例子。

let a = 2;
let b = 3;
let c = 4;

a = b = c;

console.log(a);
console.log(b);
console.log(c);

在上述的例子當中,可以看到 a = b = c 這一行的運算子優先級是相同的(因為都是 =,每個 = 的優先級相同),接下來要看的就是 = 的 Associativity,到 MDN 文件查之後,知道 = 的 Associativity 是從右到左,所以 a = b = c 會從右到左執行,先執行 b = c 再執行 a = b,也就是說會先將 c 賦值給 b,再將 b 賦值給 c,所以最後 a、b、c 都會印出 4。

從以上兩個例子中,可以很清楚的知道 Operator Precedence 和 Associativity 的作用。

🐳 Comparison Operators

在這個小節當中,講師提到當所有以上概念(Coercion、Operator Precedence and Associativity)合在一起的時候,JavaScript 會出現一些讓人困惑的現象。

第一個讓人困惑的地方是,JavaScript 在計算多個運算子的時候,運算的方式其實與人腦的運算方式並不同,所以會出現一些我們預期之外的狀況。

首先先觀察一個符合人們直覺的範例:

console.log(1 < 2 < 3);

上述的程式碼會印出 true,而這個也符合人們對數學運算的理解,1 的確是小於2,2 也的確是小於 3。但如果是以下的程式碼呢?

console.log(3 < 2 < 1);

JavaScript 還是會印出 true,這時候就要來理解,當看到 3 < 2 < 1 的時候,JavaScript Engine 是以下面的步驟在運作的:

  1. 根據 Operator Associativity 先執行 3 < 2,得到 false
  2. 進行 false < 1 的運算
  3. 嘗試把 false 轉型成 number,所以 false < 1 變成 0 < 1
  4. 進行 0 < 1 的運算
  5. 得到 true,然後印出來

從以上步驟可以知道,JavaScript Engine 在進行各種運算子運算的時候,與我們平常在算數學時使用的計算方式不同。


第二個讓人困惑的地方是有關 undefined、false、null 這三個型別如果被轉型成數字的話,我們會預期都是 0。但實際上並不是,undefined 會被轉型成 NaN,false、null 才會被轉型成數字 0。

Number(undefined); // NaN
Number(false); // 0
Number(null); // 0

第三個讓人困惑的地方是,如果使用運算子,特別是 == 的時候(因為使用兩個等於會先轉型才比較),又會發生讓人困惑的狀況,比如以下幾個例子:

false == 0; // true

null == 0; // false
null < 1; // true

"" == 0; // true
"" == false; // true

由於使用 == 會導致互相比較的值先轉型才進行比較,但我們很多時候並沒有辦法準確預測 JavaScript Engine 會將值轉型成什麼型別,可能會造成小錯誤。

在 JavaScript 當中,還有另外一個運算子 === 也可以用來比較兩個值是否相等。使用 === 時並不會使想要比較的值被轉型,會先比較型別是否相同然後才比較兩者的值,如果型別不同便會直接回傳 false,所以可以盡量使用 === 會比較好。

🐳 什麼時候用到了 Coercion?

其實平常在寫 code 的時候,我們也默默用到了很多轉型的概念,比如說以下的 react 的使用情境就是利用當 state 是空字串時會轉型成 false,非空字串會轉型成 true ,來判斷要顯示什麼樣的畫面。

funciton Component() {
const [state, setState] = useState('');

useEffect(() => {
setState('Hello World')
}, [])

return(
// 這邊的 state ? 就用到了轉型 //
{state ? <div>{state}</div> : <div>There is no state</div>}
)
}

🐳 參考資源

- + \ No newline at end of file diff --git "a/docs/notes/\346\234\252\345\210\206\351\241\236/writing-a-good-pull-request.html" "b/docs/notes/\346\234\252\345\210\206\351\241\236/writing-a-good-pull-request.html" index d8e81e9..da80bd1 100644 --- "a/docs/notes/\346\234\252\345\210\206\351\241\236/writing-a-good-pull-request.html" +++ "b/docs/notes/\346\234\252\345\210\206\351\241\236/writing-a-good-pull-request.html" @@ -10,13 +10,13 @@ - +

Writing a Good Pull Request

🐳 前情提要

會想要寫一篇「如何寫好的 pull request」相關的文章,是因為在實作一個大功能的重構時,發了一個龐大的 pull request,把要重構的項目一次修改掉。但這個 pull request 是一個不太好的 pull request:

  1. 一次 pull request 修改改太多(高達兩千行),reviewer 會看了很痛苦。
  2. 馬上把新的程式碼改掉,舊的程式碼也刪掉之後,沒有辦法確保原本的功能也能照之前的一樣正常運作,因為目前該功能缺少測試。

所以希望透過搜尋相關的資料,讓自己的 pull request 可以寫得好一點。讓 reviewer 可以輕鬆寫意的看懂,功能可以順利上線。

🐳 好的 pull request 有哪些特質

一個好的 pull request 通常具有以下的特質:

「一,可以得到清楚的回饋或修改建議」

如果一個 pull request 得到清楚明瞭的回饋或是修改建議,不代表這個 pull request 是不好的,而是表示它讓 reviewer 好閱讀,進而提出具體和清楚的修改建議,

「二,可以很快速地被 review」

如果一個 pull request 可以很快速地被 review,那就表示 reviewer 會更願意 review 該 pull request,因為比較不會打斷 reviewr 本來的工作安排。

「三,reviewer 不會問太多關於這個 pull request 的問題」

如果你的 pull request 發出去後,reviewer 對這個 pull request 問了很多 How 和 Why 的問題,那可能表示這不是一個好的 pull request,因為 reviewer 可能看不太懂為什麼要發 pull request,或是該 pull request 究竟如何解決了問題。一個好的 pull request 應該要能夠很好地對上述兩個疑問解惑。

🐳 如何寫出好的 pull request

下面來一一列出如何寫出好的 pull request的具體方法。

🦀 遵守團隊訂定的 coding style 規範

這是一定要的,每次發出 pull request 之前,可以先自己檢查寫的 code 有沒有符合團隊的 coding 規範。

🦀 Make Pull Request Small

一個 pull request 裡面修改的 code 不要太多(個人認為最少最少要控制在 800 行內)。

因為:

  1. reviewer 可以更完整地 review pull request
  2. reviewer 可以更快地 review pull request
  3. 比較容易 merge 進 master
  4. 被退件的時候,不會做太多白工

具體做法:

  1. 一個 pull request 解決一個問題,將 code 的修改範圍對焦在一個 issue,不要一個 pull request 裡面試圖解決多個 issue。如果一個 issue 要改的 code 還是太多,那表示這個 issue 的 scope 太大了,應該要把 issue 拆得更小。
  2. 把 refactor 拆成一步一步不同的 pull request,不要一次改一堆。
  3. 善用 git add --patchgit rebase --interactive
  4. 如果是在一個要長期進行的 feature branch 的話,可以將該 branch 設為你的 pull request target branch 而不是 master branch。

🦀 Use Commits

commit 寫個好的話,reviewer 也可以更容易看懂該次 commit 做了哪些 code 的修改。可以在 google 搜尋「commit convention」來了解如何好的運用 commit。

🦀 Test

  1. 手動測試:在發出 pull request 之前,先自己手動測試修改的地方有沒有問題,例如新功能有沒有問題、用 edge case 來測試自己修改的地方有沒有問題。
  2. 自動化測試:如果是新功能的 pull request,且在時程上有時間的話,可以增加自動化測試,確保自己寫出來的 code 是安全的,有了自動化測試,對於未來的重構也會很有幫助。
  3. 視情況在 pull request 的 description 說明測試結果,或是有什麼 edge case 需要 reviewer 注意等等。

🦀 Make a Clear Description

在 pull request 的 description 中,盡量對以下幾點做清楚的描述,讓 reviewer 更清楚地了解你寫的 pull request 在做什麼:

  1. 描述這個 pull request 解決了什麼問題,同時附上 issue 的連結
  2. 如果有決定採取什麼 design pattern 或是一些迫不得已的 walkaround 的話,也可以在 decription 說明
  3. 測試相關的說明,可以參考上述 Test 提到的第三點。

🦀 Add possible risks and highlight risky code

如果在發 pull request 之後,有一些不太確定的地方,比如說不確定某段修改的 code 改得好不好,會不會有什麼問題(例如:效能、資安、edge case 等問題)。可以在 pull request 發出之後,特別在該段 code 留個言,請 reviewer 特別注意或是協助你改善 code。

🦀 Rebase Onto Fresh Master Before Creating a PR

在正式 merge 之前,可以先將自己開發的分支 rebase 到 target branch,確保自己的分支一直有在跟 target branch 做同步和更新,這樣可以減少 merge 的衝突,如果 target branch 有什麼新的功能或是 function 也可以在自己的分支使用。

🦀 不要修改已經 review 過的 commit

如果某些 commits 已經被 review 過的話,就不要再去動它了,不要去修改 commit message 或是 squash 等等。如果有收到 review 需要修改的話,請直接寫一個新的 commit。

因為如果把舊的改掉的話,reviewer 可能會不知道他已經 review 過舊的部分,又再多看一次,降低了雙方的效率。

🦀 快速地回覆 review

reviewer 看完你的 pull request 之後,可以快速地針對 reviewer 的回饋進行修改,一來自己寫 code 的邏輯和想法都還記得,二來 reviewer 也還對 review 的記憶比較深刻。不要過了太久才進行修改,不然雙方都很容易忘記。

🦀 發 pull request 前先跟同事溝通

在開始實作之前,可以先將同事討論如何實作,用什麼樣的方法,如何拆分 pull request 等等,也許你的同事可以給你更多不一樣的實作想法。事先討論也可以避免下面的情況:也許你想實作的東西不一定需要修改,可以先和同事確認,避免改了之後,其實不需要改的做白工狀況發生。

tip

可以參考 google 的 Google Engineering Practices Documentation,看看 google 是如何訂定 pull request author 和 pull request reviewer guide。

🐳 Resource

- + \ No newline at end of file diff --git a/index.html b/index.html index 82a8538..15368ab 100644 --- a/index.html +++ b/index.html @@ -10,13 +10,13 @@ - +
- + \ No newline at end of file