957962665d
algorithms(avl): refactor code
...
Signed-off-by: Matej Focko <me@mfocko.xyz>
diff --git a/static/files/algorithms/rb-trees/avl/src/AVL.cs b/static/files/algorithms/rb-trees/avl/src/AVL.cs
index 757d8d4..9b3e35e 100644
--- a/static/files/algorithms/rb-trees/avl/src/AVL.cs
+++ b/static/files/algorithms/rb-trees/avl/src/AVL.cs
@@ -12,32 +12,29 @@ class AVL<T>(IComparer<T> comparator) : IEnumerable<T> {
#region AVLSpecific
- private static (bool correct, int depth) Check(Node<T>? node, int depth) {
+ private static (bool Correct, int Depth) Check(Node<T>? node, int depth) {
if (node == null) {
return (true, depth);
}
- var (leftCorrect, leftDepth) = Check(node.Left, 1 + depth);
- if (!leftCorrect) {
- return (false, leftDepth);
+ var left = Check(node.Left, 1 + depth);
+ if (!left.Correct) {
+ return (false, left.Depth);
}
- var (rightCorrect, rightDepth) = Check(node.Right, 1 + depth);
+ var right = Check(node.Right, 1 + depth);
- var foundDepth = Math.Max(leftDepth, rightDepth);
- return (rightCorrect && Math.Abs(leftDepth - rightDepth) <= 1, foundDepth);
+ var foundDepth = Math.Max(left.Depth, right.Depth);
+ return (right.Correct && Math.Abs(left.Depth - right.Depth) <= 1, foundDepth);
}
- public bool IsCorrect() {
- var (correct, _) = Check(_root, 0);
- return correct;
- }
+ public bool IsCorrect() => Check(_root, 0).Correct;
- private void InsertRebalance(List<Node<T>> nodes) {
+ private void InsertRebalance(List<Node<T>> nodes, T item) {
// TODO
}
- private void DeleteRebalance(List<Node<T>> nodes) {
+ private void DeleteRebalance(List<Node<T>> nodes, T item) {
// TODO
}
@@ -79,10 +76,9 @@ class AVL<T>(IComparer<T> comparator) : IEnumerable<T> {
} else {
path[lastIdx].Left = newItem;
}
- path.Add(newItem);
// rebalance
- InsertRebalance(path);
+ InsertRebalance(path, item);
return true;
}
2024-02-04 13:58:41 +01:00
aa6f33feb5
algorithms(avl): add changes
...
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-02-04 13:58:41 +01:00
f46561653f
algorithms(avl): add WIP
...
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-02-04 13:58:41 +01:00
4ab2615a05
cpp(placeholders): fix the static analysis
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-01-06 21:12:33 +01:00
2cf4a3efba
chore: run pre-commit
...
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 19:38:35 +01:00
2d7ba03369
algorithms(bf-to-astar): add A*
...
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:09:41 +01:00
21aeeeb042
algorithms(bf-to-astar): factor out the heap and dirs
...
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:08:54 +01:00
5164a31ce2
algorithms(bf-to-astar): add Dijkstra
...
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:07:54 +01:00
b048c6dc4f
algorithms(bf-to-astar): add headers to satisfy compilation
...
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:07:53 +01:00
858a96722b
algorithms(bf-to-astar): add BF
...
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:07:52 +01:00
d16eaafd97
algorithms(bf-to-astar): add intro
...
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:06:12 +01:00
2794519506
feat(algorithms): add Breaking of the Hash Table
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-28 17:23:44 +01:00
311ebacf84
feat(cpp): add placeholders
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-24 18:27:59 +01:00
61d00c708e
fix(c): add missing images
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-24 16:34:15 +01:00
e1dea0cdbc
feat: don't reference FI MU subjects by their codes
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-24 16:30:23 +01:00
a868efaee6
chore: switch to ‹tar› and have consistent paths
...
* Switch the archiving from the ‹zip› to ‹tar.gz› and ‹tar.bz2›
* Adjust the static files to have consistent paths
Signed-off-by: Matej Focko <me@mfocko.xyz>
2023-08-18 12:19:47 +02:00
84b080e343
ib002(recursion): add “Pyramid Slide Down”
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-08-17 00:14:48 +02:00
efc60e98d7
ib002(rb-trees): add “discourse” on the rules
...
Signed-off-by: Matej Focko <xfocko@fi.muni.cz>
2023-06-10 18:04:33 +02:00
7ed3cd3298
blog(leetcode): add matrix sort
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-03-04 23:13:20 +01:00
acdbce0d0c
fix(pb161): update gitignore
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-02-18 00:32:49 +01:00
ab6868fa45
chore: add gitkeep for IB111 static files
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-02-04 18:07:53 +01:00
fa0ff486a3
chore(ib002,ib111): use consistent naming
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2022-11-29 18:04:49 +01:00
e71fcfdf4f
feat(ib002,ib111): add backtracking exercise
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2022-11-29 15:21:48 +01:00
9f9dc39a31
chore: do not keep SVGs in the repository
...
• Do not keep the SVG files in the repository, generate them just for
the builds
• Also generate ZIP files with sources for downloading
Signed-off-by: Matej Focko <mfocko@redhat.com>
2022-11-24 17:25:30 +01:00
7efd5e294b
chore: use Iosevka as a default font
...
• Use Iosevka as a default font (with few reasonable fallbacks)
• Introduce a „steam machine“ for regenerating graphviz files
· Use same monospace fonts for graphviz too
Signed-off-by: Matej Focko <mfocko@redhat.com>
2022-11-18 11:57:56 +01:00
7427475022
chore: transfer all KBs to single one
...
Signed-off-by: Matej Focko <mfocko@redhat.com>
2022-11-05 15:25:15 +01:00