You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A **binary tree** is a hierarchical **data structure** in which each **node** has a **value** (in this case, it is also a key) and **links** to the **left** and **right****children**. The **node** that is at the topmost level (which is not someone else's child) is called the **root**. **Nodes** that have no children are called **leaves**.
283
-
284
-
A **binary search tree** is a **binary tree** with additional properties: the value of the **left** child is **less** than the value of the parent, and the value of the **right** child is **greater** than the value of the parent for each tree **node**. That is, the data in the binary search tree is stored sorted. Each time you **add** a new or **remove** an existing node, the sorted order of the tree is preserved. When **searching** for an element, the search value is compared with the root. If the desired is **greater** than the root, then the search continues in the **right** child of the root, if **less**, then in the **left**, if **equal**, then the value is **found** and the search stops.
285
-
286
-
Your task is to implement the class `BinarySearchTree`.
287
-
Each instance of `BinarySearchTree` must have following methods:
288
-
*`root` — return **root node** of the tree
289
-
*`add(data)` — add **node** with `data` to the tree
290
-
*`has(data)` — returns `true` if **node** with the `data` exists in the tree and `false` otherwise
291
-
*`find(data)` — returns **node** with the `data` if **node** with the `data` exists in the tree and `null` otherwise
292
-
*`remove(data)` — removes **node** with the `data` from the tree if **node** with the `data` exists
293
-
*`min` — returns **minimal****value** stored in the tree (or `null` if tree has no **nodes**)
294
-
*`max` — returns **maximal****value** stored in the tree (or `null` if tree has no **nodes**)
295
-
296
-
For example:
297
-
298
-
`const tree = new BinarySearchTree();`
299
-
300
-
`tree.add(1);`
301
-
302
-
`tree.add(2);`
303
-
304
-
`tree.add(3);`
305
-
306
-
`tree.add(4);`
307
-
308
-
`tree.add(5);`
309
-
310
-
`tree.root().data` => `1;`
311
-
312
-
`tree.min()` => `1`
313
-
314
-
`tree.max()` => `5`
315
-
316
-
`tree.remove(5);`
317
-
318
-
`tree.has(5)` => `false`
319
-
320
-
`tree.max()` => `4`
321
-
322
-
Write your code in `src/binary-search-tree.js`.
323
-
324
-
---
325
-
326
279
### **(ST) Common character count**
327
280
Your task is to implement function that accepts two **strings** (`s1` and `s2`) and returns **number** of common characters between them.
328
281
@@ -446,25 +399,6 @@ Write your code in `src/st-mine-sweeper.js`.
446
399
447
400
---
448
401
449
-
### **(ST) Remove from list**
450
-
Given a **singly linked list** of integers `l` and an integer `k`, remove all elements from list `l` that have a value equal to `k`.
451
-
452
-
For example, for `l` = `[3, 1, 2, 3, 4, 5]` and `k` = `3`,
453
-
the output should be `[1, 2, 4, 5]`
454
-
455
-
**Singly linked lists** are already defined with this interface
456
-
457
-
```js
458
-
functionListNode(x) {
459
-
this.value= x;
460
-
this.next=null;
461
-
}
462
-
```
463
-
464
-
Write your code in `src/st-remove-from-list.js`.
465
-
466
-
---
467
-
468
402
### **(ST) Sort by height**
469
403
Given an array with heights, sort them except if the value is `-1`.
470
404
Your task is to implement function that accepts **array** (`arr`) and returns it **sorted**
@@ -477,24 +411,6 @@ Write your code in `src/st-sort-by-height.js`.
477
411
478
412
---
479
413
480
-
### **(ST) Stack**
481
-
Implement the **Stack** with a given interface via **array**.
482
-
483
-
For example:
484
-
485
-
```js
486
-
conststack=newStack();
487
-
488
-
stack.push(1); // adds the element to the stack
489
-
stack.peek(); // returns the peek, but doesn't delete it, returns 1
490
-
stack.pop(); // returns the top element from stack and deletes it, returns 1
491
-
stack.pop(); // undefined
492
-
```
493
-
494
-
Write your code in `src/st-stack.js`.
495
-
496
-
---
497
-
498
414
### **(ST) Sum digits**
499
415
Your task is to implement function that accepts a **number** (`n`) and returns the **sum of its digits** until we get to a **one digit number**.
500
416
@@ -509,29 +425,6 @@ Write your code in `src/st-sum-digits.js`.
509
425
510
426
---
511
427
512
-
### **(ST) Queue**
513
-
Implement the **Queue** with a given interface via **linked list** (use `ListNode` extension).
514
-
Each instance of queue must have 3 methods:
515
-
* `enqueue(value)` — puts the `value` at the end of the **queue**
516
-
* `deque` — retrieves a value from the head of the **queue** and deletes it
**Бинарное дерево** — это иерархическая **структура данных**, в которой каждый **узел** имеет **значение** (оно же является в данном случае и ключом) и **ссылки** на **левого** и **правого****потомка**. **Узел**, находящийся на самом верхнем уровне (не являющийся чьим либо потомком) называется **корнем**. **Узлы**, не имеющие потомков, называются **листьями**.
282
-
283
-
284
-
**Бинарное дерево поиска** — это **бинарное дерево**, обладающее дополнительными свойствами: значение **левого** потомка **меньше** значения родителя, а значение **правого** потомка **больше** значения родителя для каждого **узла** дерева. То есть, данные в бинарном дереве поиска хранятся в отсортированном виде. При каждой операции **вставки** нового или **удаления** существующего узла отсортированный порядок дерева сохраняется. При **поиске** элемента сравнивается искомое значение с корнем. Если искомое **больше** корня, то поиск продолжается в **правом** потомке корня, если **меньше**, то в **левом**, если **равно**, то значение **найдено** и поиск прекращается.
285
-
286
-
Ваша задача — реализовать класс `BinarySearchTree`.
287
-
Каждый экземпляр `BinarySearchTree` должен обладать следующими методами:
288
-
*`root` — возвращает **корневой узел** дерева
289
-
*`add(data)` — добавляет **узел** с `data` к дереву
290
-
*`has(data)` — возвращает `true`, если **узел** с `data` имеется в дереве и `false`, если нет
291
-
*`find(data)` — возвращает **узел** с `data`, если **узел** с `data` имеется в дереве и `null`, если нет
292
-
*`remove(data)` — удаляет **узел** с `data` из дерева, если **узел** с `data` имеется в дереве
293
-
*`min` — возвращает **минимальное****значение**, хранящееся в дереве (или `null`, если у дерева нет **узлов**)
294
-
*`max` — возвращает **максимальное****значение**, хранящееся в дереве (или `null`, если у дерева нет **узлов**)
295
-
296
-
Например:
297
-
298
-
`const tree = new BinarySearchTree();`
299
-
300
-
`tree.add(1);`
301
-
302
-
`tree.add(2);`
303
-
304
-
`tree.add(3);`
305
-
306
-
`tree.add(4);`
307
-
308
-
`tree.add(5);`
309
-
310
-
`tree.root().data` => `1;`
311
-
312
-
`tree.min()` => `1`
313
-
314
-
`tree.max()` => `5`
315
-
316
-
`tree.remove(5);`
317
-
318
-
`tree.has(5)` => `false`
319
-
320
-
`tree.max()` => `4`
321
-
322
-
Напишите свой код в `src/binary-search-tree.js`.
323
-
324
-
---
325
-
326
278
### **(ST) Сосчитать общие символы**
327
279
Ваша задача — реализовать функцию, которая принимает 2 **строки** (`s1` и `s2`) и возвращает **число** их общих символов.
328
280
@@ -446,25 +398,6 @@ minesweeper(matrix) => [
446
398
447
399
---
448
400
449
-
### **(ST) Удалить из списка**
450
-
Дан **односвязный связный список** целых чисел (`l`) и целое число (`k`), удалите все элементы из списка `l`, содержащие значение `k`.
451
-
452
-
Например, для `l` = `[3, 1, 2, 3, 4, 5]` и `k` = `3`,
0 commit comments