blog/assets/js/087808f1.e9aaa303.js

1 line
18 KiB
JavaScript
Raw Permalink Normal View History

"use strict";(self.webpackChunkfi=self.webpackChunkfi||[]).push([[3731],{48157:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>h,contentTitle:()=>r,default:()=>d,frontMatter:()=>i,metadata:()=>o,toc:()=>l});var s=n(85893),a=n(11151);const i={id:"breaking",slug:"/hash-tables/breaking",title:"Breaking hash table",description:"How to get the linear time complexity in a hash table.\n",tags:["cpp","python","hash-tables"],last_update:{date:new Date("2023-11-28T00:00:00.000Z")}},r=void 0,o={id:"hash-tables/2023-11-28-breaking/breaking",title:"Breaking hash table",description:"How to get the linear time complexity in a hash table.\n",source:"@site/algorithms/12-hash-tables/2023-11-28-breaking/index.md",sourceDirName:"12-hash-tables/2023-11-28-breaking",slug:"/hash-tables/breaking",permalink:"/algorithms/hash-tables/breaking",draft:!1,unlisted:!1,editUrl:"https://github.com/mfocko/blog/tree/main/algorithms/12-hash-tables/2023-11-28-breaking/index.md",tags:[{label:"cpp",permalink:"/algorithms/tags/cpp"},{label:"python",permalink:"/algorithms/tags/python"},{label:"hash-tables",permalink:"/algorithms/tags/hash-tables"}],version:"current",lastUpdatedAt:1701129600,formattedLastUpdatedAt:"Nov 28, 2023",frontMatter:{id:"breaking",slug:"/hash-tables/breaking",title:"Breaking hash table",description:"How to get the linear time complexity in a hash table.\n",tags:["cpp","python","hash-tables"],last_update:{date:"2023-11-28T00:00:00.000Z"}},sidebar:"autogeneratedBar",previous:{title:"Hash Tables",permalink:"/algorithms/category/hash-tables"},next:{title:"Breaking Python",permalink:"/algorithms/hash-tables/breaking/python"}},h={},l=[{value:"Introduction",id:"introduction",level:2},{value:"Hash Table v. Trees",id:"hash-table-v-trees",level:2},{value:"Requirements",id:"requirements",level:3},{value:"Underlying data structure",id:"underlying-data-structure",level:3},{value:"Major Factors of Hash Tables",id:"major-factors-of-hash-tables",level:2},{value:"Hash functions",id:"hash-functions",level:3},{value:"Implementation details",id:"implementation-details",level:3}];function c(e){const t={a:"a",admonition:"admonition",annotation:"annotation",code:"code",em:"em",h2:"h2",h3:"h3",li:"li",math:"math",mi:"mi",mo:"mo",mrow:"mrow",ol:"ol",p:"p",pre:"pre",section:"section",semantics:"semantics",span:"span",strong:"strong",sup:"sup",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,a.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.p,{children:"We will try to break a hash table and discuss possible ways how to prevent such\nissues to occur."}),"\n",(0,s.jsx)(t.h2,{id:"introduction",children:"Introduction"}),"\n",(0,s.jsxs)(t.p,{children:["Hash tables are very commonly used to represent sets or dictionaries. Even when\nyou look up solution to some problem that requires set or dictionary, it is more\nthan likely that you'll find something that references usage of the hash table.\nYou might think it's the only possible option",(0,s.jsx)(t.sup,{children:(0,s.jsx)(t.a,{href:"#user-content-fn-1",id:"user-content-fnref-1","data-footnote-ref":!0,"aria-describedby":"footnote-label",children:"1"})}),", or it's the best one",(0,s.jsx)(t.sup,{children:(0,s.jsx)(t.a,{href:"#user-content-fn-2",id:"user-content-fnref-2","data-footnote-ref":!0,"aria-describedby":"footnote-label",children:"2"})}),"."]}),"\n",(0,s.jsxs)(t.p,{children:["One of the reasons to prefer hash tables over any other representation is the\nfact that they are ",(0,s.jsx)(t.strong,{children:"supposed"})," to be faster than the alternatives, but the\ntruth lies somewhere in between."]}),"\n",(0,s.jsxs)(t.p,{children:["One of the other possible implementations of the set is a balanced tree. Majorly\noccurring implementations rely on the ",(0,s.jsx)(t.em,{children:"red-black tree"}),", but you may see also\nothers like an ",(0,s.jsx)(t.em,{children:"AVL tree"}),(0,s.jsx)(t.sup,{children:(0,s.jsx)(t.a,{href:"#user-content-fn-3",id:"user-content-fnref-3","data-footnote-ref":!0,"aria-describedby":"footnote-label",children:"3"})})," or ",(0,s.jsx)(t.em,{children:"B