README.md 2.16 KB
Newer Older
Louis Maliyam's avatar
Louis Maliyam committed
1
# ForkJoin Practice
Louis Maliyam's avatar
Louis Maliyam committed
2

Louis Maliyam's avatar
Louis Maliyam committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
This project is for you to get some practice with parallel programming using ForkJoin. Clone the repo and try each exercise! We recommend going in this order:
- [LessThan7](src/main/java/LessThan7.java)
- [Parity](src/main/java/Parity.java)
- [PowMod](src/main/java/PowMod.java)
- [CountStrs](src/main/java/CountStrs.java)
- [SecondSmallest](src/main/java/SecondSmallest.java)

## LessThan7

```java
public static int lessThan7(int[] arr)
```

lessThan7 returns the number of elements in `arr` that are less than 7.

For example, if `arr` is `[21, 7, 6, 8, 17, 1]`, then `lessThan7(arr) == 2`.

Your code must have `O(n)` work, `O(lg(n))` span, where `n` is the length of `arr`.

## Parity

```java
public static boolean parity(int[] arr)
```

parity returns `true` if there are even number of even numbers and `false` otherwise.

For example, if `arr` is `[1, 7, 4, 3, 6]`, then `parity(arr) == true`. But, if `arr` is `[6, 5, 4, 3, 2, 1]`, `parity(arr) == false`.

Your code must have `O(n)` work, `O(lg(n))` span, where `n` is the length of `arr`.

## PowMod

```java
public static void powmod(int[] arr, int p, int m)
```

powMod replaces every element of `arr` with `arr[i]^p mod m`.

For example, if `arr` is `[1, 7, 4, 3, 6]`, then `powmod(arr, 2, 5)` would result in `arr = [1, 4, 1, 4, 1]`.

Your code must have `O(n)` work, `O(lg(n))` span, where `n` is the length of `arr`.

## CountStrs

```java
public static int countStrs(String str, String[] arr)
```

countStrs returns the number of elements in `arr` that equal `str`.

For example, if `arr` is `["h", "ee", "llll", "llll", "oo", "llll"]`, then `countStrs(arr, "llll") == 3` and `countStrs(arr, "h") == 1`.

Your code must have `O(n)` work, `O(lg(n))` span, where `n` is the length of `arr`.

## SecondSmallest

```java
 public static int secondSmallest(int[] arr)
```

secondSmallest returns the second smallest unique element of `arr`. Assume `arr` contains at least two unique elements.

For example, if `arr` is `[1, 7, 4, 3, 6]`, then `secondSmallest(arr) == 3`. But, if `arr` is `[6, 1, 4, 3, 5, 2, 1]`, `secondSmallest(arr) == 2`.

Your code must have `O(n)` work, `O(lg(n))` span, where `n` is the length of `arr`.