From 6f839da8a52c5b6ab9667a1b58dffbb1486dbf82 Mon Sep 17 00:00:00 2001 From: Xtrah Date: Mon, 23 Nov 2020 12:39:52 +0100 Subject: [PATCH] Fix Python imports and formatting --- .gitignore | 5 +++- Python/Datastrukturer/HashTable.py | 5 ++-- Python/Datastrukturer/Heap.py | 3 ++- .../__pycache__/HeapList.cpython-37.pyc | Bin 1594 -> 0 bytes .../__pycache__/LinkedList.cpython-37.pyc | Bin 3181 -> 0 bytes Python/Graphs/BFS.py | 2 +- .../Graphs/__pycache__/Vertex.cpython-37.pyc | Bin 853 -> 0 bytes ... ComparisonSortingComplexityLowerBound.md} | 22 ++++++++++-------- Python/Sortering/heapsort.py | 7 ------ 9 files changed, 21 insertions(+), 23 deletions(-) delete mode 100644 Python/Datastrukturer/__pycache__/HeapList.cpython-37.pyc delete mode 100644 Python/Datastrukturer/__pycache__/LinkedList.cpython-37.pyc delete mode 100644 Python/Graphs/__pycache__/Vertex.cpython-37.pyc rename Python/Sortering/{ComparisonSortingComplexityLowerBound => ComparisonSortingComplexityLowerBound.md} (64%) delete mode 100644 Python/Sortering/heapsort.py diff --git a/.gitignore b/.gitignore index 08fd2d7..dd420d8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,7 @@ *.code-workspace # Local History for Visual Studio Code -.history/ \ No newline at end of file +.history/ + +# Python cache +__pycache__ diff --git a/Python/Datastrukturer/HashTable.py b/Python/Datastrukturer/HashTable.py index f6ca933..585c6fd 100644 --- a/Python/Datastrukturer/HashTable.py +++ b/Python/Datastrukturer/HashTable.py @@ -1,4 +1,4 @@ -import Python.Datastrukturer.LinkedList as LL +import LinkedList as LL import random import math class HashTable: @@ -44,9 +44,8 @@ def __str__(self): - for i in range(3000): # reliability testing - ht = HashTable(); + ht = HashTable() for j in range(1000): a = LL.Node(random.randint(0,100)) ht.hash_insert(a) diff --git a/Python/Datastrukturer/Heap.py b/Python/Datastrukturer/Heap.py index c2bc6ca..9d3dc4e 100644 --- a/Python/Datastrukturer/Heap.py +++ b/Python/Datastrukturer/Heap.py @@ -1,4 +1,5 @@ -from Python.Datastrukturer.HeapList import HeapList as HL +from HeapList import HeapList as HL + import random def exchange(A, idx_A, idx_B): diff --git a/Python/Datastrukturer/__pycache__/HeapList.cpython-37.pyc b/Python/Datastrukturer/__pycache__/HeapList.cpython-37.pyc deleted file mode 100644 index 185a8b5b7d7a2f2ca680a3095bcd035e1b2fb262..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1594 zcma)6J#Q015Z%2y+ZQ`doDUSGK#J(xpePMd6d@821PNV}&{&pMC(ja`_#^C{BgJx; z@M9=w_z(PvYpJN|sCctypYMVr*yv_ zK!95^XgY}-8k6`RaXadcb<<6}NcTP%zG*nb7hy_JzYmTN+QC`yzJ0Q{ySLju>YY;< zvl^Oi+}Ec4DvZM@HlxdUWN@6}d3tq|_)2vL-B>9Pks=mCmgRUY^O@N@l5JS5Gw@u8 zSWLu)ypY57cPIXc~1iQ*es;f6Nf#?OvWbu2-RJ7tdxHgK%WbPA=DK zmMgUd&1HTy24P<-l~k4L4{6ln{jyS@Mqw|tm(AfGha0WZFQA7Lh5@7lG(YZP#&3asq zV%<53I~vWcM(ZS0Ta75Lo?Rq<5HwniI0y(T;)X)z@%Cm2yE+^_kQ~9oGR03*$H06n zucXE7BrZN>@KvPFVcdYUSpm(Y5CoVJ1Z+gyNyuJl@GUb?tK^8PRX+`bASnjHX9L&h$)n;xkOS-H9p>XXaEv`6%;hN)=HS z)HDuUN(x(>?auGbi`(sE{X6ujOuVD8t|r^Y90{aN?J_^u{l*Q(V3Z$#f25KGTtg>jOmc`B~;6gN#|H)BuZvFRqb5=3EL z9~{kMN<_<(B@bj#_U;ccW@b%h`xC4p%)Si3_G2&~@IEE;kHLBq0gMKji2w_f7&T8@ zaV*ezb{Jo$4o@t~Mk@++`~c&T(E;fLqfb7M;6d?8A~Xd zl%l)Yw-{fc$BALzWA{ofLE)B!X?Y{9oN0MWf@?81cPY>3-`G>-YQ0a2yWJ|)Xt~_2 zLXTKbk@i=61qSbGdG}f__uT#EawTuho#f7RqZR8ZAT!R(@a+ya77dNe(l2;0>&3kB zpwT5}Gt7)M++%Hl*?nfz+6-q>;%HKuUooG8Qn-HJFZjOcKR|!_ z(BNxG(I&F@*9%pGZun|O&7z!AbD+yS^kcixI(!fPu$-DGt>)NY6Cja7R_6zs-^j;M z#Tn_GWVrJ!DwaEjF^*nPP;&**fSiEaDbwYpguFQ4KxocC9>|GXdxz!X9d`!Rjj&`j zg`t|rM#l0PO=*U$!}y4|am0Dl6kmFHOQ@B|e`}qpA%&ft#_Y%$KBNTd3G$-JCK_s7 z{IUS8M5X{~;MB+@B8_askC%Na7+Is;9vFtnFA0Fw6|mEob;cBJ#5%tXK7Q#~2q%s< zo*lyIK1#2PRo0BhO%0xYL{AU;UXc%dhkq*DP!X#%M){mtulo8ZEVm#A<@l%`moM6# z@?VYUs2sP;R=Ucn9Y(D$<8s)=je=VzWsCj@2#42@rOd?`WlR*WV_HOYCsioyo?Jv} zYhwnvOD=!J4r6lpd?1&bcgp3BKzgGBd5;1)Sr|0|TWQSMBlEOY80jW^2jAg(O4m7NvQU5Tfn!@6>f+nfw*SNh0jayx#Ud& zk@9NSa@U;UTJBdodjg~CH{k6LM3UEG)M>^O1Bep)3&BvP1sq2QE+F;hhQ}EE8P+Pr ziGt1>(!}Aos&nfMTW+L%2?I}%B5J&m_9DdH^Jn~m<{195&2OR6debv$o5X)%e?ecG OA4+aNJ2hLLefA%{1u%R7 diff --git a/Python/Graphs/BFS.py b/Python/Graphs/BFS.py index cee47a7..972cc50 100644 --- a/Python/Graphs/BFS.py +++ b/Python/Graphs/BFS.py @@ -4,7 +4,7 @@ # if there are disjoint nodes or if there is no path to some nodes, it won't visit them # This is unlike DFS, which will visit all nodes, but won't necessarily find the shortest path import queue -import Algoritmer.Graphs.Vertex as Vertex +import Vertex as Vertex # G = A list of lists. G[0] contains for example [1,4,6] meaning that node 0 goes to nodes 1, 4 and 6. def BFS(G, start): diff --git a/Python/Graphs/__pycache__/Vertex.cpython-37.pyc b/Python/Graphs/__pycache__/Vertex.cpython-37.pyc deleted file mode 100644 index 2f457d6cfeea66631966dd081436ca7e4b7919ed..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 853 zcmZuuJ#Q015Z>Ou!J)xJ8J@5<*r=givCHLJ?iVM{yXfPB%xeW1r3LSt8bT$)BO; zFYqU}rKh2D#hX1l0*g7#o7vr&o0&JGUhhyqUj6v4e@P*J@?j?doD-;h05}sQNZvrN zRW3-q5rd$_{jDf?Cs6wsP>EcU$Q4OaHzE%xpb$2sh+^1?66B{YeqWiU`dUUvVPVVv zc?q?T0Ih6=7OeuxHUO$N1O^uZ7?QwWWHyLgY@4E4S(nlTUR_o$UKXaR8y8$wS1u`N zdX5)FhPIl0GF-&)d?sYzy5EFJVK&3jvvKw|dpCZ4JUkwbPiGfYG;9`T(#$I}J~PGg zvmJM>KV4qARO?ASX|(3QTFYidpw!crWG-1C#w%A>O)S h&J1(GYMJy@rb!z5yA0j&{r{3&`n)Unf+K!I#UDiDt|$Ni diff --git a/Python/Sortering/ComparisonSortingComplexityLowerBound b/Python/Sortering/ComparisonSortingComplexityLowerBound.md similarity index 64% rename from Python/Sortering/ComparisonSortingComplexityLowerBound rename to Python/Sortering/ComparisonSortingComplexityLowerBound.md index ff9150f..48db245 100644 --- a/Python/Sortering/ComparisonSortingComplexityLowerBound +++ b/Python/Sortering/ComparisonSortingComplexityLowerBound.md @@ -1,21 +1,23 @@ -Hvorfor er det en nedre grense for kompleksiteten til sammenligningsbaserte algoritmer? +# Hvorfor er det en nedre grense for kompleksiteten til sammenligningsbaserte algoritmer? + Forestill deg et sammenligningstre, slik som treet på side 192 i boka. Den maksimale høyden til dette treet er 3, og det er 6 løvnoder. Dette sammenligningstreet sammenligner tallene i en liste med 3 tall. Det er 3!=6 ulike permutasjoner av inputet, så det minste antallet løvnoder er 6. -Så n = 3 -h = 3 -antall løvnoder = 6 +Så n = 3 +h = 3 +antall løvnoder = 6 Det maksimale antallet løvnoder vi kan ha, er 2^h = 2^3 = 8 Det minste antallet løvnoder er n! = 6 Vi vil finne høyden til treet, fordi høyden gir oss antallet sammenligninger vi må gjøre for å sortere listen. (Hvert nivå er en sammenligning). -Dette kan vi finne ved å løse -2^h >= n! -lg2^h >= lg(n!) -h*lg2 >= n lg(n) -h >= n lg(n) -https://www.youtube.com/watch?v=WffUZk1pgXE&ab_channel=BackToBackSWE \ No newline at end of file +Dette kan vi finne ved å løse +2^h >= n! +lg2^h >= lg(n!) +h*lg2 >= n lg(n) +h >= n lg(n) + + diff --git a/Python/Sortering/heapsort.py b/Python/Sortering/heapsort.py deleted file mode 100644 index 4f86a1e..0000000 --- a/Python/Sortering/heapsort.py +++ /dev/null @@ -1,7 +0,0 @@ -import Python.Datastrukturer.Heap as H - - -def heapsort(): # O(n lg n) sorts an array in place - print("") - -