Length of the array | Simple search algorithm | Binary search |
---|---|---|
10 | 10 | 3 |
100 | 100 | 6 |
1000 | 1000 | 10 |
1.000.000 | 1.000.000 | 20 |
1.000.000.000 | 1.000.000.000 | 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "../utils.c" | |
#define DIM 10000 | |
int main () { | |
long array [DIM]; | |
int i,j; | |
for (i = 0; i < DIM; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/*Devi trovare un modo di raccogliere un numero in input e invertire le cifre. | |
Devi anche fare attenzione al fatto che se il numero finisce con 0 (Γ¨ multiplo di 10), non devi scrivere 0 | |
davanti al numero invertito. | |
Cioè se l'utente ti inserisce 432 devi ottenere 234. Oppure se l'utente ti inserisce 230, devi ottenere 32. | |
Occhio non puoi 'salvare' il numero che inverti da qualche parte: non sai quanto Γ¨ lungo il numero che ti viene inserito. | |
Quindi non puoi utilizzare un array. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def multiplication (n :str,m :int): | |
reversed = list(n) | |
reversed.reverse() | |
newNumber = "" | |
remainder = 0 | |
for r in reversed: | |
result = int(r) * m + remainder | |
newNumber = str(result)[-1] + newNumber |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// Object stored in the cache, could be anything | |
class Object (val key: String, val value: Int) | |
class LeastFrequentlyUsed (private val cacheLimit :Int) { | |
// Holds objects | |
private val cache = mutableListOf<Object>() | |
// Keeps track of hashes -> index, used in get(key) => hash(key) => index | |
private val indexLinks = mutableMapOf<Int,Int>() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import turtle | |
# Draws a circle from the origin with a given radius | |
def drawCircle ( turtle :turtle.Turtle, radius :int, origin :tuple=(0,0), penSize :int=1, penColor :str="black", writeLabel :bool=False ) : | |
turtle.pensize(penSize) | |
turtle.pencolor(penColor) | |
turtle.up() | |
turtle.goto(origin[0],origin[1]-radius) | |
turtle.down() | |
turtle.circle(radius) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Compare (arrayA, arrayB []int) bool { | |
for i := range arrayA { | |
if arrayA[i] != arrayB[i] { | |
return false | |
} | |
} | |
return true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ToeplitzCheck(matrix): | |
crntRow = 0 | |
maxRow = len(matrix) | |
while crntRow < maxRow -1 : | |
if matrix[crntRow][0:len(matrix)-1] != matrix[crntRow+1][1:len(matrix)]: | |
return False | |
crntRow += 1 | |
return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binarySearch (array, element): | |
a = 1 | |
b = len(array) | |
while array[int((a+b)/2)] != element: | |
m = int((a+b)/2) | |
if (array[m]) > element: | |
b = m - 1 | |
else: | |
a = m + 1 | |
if a > b: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def simpleSort (array, element): | |
for a in array: | |
if a == element: | |
return true | |
return false |
NewerOlder