Exercise 8

Added Exercise 8 to repository
This commit is contained in:
2025-04-21 19:08:07 +02:00
parent c71d2e026f
commit 950098d35e
8 changed files with 432 additions and 11 deletions

View File

@@ -1,7 +1,9 @@
#+title: Task 1: Recursive function analysis
#+author: JirR02
/This task is a text based task. You do not need to write any program or C++ file: the answer should be written in main.md (and might include code fragments if questions ask for them)./
/This task is a text based task. You do not need to write any
program/C++ file: the answer should be written in main.md (and might
include code fragments if questions ask for them)./
* Task
:PROPERTIES:
@@ -50,22 +52,30 @@ g(n - 1);
// PRE: n is a positive integer
// POST: returns true if n is even and false if n is odd.
```
#+end_src
ii) The function =plain|f= terminates because it has a termination
2) [@2] The function =plain|f= terminates because it has a termination
condition. It will terminate once n reaches 0. If the number is
negative, it will be in an infinite loop.
iii) $\text{Calls}_{f}(n) = n$
3) \(\text{Calls}_{f}(n) = n\)
2. i) Pre- and post conditions
2. [@2]
1) Pre- and post conditions
```cpp
#+begin_src cpp
// PRE: n is a positive integer
// POST: print 2^n *
```
ii) The function =plain|g= terminates because it has a termination condition. It will terminate once n reaches 0. If the number is negative, it will be in an infinite loop.
iii) $\text{Calls}_{g}(n) = 2^n$
#+end_src
2) [@2] The function =plain|g= terminates because it has a termination
condition. It will terminate once n reaches 0. If the number is
negative, it will be in an infinite loop.
3) \(\text{Calls}_{g}(n) = 2^n\)
#+begin_example
___
Made by JirR02 in Switzerland 🇨🇭
#+end_example

View File

@@ -86,3 +86,7 @@ vec all_bitstrings_up_to_n(int n) {
return res;
}
#+end_src
--------------
Made by JirR02 in Switzerland 🇨🇭

View File

@@ -195,3 +195,7 @@ void print_hourglass(int base_width) {
print_trapezoid(base_width, base_width, 0, true);
print_trapezoid(base_width, base_width - 1, 0, false);
#+end_src
--------------
Made by JirR02 in Switzerland 🇨🇭

View File

@@ -99,3 +99,7 @@ int best_two_elements(const vec &values, const vec &weights, int weight_limit) {
return value;
}
#+end_src
--------------
Made by JirR02 in Switzerland 🇨🇭