2025 init

This commit is contained in:
Romain Lefeuvre
2025-11-18 14:44:07 +01:00
commit ac81d61d01
21 changed files with 986 additions and 0 deletions

37
exercises/heap.md Normal file
View File

@@ -0,0 +1,37 @@
# Testing the heap property
A [*binary heap*](https://en.wikipedia.org/wiki/Binary_heap) is a data structure that contains comparable objects and it is able to efficiently return the lowest element.
This data structure relies on a binary tree to keep the insertion and deletion operations efficient. It is the base of the [*Heapsort* algorithm](https://en.wikipedia.org/wiki/Heapsort).
Implement a `BinaryHeap` class with the following interface:
```java
class BinaryHeap<T> {
public BinaryHeap(Comparator<T> comparator) { ... }
public T pop() { ... }
public T peek() { ... }
public void push(T element) { ... }
public int count() { ... }
}
```
A `BinaryHeap` instance is created using a `Comparator` object that represents the ordering criterion between the objects in the heap.
`pop` returns and removes the minimum object in the heap. If the heap is empty it throws a `NotSuchElementException`.
`peek` similar to `pop`, returns the minimum object but it does not remove it from the `BinaryHeap`.
`push` adds an element to the `BinaryHeap`.
`count` returns the number of elements in the `BinaryHeap`.
With the help of [jqwik](https://jqwik.net/) create a test that generates random inputs for your heap and ensures that the element returned by `pop` every time it is invoked is the minimum of the remaining elements in the heap.
**NOTE:**
- Do not use any existing implementation, write your own code.
- Use the provided project template as a starting point.
- In the project you can launch the tests with `mvn test`.
- You may reuse your binary heap code from the previous practical assignment.

View File

@@ -0,0 +1,49 @@
# Roman numerals
Any natural number between 0 and 3999 can be represented in *roman numerals* using the following rules:
1. Only symbols *M*, *D*, *C*, *X*, *V*, *I* can be used. Their values are shown below:
| M | D | C | L | X | V | I |
|------|-----|-----|----|----|---|---|
| 1000 | 500 | 100 | 50 | 10 | 5 | 1 |
2. Symbols M, C, X, I can be repeated consecutively up to three times.
3. Symbols D, L and V can not be repeated.
4. When a symbol of lower value of appears to the right of a symbol of equal or higher value, all symbol values are added.
5. When a symbols of lower value appears to the left of a symbols of higher value, the lower value is subtracted from the higher value. Only symbols C, X, V can be subtracted. Each symbol can be subtracted only once. The subtracted symbol must be one fifth or one tenth of the larger.
*Examples:*
- 1 = I
- 4 = IV
- 8 = VIII
- 9 = IX
- 14 = XIV
- 16 = XVI
- 19 = XIX
- 99 = XCIX
- 105 = CV
- 1001 = MI
- 2289 = MMCCLXXXIX
Implement the following methods in the `RomanNumeralUtils` class:
```java
class RomanNumeralUtils {
public static boolean isValidRomanNumeral(String value) { ... }
public static int parseRomanNumeral(String numeral) { ... }
public static String toRomanNumeral(int number) { ... }
}
```
Use [jqwik](https://jqwik.net/) to create property based tests verifying these three methods. Create the tests before implementing the methods. Document any bugs you found with the help of these tests during the process.
**NOTE:**
- Do not use any existing implementation, write your own code.
- Use the provided project template as a starting point.
- In the project you can launch the tests with `mvn test`.

23
exercises/sorting.md Normal file
View File

@@ -0,0 +1,23 @@
# Sorting algorithms
Implement [Bubble sort](https://en.wikipedia.org/wiki/Bubble_sort), [Quicksort](https://en.wikipedia.org/wiki/Quicksort) and [Merge sort](https://en.wikipedia.org/wiki/Merge_sort) in the `Sorting` class as indicated below. The three methods return a sorted version of the original array. The comparison between the elements of the arrays is specified with an instance of `Comparator`.
```java
class Sorting {
public static T[] bubblesort(T[] array, Comparator<T> comparator) { ... }
public static T[] quicksort(T[] array, Comparator<T> comparator) { ... }
public static T[] mergesort(T[] array, Comparator<T> comparator) { ... }
}
```
Using [jqwik](https://jqwik.net/) create a differential fuzzing strategy to test the three sorting algorithms at the same time. Create the test before any sorting implementation. Document any bug you find with the help of your tests.
**NOTE:**
- Do not use any existing implementation, write your own code.
- Use the provided project template as a starting point.
- In the project you can launch the tests with `mvn test`.