Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const V = [...Array(10)].map(x => Math.round(Math.random() * 100));
- const max3 = function (arr) {
- // 3 passaggi
- let [a, b, c] = [Number.MIN_SAFE_INTEGER, Number.MIN_SAFE_INTEGER - 1, Number.MIN_SAFE_INTEGER - 2];
- // N executions
- for (let i = 0; i < arr.length; i++) {
- // 1 o 2
- if (arr[i] > a) {
- a = arr[i];
- }
- }
- // N executions
- for (let i = 0; i < arr.length; i++) {
- // 1 o 2
- if (arr[i] > b && arr[i] != a) {
- b = arr[i];
- }
- }
- // N executions
- for (let i = 0; i < arr.length; i++) {
- // 1 o 2
- if (arr[i] > c && arr[i] != a && arr[i] != b) {
- c = arr[i];
- }
- }
- return [a, b, c];
- }
- // T(N) = 3N + 3 a 6N + 3 in generale impiega T(N) = KN + K'
- // S(N) = 3 = K
- // Costo lineare = T(N) = N
- // Costo spaziale = S(N) = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement