mirror of
https://github.com/mfocko/blog.git
synced 2024-11-25 06:11:55 +01:00
1 line
27 KiB
JavaScript
1 line
27 KiB
JavaScript
|
"use strict";(self.webpackChunkfi=self.webpackChunkfi||[]).push([[3707],{69383:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>r,contentTitle:()=>l,default:()=>d,frontMatter:()=>i,metadata:()=>c,toc:()=>m});var a=n(85893),t=n(11151);const i={id:"extend",title:"Time complexity of \u2039extend\u203a",description:"How to make inefficient algorithm unknowingly.\n",tags:["c","python","dynamic array","time complexity","recursion"],last_update:{date:new Date("2021-03-31T00:00:00.000Z")}},l=void 0,c={id:"time-complexity/extend",title:"Time complexity of \u2039extend\u203a",description:"How to make inefficient algorithm unknowingly.\n",source:"@site/algorithms/03-time-complexity/2021-03-31-extend.md",sourceDirName:"03-time-complexity",slug:"/time-complexity/extend",permalink:"/algorithms/time-complexity/extend",draft:!1,unlisted:!1,editUrl:"https://github.com/mfocko/blog/tree/main/algorithms/03-time-complexity/2021-03-31-extend.md",tags:[{label:"c",permalink:"/algorithms/tags/c"},{label:"python",permalink:"/algorithms/tags/python"},{label:"dynamic array",permalink:"/algorithms/tags/dynamic-array"},{label:"time complexity",permalink:"/algorithms/tags/time-complexity"},{label:"recursion",permalink:"/algorithms/tags/recursion"}],version:"current",lastUpdatedAt:1617148800,formattedLastUpdatedAt:"Mar 31, 2021",frontMatter:{id:"extend",title:"Time complexity of \u2039extend\u203a",description:"How to make inefficient algorithm unknowingly.\n",tags:["c","python","dynamic array","time complexity","recursion"],last_update:{date:"2021-03-31T00:00:00.000Z"}},sidebar:"autogeneratedBar",previous:{title:"Asymptotic Notation and Time Complexity",permalink:"/algorithms/category/asymptotic-notation-and-time-complexity"},next:{title:"Recursion",permalink:"/algorithms/category/recursion"}},r={},m=[{value:"Introduction",id:"introduction",level:2},{value:"Technicalities",id:"technicalities",level:2},{value:"Example #1",id:"example-1",level:2},{value:"Example #2",id:"example-2",level:2},{value:"Implementation of <code>extend</code>",id:"implementation-of-extend",level:2}];function h(e){const s={a:"a",annotation:"annotation",code:"code",em:"em",h2:"h2",img:"img",li:"li",math:"math",mi:"mi",mn:"mn",mo:"mo",mrow:"mrow",mtext:"mtext",p:"p",pre:"pre",semantics:"semantics",span:"span",strong:"strong",ul:"ul",...(0,t.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.h2,{id:"introduction",children:"Introduction"}),"\n",(0,a.jsxs)(s.p,{children:["Each year there is a lot of confusion regarding time complexity of the ",(0,a.jsx)(s.code,{children:"extend"})," operation on the lists in Python. I will introduce two specific examples from previous year and also will try to explain it on one of the possible implementations of ",(0,a.jsx)(s.code,{children:"extend"})," operation."]}),"\n",(0,a.jsx)(s.h2,{id:"technicalities",children:"Technicalities"}),"\n",(0,a.jsxs)(s.p,{children:["At the beginning we should clear some of the \u201cmyths\u201d regarding extending of the lists. There is a common misunderstanding regarding differences between ",(0,a.jsx)(s.code,{children:"a += b"}),", ",(0,a.jsx)(s.code,{children:"a.extend(b)"})," and ",(0,a.jsx)(s.code,{children:"a + b"}),"."]}),"\n",(0,a.jsxs)(s.ul,{children:["\n",(0,a.jsxs)(s.li,{children:["\n",(0,a.jsxs)(s.p,{children:[(0,a.jsx)(s.code,{children:"a.extend(b)"})," - adds all elements from ",(0,a.jsx)(s.code,{children:"b"})," to ",(0,a.jsx)(s.code,{children:"a"}),"."]}),"\n",(0,a.jsxs)(s.p,{children:["Time complexity: ",(0,a.jsxs)(s.span,{className:"katex",children:[(0,a.jsx)(s.span,{className:"katex-mathml",children:(0,a.jsx)(s.math,{xmlns:"http://www.w3.org/1998/Math/MathML",children:(0,a.jsxs)(s.semantics,{children:[(0,a.jsxs)(s.mrow,{children:[(0,a.jsx)(s.mi,{mathvariant:"script",children:"O"}),(0,a.jsx)(s.mo,{stretchy:"false",children:"("}),(0,a.jsx)(s.mi,{children:"n"}),(0,a.jsx)(s.mo,{stretchy:"false",children:")"})]}),(0,a.jsx)(s.annotation,{encoding:"application/x-tex",children:"\\mathcal{O}(n)"})]})})}),(0,a.jsx)(s.span,{className:"katex-html","aria-hidden":"true",children:(0,a.jsxs)(s.span,{clas
|