chore(i18n,curriculum): update translations (#42976)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 8d5123c8c441eddfaeb5bdef
|
||||
title: Implement Bubble Sort
|
||||
title: Implementare Bubble Sort
|
||||
challengeType: 1
|
||||
forumTopicId: 301612
|
||||
dashedName: implement-bubble-sort
|
||||
@ -8,23 +8,23 @@ dashedName: implement-bubble-sort
|
||||
|
||||
# --description--
|
||||
|
||||
This is the first of several challenges on sorting algorithms. Given an array of unsorted items, we want to be able to return a sorted array. We will see several different methods to do this and learn some tradeoffs between these different approaches. While most modern languages have built-in sorting methods for operations like this, it is still important to understand some of the common basic approaches and learn how they can be implemented.
|
||||
Questa è la prima di diverse sfide sugli algoritmi di ordinamento. Dato un array di elementi non ordinati, vogliamo essere in grado di restituire un array ordinato. Vedremo diversi metodi per farlo e impareremo alcuni compromessi tra questi diversi approcci. Mentre la maggior parte dei linguaggi moderni ha integrato metodi di ordinamento per operazioni come questa, è ancora importante comprendere alcuni degli approcci di base comuni e imparare come possono essere attuati.
|
||||
|
||||
Here we will see bubble sort. The bubble sort method starts at the beginning of an unsorted array and 'bubbles up' unsorted values towards the end, iterating through the array until it is completely sorted. It does this by comparing adjacent items and swapping them if they are out of order. The method continues looping through the array until no swaps occur at which point the array is sorted.
|
||||
Qui vedremo il Bubble Sort. Il metodo di ordinamento Bubble Sort comincia all'inizio di un array non ordinato e 'porta a galla' i valori non ordinati verso la fine, iterando attraverso l'array fino a quando non è completamente ordinato. Lo fa confrontando gli elementi adiacenti e scambiandoli se sono fuori ordine. Il metodo continua a iterare attraverso l'array fino a quando non si verificano più scambi: a quel punto l'array è ordinato.
|
||||
|
||||
This method requires multiple iterations through the array and for average and worst cases has quadratic time complexity. While simple, it is usually impractical in most situations.
|
||||
Questo metodo richiede iterazioni multiple attraverso l'array e per i casi medi e peggiori ha complessità di tempo quadratica. Per quanto semplice, è poco pratico nella maggior parte delle situazioni.
|
||||
|
||||
**Instructions:** Write a function `bubbleSort` which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest.
|
||||
**Istruzioni:** Scrivi una funzione `bubbleSort` che prende un array di interi come input e restituisce un array di questi interi in ordine dal più piccolo al più grande.
|
||||
|
||||
# --hints--
|
||||
|
||||
`bubbleSort` should be a function.
|
||||
`bubbleSort` dovrebbe essere una funzione.
|
||||
|
||||
```js
|
||||
assert(typeof bubbleSort == 'function');
|
||||
```
|
||||
|
||||
`bubbleSort` should return a sorted array (least to greatest).
|
||||
`bubbleSort` dovrebbe restituire un array ordinato (dal più piccolo al più grande).
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -52,7 +52,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`bubbleSort` should return an array that is unchanged except for order.
|
||||
`bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])` dovrebbe restituire un array invariato tranne che per l'ordine.
|
||||
|
||||
```js
|
||||
assert.sameMembers(
|
||||
@ -79,7 +79,7 @@ assert.sameMembers(
|
||||
);
|
||||
```
|
||||
|
||||
`bubbleSort` should not use the built-in `.sort()` method.
|
||||
`bubbleSort` non dovrebbe usare il metodo integrato `.sort()`.
|
||||
|
||||
```js
|
||||
assert(isBuiltInSortUsed());
|
||||
@ -113,8 +113,6 @@ function bubbleSort(array) {
|
||||
return array;
|
||||
// Only change code above this line
|
||||
}
|
||||
|
||||
bubbleSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: a7bf700cd123b9a54eef01d5
|
||||
title: No Repeats Please
|
||||
title: Nessuna ripetizione per favore
|
||||
challengeType: 5
|
||||
forumTopicId: 16037
|
||||
dashedName: no-repeats-please
|
||||
@ -8,67 +8,67 @@ dashedName: no-repeats-please
|
||||
|
||||
# --description--
|
||||
|
||||
Return the number of total permutations of the provided string that don't have repeated consecutive letters. Assume that all characters in the provided string are each unique.
|
||||
Restituisci il numero di permutazioni totali della stringa fornita che non hanno lettere consecutive ripetute. Supponiamo che tutti i caratteri della stringa fornita siano univoci.
|
||||
|
||||
For example, `aab` should return 2 because it has 6 total permutations (`aab`, `aab`, `aba`, `aba`, `baa`, `baa`), but only 2 of them (`aba` and `aba`) don't have the same letter (in this case `a`) repeating.
|
||||
Ad esempio, `aab` dovrebbe restituire 2 perché ha 6 permutazioni totali (`aab`, `aab`, `aba`, `aba`, `baa`, `baa`), ma solo 2 di loro (`aba` e `aba`) non hanno la stessa lettera (in questo caso `a`) ripetuta.
|
||||
|
||||
# --hints--
|
||||
|
||||
`permAlone("aab")` should return a number.
|
||||
`permAlone("aab")` dovrebbe restituire un numero.
|
||||
|
||||
```js
|
||||
assert.isNumber(permAlone('aab'));
|
||||
```
|
||||
|
||||
`permAlone("aab")` should return 2.
|
||||
`permAlone("aab")` dovrebbe restituire 2.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('aab'), 2);
|
||||
```
|
||||
|
||||
`permAlone("aaa")` should return 0.
|
||||
`permAlone("aaa")` dovrebbe restituire 0.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('aaa'), 0);
|
||||
```
|
||||
|
||||
`permAlone("aabb")` should return 8.
|
||||
`permAlone("aabb")` dovrebbe restituire 8.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('aabb'), 8);
|
||||
```
|
||||
|
||||
`permAlone("abcdefa")` should return 3600.
|
||||
`permAlone("abcdefa")` dovrebbe restituire 3600.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('abcdefa'), 3600);
|
||||
```
|
||||
|
||||
`permAlone("abfdefa")` should return 2640.
|
||||
`permAlone("abfdefa")` dovrebbe restituire 2640.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('abfdefa'), 2640);
|
||||
```
|
||||
|
||||
`permAlone("zzzzzzzz")` should return 0.
|
||||
`permAlone("zzzzzzzz")` dovrebbe restituire 0.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('zzzzzzzz'), 0);
|
||||
```
|
||||
|
||||
`permAlone("a")` should return 1.
|
||||
`permAlone("a")` dovrebbe restituire 1.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('a'), 1);
|
||||
```
|
||||
|
||||
`permAlone("aaab")` should return 0.
|
||||
`permAlone("aaab")` dovrebbe restituire 0.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('aaab'), 0);
|
||||
```
|
||||
|
||||
`permAlone("aaabb")` should return 12.
|
||||
`permAlone("aaabb")` dovrebbe restituire 12.
|
||||
|
||||
```js
|
||||
assert.strictEqual(permAlone('aaabb'), 12);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: a3f503de51cfab748ff001aa
|
||||
title: Pairwise
|
||||
title: A coppie
|
||||
challengeType: 5
|
||||
forumTopicId: 301617
|
||||
dashedName: pairwise
|
||||
@ -8,11 +8,11 @@ dashedName: pairwise
|
||||
|
||||
# --description--
|
||||
|
||||
Given an array `arr`, find element pairs whose sum equal the second argument `arg` and return the sum of their indices.
|
||||
Dato un array `arr`, trova coppie di elementi la cui somma è uguale al secondo argomento `arg` e restituisci la somma dei loro indici.
|
||||
|
||||
You may use multiple pairs that have the same numeric elements but different indices. Each pair should use the lowest possible available indices. Once an element has been used it cannot be reused to pair with another element. For instance, `pairwise([1, 1, 2], 3)` creates a pair `[2, 1]` using the 1 at index 0 rather than the 1 at index 1, because 0+2 < 1+2.
|
||||
È possibile utilizzare più coppie che hanno gli stessi elementi numerici ma indici diversi. Ogni coppia dovrebbe utilizzare i più bassi indici disponibili. Una volta che un elemento è stato usato, non può essere riutilizzato per accoppiarsi con un altro elemento. Per esempio, `pairwise([1, 1, 2], 3)` crea una coppia `[2, 1]` usando l’1 all’indice 0 piuttosto che l’1 all’indice 1, perché 0+2 < 1+2.
|
||||
|
||||
For example `pairwise([7, 9, 11, 13, 15], 20)` returns `6`. The pairs that sum to 20 are `[7, 13]` and `[9, 11]`. We can then write out the array with their indices and values.
|
||||
Per esempio `pairwise([7, 9, 11, 13, 15], 20)` restituisce `6`. Le coppie la cui somma è 20 sono `[7, 13]` e `[9, 11]`. Possiamo poi scrivere l'array con i loro indici e valori.
|
||||
|
||||
<div style='margin-left: 2em;'>
|
||||
|
||||
@ -22,7 +22,7 @@ For example `pairwise([7, 9, 11, 13, 15], 20)` returns `6`. The pairs that sum t
|
||||
|
||||
</div>
|
||||
|
||||
Below we'll take their corresponding indices and add them.
|
||||
Qui sotto prenderemo i loro indici corrispondenti e ne faremo la somma.
|
||||
|
||||
<div style='margin-left: 2em;'>
|
||||
|
||||
@ -34,31 +34,31 @@ Below we'll take their corresponding indices and add them.
|
||||
|
||||
# --hints--
|
||||
|
||||
`pairwise([1, 4, 2, 3, 0, 5], 7)` should return 11.
|
||||
`pairwise([1, 4, 2, 3, 0, 5], 7)` dovrebbe restituire 11.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pairwise([1, 4, 2, 3, 0, 5], 7), 11);
|
||||
```
|
||||
|
||||
`pairwise([1, 3, 2, 4], 4)` should return 1.
|
||||
`pairwise([1, 3, 2, 4], 4)` dovrebbe restituire 1.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pairwise([1, 3, 2, 4], 4), 1);
|
||||
```
|
||||
|
||||
`pairwise([1, 1, 1], 2)` should return 1.
|
||||
`pairwise([1, 1, 1], 2)` dovrebbe restituire 1.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pairwise([1, 1, 1], 2), 1);
|
||||
```
|
||||
|
||||
`pairwise([0, 0, 0, 0, 1, 1], 1)` should return 10.
|
||||
`pairwise([0, 0, 0, 0, 1, 1], 1)` dovrebbe restituire 10.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pairwise([0, 0, 0, 0, 1, 1], 1), 10);
|
||||
```
|
||||
|
||||
`pairwise([], 100)` should return 0.
|
||||
`pairwise([], 100)` dovrebbe restituire 0.
|
||||
|
||||
```js
|
||||
assert.deepEqual(pairwise([], 100), 0);
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8257367417b2b2512c7b
|
||||
title: Add a New Element to a Binary Search Tree
|
||||
title: Aggiungere un nuovo elemento ad un albero binario di ricerca
|
||||
challengeType: 1
|
||||
forumTopicId: 301618
|
||||
dashedName: add-a-new-element-to-a-binary-search-tree
|
||||
@ -8,27 +8,27 @@ dashedName: add-a-new-element-to-a-binary-search-tree
|
||||
|
||||
# --description--
|
||||
|
||||
This series of challenges will introduce the tree data structure. Trees are an important and versatile data structure in computer science. Of course, their name comes from the fact that when visualized they look much like the trees we are familiar with in the natural world. A tree data structure begins with one node, typically referred to as the root, and from here branches out to additional nodes, each of which may have more child nodes, and so on and so forth. The data structure is usually visualized with the root node at the top; you can think of it as a natural tree flipped upside down.
|
||||
Questa serie di sfide introdurrà la struttura di dati ad albero. Gli alberi sono una struttura dati importante e versatile nell'informatica. Naturalmente, il loro nome deriva dal fatto che quando visualizzati assomigliano molto agli alberi con cui abbiamo familiarità nel mondo naturale. Una struttura di dati ad albero inizia con un nodo, tipicamente indicato come la radice, e da qui si dirama in nodi aggiuntivi, ciascuno dei quali può avere più nodi figli, e così via. La struttura dei dati viene solitamente visualizzata con il nodo radice in alto; lo si può pensare come un albero naturale capovolto verso il basso.
|
||||
|
||||
First, let's describe some common terminology we will encounter with trees. The root node is the top of the tree. Data points in the tree are called nodes. Nodes with branches leading to other nodes are referred to as the parent of the node the branch leads to (the child). Other more complicated familial terms apply as you might expect. A subtree refers to all the descendants of a particular node, branches may be referred to as edges, and leaf nodes are nodes at the end of the tree that have no children. Finally, note that trees are inherently recursive data structures. That is, any children of a node are parents of their own subtree, and so on. The recursive nature of trees is important to understand when designing algorithms for common tree operations.
|
||||
In primo luogo, descriviamo un po' di terminologia comune che incontreremo con gli alberi. Il nodo radice è la parte superiore dell'albero. I punti dati dell'albero sono chiamati nodi. I nodi con rami che conducono ad altri nodi sono indicati come il genitore del nodo al quale il ramo conduce (il figlio). Altri termini familiari più complicati si applicano come ci si potrebbe aspettare. Un sottoalbero si riferisce a tutti i discendenti di un particolare nodo, dei rami possono essere denominati bordi, e i nodi foglie sono i nodi alla fine dell'albero e che non hanno figli. Infine, nota che gli alberi sono intrinsecamente strutture di dati ricorsive. Cioè, tutti i figli di un nodo sono genitori del proprio sottalbero, e così via. La natura ricorsiva degli alberi è importante da capire quando si progettano algoritmi per le operazioni comuni sugli alberi.
|
||||
|
||||
To begin, we will discuss a particular type of a tree, the binary tree. In fact, we will actually discuss a particular binary tree, a binary search tree. Let's describe what this means. While the tree data structure can have any number of branches at a single node, a binary tree can only have two branches for every node. Furthermore, a binary search tree is ordered with respect to the child subtrees, such that the value of each node in the left subtree is less than or equal to the value of the parent node, and the value of each node in the right subtree is greater than or equal to the value of the parent node. It's very helpful to visualize this relationship in order to understand it better:
|
||||
Per cominciare, discuteremo un particolare tipo di albero, l'albero binario. Infatti, in realtà discuteremo di un particolare albero binario, un albero binario di ricerca. Vediamo cosa significa. Mentre la struttura dei dati ad albero può avere un numero qualsiasi di rami in un unico nodo, un albero binario può avere solo due rami per ogni nodo. Inoltre, un albero binario di ricerca è ordinato rispetto ai sotto-alberi figli, in modo che il valore di ogni nodo nel sottoalbero sinistro sia inferiore o uguale al valore del nodo genitore, e il valore di ogni nodo nel sottoalbero destro sia maggiore o uguale al valore del nodo genitore. È molto utile visualizzare questa relazione per comprenderla meglio:
|
||||
|
||||
<div style='width: 100%; display: flex; justify-content: center; align-items: center;'><img style='width: 100%; max-width: 350px; background-color: var(--gray-05);' src='https://user-images.githubusercontent.com/18563015/32136009-1e665d98-bbd6-11e7-9133-63184f9f9182.png'></div>
|
||||
|
||||
Now this ordered relationship is very easy to see. Note that every value to the left of 8, the root node, is less than 8, and every value to the right is greater than 8. Also notice that this relationship applies to each of the subtrees as well. For example, the first left child is a subtree. 3 is the parent node, and it has exactly two child nodes — by the rules governing binary search trees, we know without even looking that the left child of this node (and any of its children) will be less than 3, and the right child (and any of its children) will be greater than 3 (but also less than the structure's root value), and so on.
|
||||
Ora questo relazione di ordinamento è molto facile da vedere. Nota che ogni valore a sinistra di 8, il nodo radice, è inferiore a 8, e ogni valore a destra è maggiore di 8. Nota che questa relazione si applica anche a ciascuno dei sottoalberi. Per esempio, il primo figlio sinistro è un sottoalbero. 3 è il nodo padre, e ha esattamente due nodi figli — dalle regole che regolano gli alberi binari di ricerca, sappiamo senza nemmeno guardare che il figlio sinistro di questo nodo (e di tutti i suoi figli) sarà minore di 3, e il figlio destro (e qualsiasi dei suoi figli) sarà maggiore di 3 (ma anche minore del valore della radice della struttura), e così via.
|
||||
|
||||
Binary search trees are very common and useful data structures because they provide logarithmic time in the average case for several common operations such as lookup, insertion, and deletion.
|
||||
Gli alberi binari di ricerca sono strutture di dati molto comuni e utili perché nel caso medio forniscono tempo logaritmico per diverse operazioni comuni come la ricerca, l'inserimento, e la cancellazione.
|
||||
|
||||
# --instructions--
|
||||
|
||||
We'll start simple. We've defined the skeleton of a binary search tree structure here in addition to a function to create nodes for our tree. Observe that each node may have a left and right value. These will be assigned child subtrees if they exist. In our binary search tree, you will create a method to add new values to our binary search tree. The method should be called `add` and it should accept an integer value to add to the tree. Take care to maintain the invariant of a binary search tree: the value in each left child should be less than or equal to the parent value, and the value in each right child should be greater than or equal to the parent value. Here, let's make it so our tree cannot hold duplicate values. If we try to add a value that already exists, the method should return `null`. Otherwise, if the addition is successful, `undefined` should be returned.
|
||||
Cominceremo con qualcosa di semplice. Qui abbiamo definito lo scheletro di una struttura ad albero binario di ricerca oltre a una funzione per creare nodi per il nostro albero. Nota che ogni nodo può avere un valore sinistro e destro. A questi saranno assegnati sotto-alberi figli, se esistono. Nel nostro albero binario di ricerca, creerai un metodo per aggiungere nuovi valori. Il metodo dovrebbe essere chiamato `add` e dovrebbe accettare un valore intero da aggiungere all'albero. Fai attenzione a mantenere invariata la struttura di un albero binario di ricerca: il valore in ogni figlio sinistro dovrebbe essere inferiore o uguale al valore genitore, e il valore in ogni figlio destro dovrebbe essere maggiore o uguale al valore genitore. Ecco, facciamo in modo che il nostro albero non possa contenere valori duplicati. Se cerchiamo di aggiungere un valore che esiste già, il metodo dovrebbe restituire `null`. Altrimenti, se l'aggiunta è riuscita, dovrebbe essere restituito `undefined`.
|
||||
|
||||
**Hint:** trees are naturally recursive data structures!
|
||||
**Suggerimento:** gli alberi sono strutture dati ricorsive per natura!
|
||||
|
||||
# --hints--
|
||||
|
||||
The `BinarySearchTree` data structure should exist.
|
||||
La struttura di dati `BinarySearchTree` dovrebbe esistere.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -42,7 +42,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
The binary search tree should have a method called `add`.
|
||||
L'albero binario di ricerca dovrebbe avere un metodo chiamato `add`.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -58,7 +58,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
The add method should add elements according to the binary search tree rules.
|
||||
Il metodo di aggiunta dovrebbe aggiungere elementi secondo le regole dell'albero binario di ricerca.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -87,7 +87,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
Adding an element that already exists should return `null`.
|
||||
Aggiungere un elemento già esistente dovrebbe restituire `null`.
|
||||
|
||||
```js
|
||||
assert(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8256367417b2b2512c77
|
||||
title: Adjacency List
|
||||
title: Lista di adiacenza
|
||||
challengeType: 1
|
||||
forumTopicId: 301620
|
||||
dashedName: adjacency-list
|
||||
@ -8,11 +8,11 @@ dashedName: adjacency-list
|
||||
|
||||
# --description--
|
||||
|
||||
Graphs can be represented in different ways. Here we describe one way, which is called an <dfn>adjacency list</dfn>. An adjacency list is essentially a bulleted list where the left side is the node and the right side lists all the other nodes it's connected to. Below is a representation of an adjacency list.
|
||||
I grafici possono essere rappresentati in modi diversi. Qui descriviamo un modo, che è chiamato una <dfn>lista di adiacenza</dfn>. Una lista di adiacenza è essenzialmente un elenco puntato dove il lato sinistro è il nodo e il lato destro elenca tutti gli altri nodi a cui è collegato. Di seguito è riportata una rappresentazione di una lista di adiacenza.
|
||||
|
||||
<blockquote>Node1: Node2, Node3<br>Node2: Node1<br>Node3: Node1</blockquote>
|
||||
|
||||
Above is an undirected graph because `Node1` is connected to `Node2` and `Node3`, and that information is consistent with the connections `Node2` and `Node3` show. An adjacency list for a directed graph would mean each row of the list shows direction. If the above was directed, then `Node2: Node1` would mean there the directed edge is pointing from `Node2` towards `Node1`. We can represent the undirected graph above as an adjacency list by putting it within a JavaScript object.
|
||||
Quello sopra è un grafico non orientato perché `Node1` è connesso a `Node2` e `Node3`, e tali informazioni sono coerenti con le connessioni `Node2` e `Node3`. La lista di adiacenza per un grafico orientato significherebbe che ogni riga della lista mostra la direzione. Se quanto sopra fosse orientato, allora `Node2: Node1` significherebbe che l'arco orientato sta puntando da `Node2` verso `Node1`. Possiamo rappresentare il grafo non orientato qui sopra come una lista di adiacenza inserendolo in un oggetto JavaScript.
|
||||
|
||||
```js
|
||||
var undirectedG = {
|
||||
@ -22,7 +22,7 @@ var undirectedG = {
|
||||
};
|
||||
```
|
||||
|
||||
This can also be more simply represented as an array where the nodes just have numbers rather than string labels.
|
||||
Questo può anche essere rappresentato più semplicemente come un array in cui i nodi hanno solo numeri invece di etichette di stringa.
|
||||
|
||||
```js
|
||||
var undirectedGArr = [
|
||||
@ -34,17 +34,17 @@ var undirectedGArr = [
|
||||
|
||||
# --instructions--
|
||||
|
||||
Create a social network as an undirected graph with 4 nodes/people named `James`, `Jill`, `Jenny`, and `Jeff`. There are edges/relationships between James and Jeff, Jill and Jenny, and Jeff and Jenny.
|
||||
Crea un social network come grafo non orientato con 4 nodi/persone di nome `James`, `Jill`, `Jenny`, e `Jeff`. Ci sono lati/rapporti tra James e Jeff, Jill e Jenny, e Jeff e Jenny.
|
||||
|
||||
# --hints--
|
||||
|
||||
`undirectedAdjList` should only contain four nodes.
|
||||
`undirectedAdjList` dovrebbe contenere solo quattro nodi.
|
||||
|
||||
```js
|
||||
assert(Object.keys(undirectedAdjList).length === 4);
|
||||
```
|
||||
|
||||
There should be an edge between `Jeff` and `James`.
|
||||
Ci dovrebbe essere un arco tra `Jeff` e `James`.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -53,7 +53,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
There should be an edge between `Jill` and `Jenny`.
|
||||
Ci dovrebbe essere un arco tra `Jill` e `Jenny`.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -62,7 +62,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
There should be an edge between `Jeff` and `Jenny`.
|
||||
Dovrebbe esserci un arco tra `Jeff` e `Jenny`.
|
||||
|
||||
```js
|
||||
assert(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8257367417b2b2512c7c
|
||||
title: Check if an Element is Present in a Binary Search Tree
|
||||
title: Controllare se un elemento è presente in un albero binario di ricerca
|
||||
challengeType: 1
|
||||
forumTopicId: 301623
|
||||
dashedName: check-if-an-element-is-present-in-a-binary-search-tree
|
||||
@ -8,15 +8,15 @@ dashedName: check-if-an-element-is-present-in-a-binary-search-tree
|
||||
|
||||
# --description--
|
||||
|
||||
Now that we have a general sense of what a binary search tree is let's talk about it in a little more detail. Binary search trees provide logarithmic time for the common operations of lookup, insertion, and deletion in the average case, and linear time in the worst case. Why is this? Each of those basic operations requires us to find an item in the tree (or in the case of insertion to find where it should go) and because of the tree structure at each parent node we are branching left or right and effectively excluding half the size of the remaining tree. This makes the search proportional to the logarithm of the number of nodes in the tree, which creates logarithmic time for these operations in the average case. Ok, but what about the worst case? Well, consider constructing a tree from the following values, adding them left to right: `10`, `12`, `17`, `25`. Following our rules for a binary search tree, we will add `12` to the right of `10`, `17` to the right of this, and `25` to the right of this. Now our tree resembles a linked list and traversing it to find `25` would require us to traverse all the items in linear fashion. Hence, linear time in the worst case. The problem here is that the tree is unbalanced. We'll look a little more into what this means in the following challenges.
|
||||
Ora che abbiamo un senso generale di cosa è un albero binario di ricerca, parliamo di esso in maggiore dettaglio. Gli alberi binari di ricerca richiedono un tempo logaritmico per le operazioni comuni di ricerca, inserimento, e cancellazione nel caso medio, e tempo lineare nel caso peggiore. Perché? Ognuna di queste operazioni di base ci richiede di trovare un elemento nell'albero (o nel caso di inserimento per trovare dove dovrebbe andare) e a causa della struttura ad albero ad ogni nodo genitore ci dirigiamo o a sinistra o a destra escludendo efficacemente metà della dimensione dell'albero rimanente. Questo rende la ricerca proporzionale al logaritmo del numero di nodi nell'albero, che nel caso medio dà un tempo logaritmico per queste operazioni. Ok, ma nel caso peggiore? Bene, immagina di costruire un albero con i seguenti valori, aggiungendoli da sinistra a destra: `10`, `12`, `17`, `25`. Seguendo le nostre regole per un albero di ricerca binario, aggiungeremo `12` alla destra di `10`, `17` a destra di questo, e `25` a destra di questo. Ora il nostro albero assomiglia a una lista collegata e attraversarlo per trovare `25` ci richiederebbe di attraversare tutti gli oggetti in modo lineare. Quindi, tempo lineare nel caso peggiore. Il problema qui è che l'albero non è bilanciato. Esamineremo un po' di più il significato di questo nelle seguenti sfide.
|
||||
|
||||
# --instructions--
|
||||
|
||||
In this challenge, we will create a utility for our tree. Write a method `isPresent` which takes an integer value as input and returns a boolean value for the presence or absence of that value in the binary search tree.
|
||||
In questa sfida, creeremo un'utilità per il nostro albero. Scrivi un metodo `isPresent` che prende un valore intero come input e restituisce un valore booleano per la presenza o l'assenza di quel valore nell'albero binario di ricerca.
|
||||
|
||||
# --hints--
|
||||
|
||||
The `BinarySearchTree` data structure should exist.
|
||||
La struttura di dati `BinarySearchTree` dovrebbe esistere.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -30,7 +30,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
The binary search tree should have a method called `isPresent`.
|
||||
L'albero binario di ricerca dovrebbe avere un metodo chiamato `isPresent`.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -46,7 +46,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
The `isPresent` method should correctly check for the presence or absence of elements added to the tree.
|
||||
Il metodo `isPresent` dovrebbe controllare correttamente la presenza o l'assenza di elementi aggiunti all'albero.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -74,7 +74,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
`isPresent` should handle cases where the tree is empty.
|
||||
`isPresent` dovrebbe gestire i casi in cui l'albero è vuoto.
|
||||
|
||||
```js
|
||||
assert(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 5cc0c1b32479e176caf3b422
|
||||
title: Check if Tree is Binary Search Tree
|
||||
title: Controlla se l'albero è un albero binario di ricerca
|
||||
challengeType: 1
|
||||
forumTopicId: 301624
|
||||
dashedName: check-if-tree-is-binary-search-tree
|
||||
@ -8,17 +8,17 @@ dashedName: check-if-tree-is-binary-search-tree
|
||||
|
||||
# --description--
|
||||
|
||||
Since you already know what a binary search tree is, this challenge will establish how it is you can tell that a tree is a binary search tree or not.
|
||||
Dal momento che sai già cos'è un albero binario di ricerca, questa sfida stabilirà come è possibile stabilire se un albero è un albero binario di ricerca o no.
|
||||
|
||||
The main distinction of a binary search tree is that the nodes are ordered in an organized fashion. Nodes have at most 2 child nodes (placed to the right and/or left) based on if the child node's value is greater than or equal to (right) or less than (left) the parent node.
|
||||
Quello che contraddistingue un albero binario di ricerca è che i nodi sono ordinati in modo organizzato. I nodi hanno al massimo 2 nodi figli (posizionati a destra e/o a sinistra) in base al fatto che il valore del nodo figlio sia maggiore o uguale a (destra) o inferiore a (sinistra) quello del nodo principale.
|
||||
|
||||
# --instructions--
|
||||
|
||||
In this challenge, you will create a utility for your tree. Write a JavaScript method `isBinarySearchTree` which takes a tree as an input and returns a boolean value for whether the tree is a binary search tree or not. Use recursion whenever possible.
|
||||
In questa sfida, creerai un'utilità per il tuo albero. Scrivi un metodo JavaScript `isBinarySearchTree` che prende un albero come input e restituisce un valore booleano a seconda se l'albero è un albero binario di ricerca o no. Usa la ricorsione quando possibile.
|
||||
|
||||
# --hints--
|
||||
|
||||
Your Binary Search Tree should return true when checked with `isBinarySearchTree()`.
|
||||
Il tuo albero di ricerca binario dovrebbe restituire true quando controllato con `isBinarySearchTree()`.
|
||||
|
||||
```js
|
||||
assert(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8253367417b2b2512c6c
|
||||
title: Perform a Union on Two Sets
|
||||
title: Eseguire l'unione di due insiemi
|
||||
challengeType: 1
|
||||
forumTopicId: 301708
|
||||
dashedName: perform-a-union-on-two-sets
|
||||
@ -8,13 +8,13 @@ dashedName: perform-a-union-on-two-sets
|
||||
|
||||
# --description--
|
||||
|
||||
In this exercise we are going to perform a union on two sets of data. We will create a method on our `Set` data structure called `union`. This method should take another `Set` as an argument and return the `union` of the two sets, excluding any duplicate values.
|
||||
In questo esercizio eseguiremo l'unione di due serie di dati. Creeremo un metodo sulla nostra struttura dati `Set` chiamato `union`. Questo metodo dovrebbe prendere un altro `Set` come argomento e restituire l'`union` dei due insiemi, escludendo eventuali valori duplicati.
|
||||
|
||||
For example, if `setA = ['a','b','c']` and `setB = ['a','b','d','e']`, then the union of setA and setB is: `setA.union(setB) = ['a', 'b', 'c', 'd', 'e']`.
|
||||
Per esempio, se `setA = ['a','b','c']` e `setB = ['a','b','d','e']`, allora l'unione di setA e setB è: `setA.union(setB) = ['a', 'b', 'c', 'd', 'e']`.
|
||||
|
||||
# --hints--
|
||||
|
||||
Your `Set` class should have a `union` method.
|
||||
La tua classe `Set` dovrebbe avere un metodo `union`.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -25,7 +25,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
The union of a Set containing values ["a", "b", "c"] and a Set containing values ["c", "d"] should return a new Set containing values ["a", "b", "c", "d"].
|
||||
L'unione di un insieme contenente valori ["a", "b", "c"] e un insieme contenente valori ["c", "d"] dovrebbe restituire un nuovo Set contenente valori ["a", "b", "c", "d"].
|
||||
|
||||
```js
|
||||
assert(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d8254367417b2b2512c71
|
||||
title: Remove items from a set in ES6
|
||||
title: Rimuovi elementi da un insieme in ES6
|
||||
challengeType: 1
|
||||
forumTopicId: 301713
|
||||
dashedName: remove-items-from-a-set-in-es6
|
||||
@ -8,15 +8,15 @@ dashedName: remove-items-from-a-set-in-es6
|
||||
|
||||
# --description--
|
||||
|
||||
Let's practice removing items from an ES6 Set using the `delete` method.
|
||||
Esercitiamoci con la rimozione di elementi da un Set ES6 utilizzando il metodo `delete`.
|
||||
|
||||
First, create an ES6 Set:
|
||||
Per prima cosa, crea un Set ES6:
|
||||
|
||||
```js
|
||||
var set = new Set([1,2,3]);
|
||||
```
|
||||
|
||||
Now remove an item from your Set with the `delete` method.
|
||||
Ora rimuovi un elemento dal tuo Set con il metodo `delete`.
|
||||
|
||||
```js
|
||||
set.delete(1);
|
||||
@ -25,13 +25,13 @@ console.log([...set]) // should return [ 2, 3 ]
|
||||
|
||||
# --instructions--
|
||||
|
||||
Now, create a set with the integers 1, 2, 3, 4, & 5.
|
||||
Ora, crea un set con gli interi 1, 2, 3, 4 e 5.
|
||||
|
||||
Remove the values 2 and 5, and then return the set.
|
||||
Rimuovi i valori 2 e 5, quindi restituisci il set.
|
||||
|
||||
# --hints--
|
||||
|
||||
Your Set should contain the values 1, 3, & 4
|
||||
Il Set deve contenere i valori 1, 3 e 4
|
||||
|
||||
```js
|
||||
assert(
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
id: 587d825a367417b2b2512c88
|
||||
title: Reverse a Doubly Linked List
|
||||
title: Invertire una lista a doppio collegamento
|
||||
challengeType: 1
|
||||
forumTopicId: 301714
|
||||
dashedName: reverse-a-doubly-linked-list
|
||||
@ -8,11 +8,11 @@ dashedName: reverse-a-doubly-linked-list
|
||||
|
||||
# --description--
|
||||
|
||||
Let's create one more method for our doubly linked list called reverse which reverses the list in place. Once the method is executed the head should point to the previous tail and the tail should point to the previous head. Now, if we traverse the list from head to tail we should meet the nodes in a reverse order compared to the original list. Trying to reverse an empty list should return null.
|
||||
Creiamo un metodo in più per la nostra lista a doppio collegamento, chiamato reverse, che inverte la lista "in place" (NdT: cioè lavorando sulla lista stessa, senza crearne una copia). Una volta eseguito il metodo la testa dovrebbe puntare alla vecchia coda e la coda dovrebbe puntare alla vecchia testa. Ora, se attraversiamo la lista dalla testa alla coda dovremmo incontrare i nodi in ordine inverso rispetto alla lista originale. Tentare di invertire una lista vuota dovrebbe restituire null.
|
||||
|
||||
# --hints--
|
||||
|
||||
The DoublyLinkedList data structure should exist.
|
||||
La struttura dei dati DoublyLinkedList dovrebbe esistere.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -26,7 +26,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
The DoublyLinkedList should have a method called reverse.
|
||||
La lista DoublyLinkedList dovrebbe avere un metodo chiamato reverse.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -43,7 +43,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
Reversing an empty list should return null.
|
||||
Invertire una lista vuota dovrebbe restituire null.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -57,7 +57,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
The reverse method should reverse the list.
|
||||
Il metodo reverse dovrebbe invertire l'elenco.
|
||||
|
||||
```js
|
||||
assert(
|
||||
@ -77,7 +77,7 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
The next and previous references should be correctly maintained when a list is reversed.
|
||||
I riferimenti next e previous dovrebbero essere mantenuti correttamente quando un elenco è invertito.
|
||||
|
||||
```js
|
||||
assert(
|
||||
|
@ -25,7 +25,7 @@ addSum(3);
|
||||
|
||||
# --instructions--
|
||||
|
||||
Crie uma função `addFive` sem qualquer argumento. Essa função adiciona 5 à variável</code>sum`, mas o valor retornado é <code>undefined`.
|
||||
Crie uma função `addFive` sem qualquer argumento. Essa função adiciona 5 à variável`sum`, mas o valor retornado é `undefined`.
|
||||
|
||||
# --hints--
|
||||
|
||||
@ -35,7 +35,7 @@ Crie uma função `addFive` sem qualquer argumento. Essa função adiciona 5 à
|
||||
assert(typeof addFive === 'function');
|
||||
```
|
||||
|
||||
Uma vez que ambas as funções são executadas, a `soma` deve ser igual a `8`.
|
||||
Uma vez que ambas as funções são executadas, a `sum` deve ser igual a `8`.
|
||||
|
||||
```js
|
||||
assert(sum === 8);
|
||||
@ -47,12 +47,13 @@ Valor retornado de `addFive` deve ser `undefined`.
|
||||
assert(addFive() === undefined);
|
||||
```
|
||||
|
||||
Dentro da função `addFive`, você deve adicionar `5` à variável `sum<code>.</p>
|
||||
Dentro da função `addFive`, você deve adicionar `5` à variável `sum`.
|
||||
|
||||
<pre><code class="js">assert(
|
||||
```js
|
||||
assert(
|
||||
__helpers.removeWhiteSpace(addFive.toString()).match(/sum=sum\+5|sum\+=5/)
|
||||
);
|
||||
`</pre>
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
|
Reference in New Issue
Block a user