123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- [
- {
- "label": "time",
- "kind": 6,
- "isExtraImport": true,
- "importPath": "time",
- "description": "time",
- "detail": "time",
- "documentation": {}
- },
- {
- "label": "randint",
- "importPath": "random",
- "description": "random",
- "isExtraImport": true,
- "detail": "random",
- "documentation": {}
- },
- {
- "label": "heap",
- "kind": 6,
- "isExtraImport": true,
- "importPath": "heap",
- "description": "heap",
- "detail": "heap",
- "documentation": {}
- },
- {
- "label": "merge",
- "importPath": "merge",
- "description": "merge",
- "isExtraImport": true,
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "heapify",
- "kind": 2,
- "importPath": "heap",
- "description": "heap",
- "peekOfCode": "def heapify(lista, n, i):\n\tlargest = i # Initialize largest as root\n\tl = 2 * i + 1 # left = 2*i + 1\n\tr = 2 * i + 2 # right = 2*i + 2\n# See if left child of root exists and is\n# greater than root\n\tif l < n and lista[i] < lista[l]:\n\t\tlargest = l\n# See if right child of root exists and is\n# greater than root",
- "detail": "heap",
- "documentation": {}
- },
- {
- "label": "\tlargest",
- "kind": 5,
- "importPath": "heap",
- "description": "heap",
- "peekOfCode": "\tlargest = i # Initialize largest as root\n\tl = 2 * i + 1 # left = 2*i + 1\n\tr = 2 * i + 2 # right = 2*i + 2\n# See if left child of root exists and is\n# greater than root\n\tif l < n and lista[i] < lista[l]:\n\t\tlargest = l\n# See if right child of root exists and is\n# greater than root\n\tif r < n and lista[largest] < lista[r]:",
- "detail": "heap",
- "documentation": {}
- },
- {
- "label": "\tl",
- "kind": 5,
- "importPath": "heap",
- "description": "heap",
- "peekOfCode": "\tl = 2 * i + 1 # left = 2*i + 1\n\tr = 2 * i + 2 # right = 2*i + 2\n# See if left child of root exists and is\n# greater than root\n\tif l < n and lista[i] < lista[l]:\n\t\tlargest = l\n# See if right child of root exists and is\n# greater than root\n\tif r < n and lista[largest] < lista[r]:\n\t\tlargest = r",
- "detail": "heap",
- "documentation": {}
- },
- {
- "label": "\tr",
- "kind": 5,
- "importPath": "heap",
- "description": "heap",
- "peekOfCode": "\tr = 2 * i + 2 # right = 2*i + 2\n# See if left child of root exists and is\n# greater than root\n\tif l < n and lista[i] < lista[l]:\n\t\tlargest = l\n# See if right child of root exists and is\n# greater than root\n\tif r < n and lista[largest] < lista[r]:\n\t\tlargest = r\n# Change root, if needed",
- "detail": "heap",
- "documentation": {}
- },
- {
- "label": "\t\tlargest",
- "kind": 5,
- "importPath": "heap",
- "description": "heap",
- "peekOfCode": "\t\tlargest = l\n# See if right child of root exists and is\n# greater than root\n\tif r < n and lista[largest] < lista[r]:\n\t\tlargest = r\n# Change root, if needed\n\tif largest != i:\n\t\t(lista[i], lista[largest]) = (lista[largest], lista[i]) # swap\n# Heapify the root.\n\t\theapify(lista, n, largest)",
- "detail": "heap",
- "documentation": {}
- },
- {
- "label": "\t\tlargest",
- "kind": 5,
- "importPath": "heap",
- "description": "heap",
- "peekOfCode": "\t\tlargest = r\n# Change root, if needed\n\tif largest != i:\n\t\t(lista[i], lista[largest]) = (lista[largest], lista[i]) # swap\n# Heapify the root.\n\t\theapify(lista, n, largest)",
- "detail": "heap",
- "documentation": {}
- },
- {
- "label": "merge",
- "kind": 2,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "def merge(arr, l, m, r):\n\tn1 = m - l + 1\n\tn2 = r - m\n\t# create temp arrays\n\tL = [0] * (n1)\n\tR = [0] * (n2)\n\t# Copy data to temp arrays L[] and R[]\n\tfor i in range(0, n1):\n\t\tL[i] = arr[l + i]\n\tfor j in range(0, n2):",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\tn1",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\tn1 = m - l + 1\n\tn2 = r - m\n\t# create temp arrays\n\tL = [0] * (n1)\n\tR = [0] * (n2)\n\t# Copy data to temp arrays L[] and R[]\n\tfor i in range(0, n1):\n\t\tL[i] = arr[l + i]\n\tfor j in range(0, n2):\n\t\tR[j] = arr[m + 1 + j]",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\tn2",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\tn2 = r - m\n\t# create temp arrays\n\tL = [0] * (n1)\n\tR = [0] * (n2)\n\t# Copy data to temp arrays L[] and R[]\n\tfor i in range(0, n1):\n\t\tL[i] = arr[l + i]\n\tfor j in range(0, n2):\n\t\tR[j] = arr[m + 1 + j]\n\t# Merge the temp arrays back into arr[l..r]",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\tL",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\tL = [0] * (n1)\n\tR = [0] * (n2)\n\t# Copy data to temp arrays L[] and R[]\n\tfor i in range(0, n1):\n\t\tL[i] = arr[l + i]\n\tfor j in range(0, n2):\n\t\tR[j] = arr[m + 1 + j]\n\t# Merge the temp arrays back into arr[l..r]\n\ti = 0\t # Initial index of first subarray\n\tj = 0\t # Initial index of second subarray",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\tR",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\tR = [0] * (n2)\n\t# Copy data to temp arrays L[] and R[]\n\tfor i in range(0, n1):\n\t\tL[i] = arr[l + i]\n\tfor j in range(0, n2):\n\t\tR[j] = arr[m + 1 + j]\n\t# Merge the temp arrays back into arr[l..r]\n\ti = 0\t # Initial index of first subarray\n\tj = 0\t # Initial index of second subarray\n\tk = l\t # Initial index of merged subarray",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\t\tL[i]",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\t\tL[i] = arr[l + i]\n\tfor j in range(0, n2):\n\t\tR[j] = arr[m + 1 + j]\n\t# Merge the temp arrays back into arr[l..r]\n\ti = 0\t # Initial index of first subarray\n\tj = 0\t # Initial index of second subarray\n\tk = l\t # Initial index of merged subarray\n\twhile i < n1 and j < n2:\n\t\tif L[i] <= R[j]:\n\t\t\tarr[k] = L[i]",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\t\tR[j]",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\t\tR[j] = arr[m + 1 + j]\n\t# Merge the temp arrays back into arr[l..r]\n\ti = 0\t # Initial index of first subarray\n\tj = 0\t # Initial index of second subarray\n\tk = l\t # Initial index of merged subarray\n\twhile i < n1 and j < n2:\n\t\tif L[i] <= R[j]:\n\t\t\tarr[k] = L[i]\n\t\t\ti += 1\n\t\telse:",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\ti",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\ti = 0\t # Initial index of first subarray\n\tj = 0\t # Initial index of second subarray\n\tk = l\t # Initial index of merged subarray\n\twhile i < n1 and j < n2:\n\t\tif L[i] <= R[j]:\n\t\t\tarr[k] = L[i]\n\t\t\ti += 1\n\t\telse:\n\t\t\tarr[k] = R[j]\n\t\t\tj += 1",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\tj",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\tj = 0\t # Initial index of second subarray\n\tk = l\t # Initial index of merged subarray\n\twhile i < n1 and j < n2:\n\t\tif L[i] <= R[j]:\n\t\t\tarr[k] = L[i]\n\t\t\ti += 1\n\t\telse:\n\t\t\tarr[k] = R[j]\n\t\t\tj += 1\n\t\tk += 1",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\tk",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\tk = l\t # Initial index of merged subarray\n\twhile i < n1 and j < n2:\n\t\tif L[i] <= R[j]:\n\t\t\tarr[k] = L[i]\n\t\t\ti += 1\n\t\telse:\n\t\t\tarr[k] = R[j]\n\t\t\tj += 1\n\t\tk += 1\n\t# Copy the remaining elements of L[], if there",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\t\t\tarr[k]",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\t\t\tarr[k] = L[i]\n\t\t\ti += 1\n\t\telse:\n\t\t\tarr[k] = R[j]\n\t\t\tj += 1\n\t\tk += 1\n\t# Copy the remaining elements of L[], if there\n\t# are any\n\twhile i < n1:\n\t\tarr[k] = L[i]",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\t\t\tarr[k]",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\t\t\tarr[k] = R[j]\n\t\t\tj += 1\n\t\tk += 1\n\t# Copy the remaining elements of L[], if there\n\t# are any\n\twhile i < n1:\n\t\tarr[k] = L[i]\n\t\ti += 1\n\t\tk += 1\n\t# Copy the remaining elements of R[], if there",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\t\tarr[k]",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\t\tarr[k] = L[i]\n\t\ti += 1\n\t\tk += 1\n\t# Copy the remaining elements of R[], if there\n\t# are any\n\twhile j < n2:\n\t\tarr[k] = R[j]\n\t\tj += 1\n\t\tk += 1\n# l is for left index and r is right index of the",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "\t\tarr[k]",
- "kind": 5,
- "importPath": "merge",
- "description": "merge",
- "peekOfCode": "\t\tarr[k] = R[j]\n\t\tj += 1\n\t\tk += 1\n# l is for left index and r is right index of the\n# sub-array of arr to be sorted",
- "detail": "merge",
- "documentation": {}
- },
- {
- "label": "mergeSort",
- "kind": 2,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "def mergeSort(lista, l, r):\n\tif l < r:\n # Same as (l+r)//2, but avoids overflow for\n # large l and h\n\t\tm = l+(r-l)//2\n # Sort first and second halves\n\t\tmergeSort(lista, l, m)\n\t\tmergeSort(lista, m+1, r)\n\t\tmerge(lista, l, m, r)\n''' Luis Andrés López Mañán",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "heapSort",
- "kind": 2,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "def heapSort(lista):\n\t# Se busca el tamaño de la lista\n\tn = len(lista)\n\theap.heapify(lista,n,0)\n\t\"\"\" Se crea un heap máximo y el último padre estará en\n\t\tla posición h1, i.e., la mitad del tamaño de la lista.\n\t\tPor lo tanto, ese sería el comienzo. \n\t\"\"\"\n\th1 = (n // 2) - 1\n\tfor i in range(h1, -1, -1):",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "quickSort",
- "kind": 2,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "def quickSort(lista):\n\t# definan el algoritmo de ordenamiento quicksort\n\telements = len(lista)\n # Base case\n\tif elements < 2:\n\t\treturn lista\n\tcurrent_position = 0 #Position of the partitioning element\n\tfor i in range(1, elements): #Partitioning loop\n\t\tif lista[i] <= lista[0]:\n\t\t\tcurrent_position += 1",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "shellSort",
- "kind": 2,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "def shellSort(lista):\n\t# definan el algoritmo de ordenamiento shellsort\n\t# determening the size of the list and calculates the gap value. \n\tn = len(lista)\n\tgap = n // 2\n\t# this algorithm will run until gap reaches 1 \n\twhile gap > 0:\n\t\tfor i in range(gap, n):\n\t\t\ttemp = lista[i] # storing all items from the list into temp \n\t\t\tj = i ",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\t\tm",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\t\tm = l+(r-l)//2\n # Sort first and second halves\n\t\tmergeSort(lista, l, m)\n\t\tmergeSort(lista, m+1, r)\n\t\tmerge(lista, l, m, r)\n''' Luis Andrés López Mañán\n Program written by hand as a draft on 09/19/2022\n Credit goes to GeeksForGeeks\n Link: https://www.geeksforgeeks.org/python-program-for-heap-sort/\n Last access on 09/19/2022",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tn",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tn = len(lista)\n\theap.heapify(lista,n,0)\n\t\"\"\" Se crea un heap máximo y el último padre estará en\n\t\tla posición h1, i.e., la mitad del tamaño de la lista.\n\t\tPor lo tanto, ese sería el comienzo. \n\t\"\"\"\n\th1 = (n // 2) - 1\n\tfor i in range(h1, -1, -1):\n\t\theap.heapify(lista, n, i)\n\t# Se extrae los elementos uno a uno",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\th1",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\th1 = (n // 2) - 1\n\tfor i in range(h1, -1, -1):\n\t\theap.heapify(lista, n, i)\n\t# Se extrae los elementos uno a uno\n\th2 = n - 1\n\tfor i in range(h2, 0, -1):\n\t\t# Se intercambia, luego se hace heapify\n\t\tlista[i], lista[0] = lista[0], lista[i]\n\t\theap.heapify(lista, 0, i)\n\treturn lista",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\th2",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\th2 = n - 1\n\tfor i in range(h2, 0, -1):\n\t\t# Se intercambia, luego se hace heapify\n\t\tlista[i], lista[0] = lista[0], lista[i]\n\t\theap.heapify(lista, 0, i)\n\treturn lista\ndef quickSort(lista):\n\t# definan el algoritmo de ordenamiento quicksort\n\telements = len(lista)\n # Base case",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\telements",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\telements = len(lista)\n # Base case\n\tif elements < 2:\n\t\treturn lista\n\tcurrent_position = 0 #Position of the partitioning element\n\tfor i in range(1, elements): #Partitioning loop\n\t\tif lista[i] <= lista[0]:\n\t\t\tcurrent_position += 1\n\t\t\ttemp = lista[i]\n\t\t\tlista[i] = lista[current_position]",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tcurrent_position",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tcurrent_position = 0 #Position of the partitioning element\n\tfor i in range(1, elements): #Partitioning loop\n\t\tif lista[i] <= lista[0]:\n\t\t\tcurrent_position += 1\n\t\t\ttemp = lista[i]\n\t\t\tlista[i] = lista[current_position]\n\t\t\tlista[current_position] = temp\n\ttemp = lista[0]\n\tlista[0] = lista[current_position] \n\tlista[current_position] = temp #Brings pivot to it's appropriate position",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\t\t\ttemp",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\t\t\ttemp = lista[i]\n\t\t\tlista[i] = lista[current_position]\n\t\t\tlista[current_position] = temp\n\ttemp = lista[0]\n\tlista[0] = lista[current_position] \n\tlista[current_position] = temp #Brings pivot to it's appropriate position\n\tleft = quickSort(lista[0:current_position]) #Sorts the elements to the left of pivot\n\tright = quickSort(lista[current_position+1:elements]) #sorts the elements to the right of pivot\n\tlista = left + [lista[current_position]] + right #Merging everything together\n\treturn lista",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\t\t\tlista[i]",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\t\t\tlista[i] = lista[current_position]\n\t\t\tlista[current_position] = temp\n\ttemp = lista[0]\n\tlista[0] = lista[current_position] \n\tlista[current_position] = temp #Brings pivot to it's appropriate position\n\tleft = quickSort(lista[0:current_position]) #Sorts the elements to the left of pivot\n\tright = quickSort(lista[current_position+1:elements]) #sorts the elements to the right of pivot\n\tlista = left + [lista[current_position]] + right #Merging everything together\n\treturn lista\n''' ",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\t\t\tlista[current_position]",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\t\t\tlista[current_position] = temp\n\ttemp = lista[0]\n\tlista[0] = lista[current_position] \n\tlista[current_position] = temp #Brings pivot to it's appropriate position\n\tleft = quickSort(lista[0:current_position]) #Sorts the elements to the left of pivot\n\tright = quickSort(lista[current_position+1:elements]) #sorts the elements to the right of pivot\n\tlista = left + [lista[current_position]] + right #Merging everything together\n\treturn lista\n''' \n\tThis algorithm was taken from: https://www.programiz.com/dsa/shell-sort ",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\ttemp",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\ttemp = lista[0]\n\tlista[0] = lista[current_position] \n\tlista[current_position] = temp #Brings pivot to it's appropriate position\n\tleft = quickSort(lista[0:current_position]) #Sorts the elements to the left of pivot\n\tright = quickSort(lista[current_position+1:elements]) #sorts the elements to the right of pivot\n\tlista = left + [lista[current_position]] + right #Merging everything together\n\treturn lista\n''' \n\tThis algorithm was taken from: https://www.programiz.com/dsa/shell-sort \n\tand was adapted in order to work for this assigment.",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tlista[0]",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tlista[0] = lista[current_position] \n\tlista[current_position] = temp #Brings pivot to it's appropriate position\n\tleft = quickSort(lista[0:current_position]) #Sorts the elements to the left of pivot\n\tright = quickSort(lista[current_position+1:elements]) #sorts the elements to the right of pivot\n\tlista = left + [lista[current_position]] + right #Merging everything together\n\treturn lista\n''' \n\tThis algorithm was taken from: https://www.programiz.com/dsa/shell-sort \n\tand was adapted in order to work for this assigment.\n'''",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tlista[current_position]",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tlista[current_position] = temp #Brings pivot to it's appropriate position\n\tleft = quickSort(lista[0:current_position]) #Sorts the elements to the left of pivot\n\tright = quickSort(lista[current_position+1:elements]) #sorts the elements to the right of pivot\n\tlista = left + [lista[current_position]] + right #Merging everything together\n\treturn lista\n''' \n\tThis algorithm was taken from: https://www.programiz.com/dsa/shell-sort \n\tand was adapted in order to work for this assigment.\n'''\ndef shellSort(lista):",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tleft",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tleft = quickSort(lista[0:current_position]) #Sorts the elements to the left of pivot\n\tright = quickSort(lista[current_position+1:elements]) #sorts the elements to the right of pivot\n\tlista = left + [lista[current_position]] + right #Merging everything together\n\treturn lista\n''' \n\tThis algorithm was taken from: https://www.programiz.com/dsa/shell-sort \n\tand was adapted in order to work for this assigment.\n'''\ndef shellSort(lista):\n\t# definan el algoritmo de ordenamiento shellsort",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tright",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tright = quickSort(lista[current_position+1:elements]) #sorts the elements to the right of pivot\n\tlista = left + [lista[current_position]] + right #Merging everything together\n\treturn lista\n''' \n\tThis algorithm was taken from: https://www.programiz.com/dsa/shell-sort \n\tand was adapted in order to work for this assigment.\n'''\ndef shellSort(lista):\n\t# definan el algoritmo de ordenamiento shellsort\n\t# determening the size of the list and calculates the gap value. ",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tlista",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tlista = left + [lista[current_position]] + right #Merging everything together\n\treturn lista\n''' \n\tThis algorithm was taken from: https://www.programiz.com/dsa/shell-sort \n\tand was adapted in order to work for this assigment.\n'''\ndef shellSort(lista):\n\t# definan el algoritmo de ordenamiento shellsort\n\t# determening the size of the list and calculates the gap value. \n\tn = len(lista)",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tn",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tn = len(lista)\n\tgap = n // 2\n\t# this algorithm will run until gap reaches 1 \n\twhile gap > 0:\n\t\tfor i in range(gap, n):\n\t\t\ttemp = lista[i] # storing all items from the list into temp \n\t\t\tj = i \n\t\t\t# compares the number in temp with the 0th possition (start of list)\n\t\t\t# if temp is larger than the first element then we swap them\n\t\t\twhile j >= gap and lista[j - gap] > temp: ",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tgap",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tgap = n // 2\n\t# this algorithm will run until gap reaches 1 \n\twhile gap > 0:\n\t\tfor i in range(gap, n):\n\t\t\ttemp = lista[i] # storing all items from the list into temp \n\t\t\tj = i \n\t\t\t# compares the number in temp with the 0th possition (start of list)\n\t\t\t# if temp is larger than the first element then we swap them\n\t\t\twhile j >= gap and lista[j - gap] > temp: \n\t\t\t\tlista[j] = lista[j - gap]",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\t\t\ttemp",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\t\t\ttemp = lista[i] # storing all items from the list into temp \n\t\t\tj = i \n\t\t\t# compares the number in temp with the 0th possition (start of list)\n\t\t\t# if temp is larger than the first element then we swap them\n\t\t\twhile j >= gap and lista[j - gap] > temp: \n\t\t\t\tlista[j] = lista[j - gap]\n\t\t\t\tj -= gap\n\t\t\tlista[j] = temp\n\t\tgap = gap // 2 # decreases the gap to continue the loop \n\treturn lista",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\t\t\tj",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\t\t\tj = i \n\t\t\t# compares the number in temp with the 0th possition (start of list)\n\t\t\t# if temp is larger than the first element then we swap them\n\t\t\twhile j >= gap and lista[j - gap] > temp: \n\t\t\t\tlista[j] = lista[j - gap]\n\t\t\t\tj -= gap\n\t\t\tlista[j] = temp\n\t\tgap = gap // 2 # decreases the gap to continue the loop \n\treturn lista\nmaxValor=1000 \t#define el valor maximo de los elementos de la lista",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\t\t\t\tlista[j]",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\t\t\t\tlista[j] = lista[j - gap]\n\t\t\t\tj -= gap\n\t\t\tlista[j] = temp\n\t\tgap = gap // 2 # decreases the gap to continue the loop \n\treturn lista\nmaxValor=1000 \t#define el valor maximo de los elementos de la lista\nlargoLista=1000 #define el largo de las listas a ordenar\nveces=100 \t\t#define las veces que se va a hacer el ordenamiento \nacumulaMerge=0 \t#variable para acumular el tiempo de ejecucion del mergesort\nacumulaHeap=0 \t#variable para acumular el tiempo de ejecucion del heapsort",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\t\t\tlista[j]",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\t\t\tlista[j] = temp\n\t\tgap = gap // 2 # decreases the gap to continue the loop \n\treturn lista\nmaxValor=1000 \t#define el valor maximo de los elementos de la lista\nlargoLista=1000 #define el largo de las listas a ordenar\nveces=100 \t\t#define las veces que se va a hacer el ordenamiento \nacumulaMerge=0 \t#variable para acumular el tiempo de ejecucion del mergesort\nacumulaHeap=0 \t#variable para acumular el tiempo de ejecucion del heapsort\nacumulaQuick=0 \t#variable para acumular el tiempo de ejecucion del quicksort\nacumulaShell=0 \t#variable para acumular el tiempo de ejecucion del shellsort",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\t\tgap",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\t\tgap = gap // 2 # decreases the gap to continue the loop \n\treturn lista\nmaxValor=1000 \t#define el valor maximo de los elementos de la lista\nlargoLista=1000 #define el largo de las listas a ordenar\nveces=100 \t\t#define las veces que se va a hacer el ordenamiento \nacumulaMerge=0 \t#variable para acumular el tiempo de ejecucion del mergesort\nacumulaHeap=0 \t#variable para acumular el tiempo de ejecucion del heapsort\nacumulaQuick=0 \t#variable para acumular el tiempo de ejecucion del quicksort\nacumulaShell=0 \t#variable para acumular el tiempo de ejecucion del shellsort\nfor i in range(veces):",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tmergelista",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tmergelista = [randint(0,maxValor) for r in range(largoLista)] #creamos una lista con valores al azar\n\theaplista=list(mergelista)\n\tquicklista=list(mergelista)\n\tsearchlista=list(mergelista)\n\tt1 = time.process_time()\t\t\t\t\t#tomamos el tiempo inicial\n\tmergeSort(mergelista,0,len(mergelista)-1) \t#ejecutamos el algoritmo mergeSort\n\tacumulaMerge+=time.process_time() - t1\t\t#acumulamos el tiempo de ejecucion\n\t# print(mergelista)\t\t\t\t\t\t\t#desplegamos la lista\n\tt1 = time.process_time()\t\t\t\t#tomamos el tiempo inicial\n\theapSort(heaplista)\t\t\t\t\t #ejecutamos el algoritmo heapSort",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tt1",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tt1 = time.process_time()\t\t\t\t\t#tomamos el tiempo inicial\n\tmergeSort(mergelista,0,len(mergelista)-1) \t#ejecutamos el algoritmo mergeSort\n\tacumulaMerge+=time.process_time() - t1\t\t#acumulamos el tiempo de ejecucion\n\t# print(mergelista)\t\t\t\t\t\t\t#desplegamos la lista\n\tt1 = time.process_time()\t\t\t\t#tomamos el tiempo inicial\n\theapSort(heaplista)\t\t\t\t\t #ejecutamos el algoritmo heapSort\n\tacumulaHeap+=time.process_time() - t1 \t#acumulamos el tiempo de ejecucion\n\t# print(heaplista)\t\t\t\t\t\t#desplegamos la lista\n\tt1 = time.process_time()\t\t\t\t#tomamos el tiempo inicial\n\tquickresult = quickSort(quicklista)\t\t\t\t\t#ejecutamos el algoritmo quickSort",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tt1",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tt1 = time.process_time()\t\t\t\t#tomamos el tiempo inicial\n\theapSort(heaplista)\t\t\t\t\t #ejecutamos el algoritmo heapSort\n\tacumulaHeap+=time.process_time() - t1 \t#acumulamos el tiempo de ejecucion\n\t# print(heaplista)\t\t\t\t\t\t#desplegamos la lista\n\tt1 = time.process_time()\t\t\t\t#tomamos el tiempo inicial\n\tquickresult = quickSort(quicklista)\t\t\t\t\t#ejecutamos el algoritmo quickSort\n\tacumulaQuick+=time.process_time() - t1\t#acumulamos el tiempo de ejecucion\n\t# print(quicklista)\t\t\t\t\t\t#desplegamos la lista\n\tt1 = time.process_time()\t\t\t\t#tomamos el tiempo inicial\n\tshellSort(searchlista)\t\t\t\t\t#ejecutamos el algoritmo shellSort",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tt1",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tt1 = time.process_time()\t\t\t\t#tomamos el tiempo inicial\n\tquickresult = quickSort(quicklista)\t\t\t\t\t#ejecutamos el algoritmo quickSort\n\tacumulaQuick+=time.process_time() - t1\t#acumulamos el tiempo de ejecucion\n\t# print(quicklista)\t\t\t\t\t\t#desplegamos la lista\n\tt1 = time.process_time()\t\t\t\t#tomamos el tiempo inicial\n\tshellSort(searchlista)\t\t\t\t\t#ejecutamos el algoritmo shellSort\n\tacumulaShell+=time.process_time() - t1\t#acumulamos el tiempo de ejecucion\n\t# print(searchlista)\t\t\t\t\t\t#desplegamos la lista\n# imprimos los resultados\nprint (\"Promedio de tiempo de ejecucion de \"+ str(veces) +\" listas de largo \" + str(largoLista))",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tquickresult",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tquickresult = quickSort(quicklista)\t\t\t\t\t#ejecutamos el algoritmo quickSort\n\tacumulaQuick+=time.process_time() - t1\t#acumulamos el tiempo de ejecucion\n\t# print(quicklista)\t\t\t\t\t\t#desplegamos la lista\n\tt1 = time.process_time()\t\t\t\t#tomamos el tiempo inicial\n\tshellSort(searchlista)\t\t\t\t\t#ejecutamos el algoritmo shellSort\n\tacumulaShell+=time.process_time() - t1\t#acumulamos el tiempo de ejecucion\n\t# print(searchlista)\t\t\t\t\t\t#desplegamos la lista\n# imprimos los resultados\nprint (\"Promedio de tiempo de ejecucion de \"+ str(veces) +\" listas de largo \" + str(largoLista))\nprint (\"MergeSort \" + str(acumulaMerge/veces) + \" segundos\")",
- "detail": "sorting",
- "documentation": {}
- },
- {
- "label": "\tt1",
- "kind": 5,
- "importPath": "sorting",
- "description": "sorting",
- "peekOfCode": "\tt1 = time.process_time()\t\t\t\t#tomamos el tiempo inicial\n\tshellSort(searchlista)\t\t\t\t\t#ejecutamos el algoritmo shellSort\n\tacumulaShell+=time.process_time() - t1\t#acumulamos el tiempo de ejecucion\n\t# print(searchlista)\t\t\t\t\t\t#desplegamos la lista\n# imprimos los resultados\nprint (\"Promedio de tiempo de ejecucion de \"+ str(veces) +\" listas de largo \" + str(largoLista))\nprint (\"MergeSort \" + str(acumulaMerge/veces) + \" segundos\")\nprint (\"HeapSort \" + str(acumulaHeap/veces) + \" segundos\")\nprint (\"QuickSort \" + str(acumulaQuick/veces) + \" segundos\")\nprint (\"ShellSort \" + str(acumulaShell/veces) + \" segundos\")",
- "detail": "sorting",
- "documentation": {}
- }
- ]
|