Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
fix: relace find_platforms for merge_sorted_array
Browse files Browse the repository at this point in the history
  • Loading branch information
storopoli committed Sep 21, 2024
1 parent 7a8db41 commit 0043c14
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
38 changes: 19 additions & 19 deletions slides/slides-pt.typ
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ Blank space can be filled with vertical spaces like #v(1fr).
grid(
columns: 2,
gutter: 2mm,
image("images/turing.jpg", width: 60%),
image("images/church.jpg", width: 60%),
image("images/turing.jpg", width: 60%), image("images/church.jpg", width: 60%),
),
caption: "Alan Turing e Alonzo Church",
)<turing-church>
Expand Down Expand Up @@ -1632,30 +1631,31 @@ proposicional pode ser tornada verdadeira* por meio de uma atribuição adequada

#pagebreak()

Dado os horários de chegada e partida de trens em uma estação, encontrar o
número mínimo de plataformas necessárias:
// Complexidade total: O(n log n)
Fundir duas _arrays_ ordeanadas:
// Complexidade total: O(N log N)
#text(size: 8pt)[
```c
int find_platforms(int arr[], int dep[], int n) {
sort(arr, arr + n);
sort(dep, dep + n);
int platforms = 1, result = 1;
int i = 1, j = 0;
void merge_sorted_arrays(int A[], int B[], int m, int n, int C[]) {
int i = 0, j = 0, k = 0;
int N = m + n; // N representa o tamanho combinado de A e B
while (i < n && j < n) {
if (arr[i] <= dep[j]) {
platforms++;
i++;
while (i < m && j < n) {
if (A[i] <= B[j]) {
C[k++] = A[i++];
} else {
platforms--;
j++;
C[k++] = B[j++];
}
result = max(result, platforms);
}
return result;
// Copia os elementos restantes de A, se houver
while (i < m) {
C[k++] = A[i++];
}
// Copia os elementos restantes de B, se houver
while (j < n) {
C[k++] = B[j++];
}
}
```
]
Expand Down
38 changes: 19 additions & 19 deletions slides/slides.typ
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ Blank space can be filled with vertical spaces like #v(1fr).
grid(
columns: 2,
gutter: 2mm,
image("images/turing.jpg", width: 60%),
image("images/church.jpg", width: 60%),
image("images/turing.jpg", width: 60%), image("images/church.jpg", width: 60%),
),
caption: "Alan Turing and Alonzo Church",
)<turing-church>
Expand Down Expand Up @@ -1627,30 +1626,31 @@ subtrees is at most 1.

#pagebreak()

Given the arrival and departure times of trains at a station, find the minimum
number of platforms required:
// Total complexity: O(n log n)
Merge two sorted arrays:
// Total complexity: O(N log N)
#text(size: 8pt)[
```c
int find_platforms(int arr[], int dep[], int n) {
sort(arr, arr + n);
sort(dep, dep + n);
int platforms = 1, result = 1;
int i = 1, j = 0;
void merge_sorted_arrays(int A[], int B[], int m, int n, int C[]) {
int i = 0, j = 0, k = 0;
int N = m + n; // N is the combined length of A and B
while (i < n && j < n) {
if (arr[i] <= dep[j]) {
platforms++;
i++;
while (i < m && j < n) {
if (A[i] <= B[j]) {
C[k++] = A[i++];
} else {
platforms--;
j++;
C[k++] = B[j++];
}
result = max(result, platforms);
}
return result;
// Copy the remaining elements of A, if any
while (i < m) {
C[k++] = A[i++];
}
// Copy the remaining elements of B, if any
while (j < n) {
C[k++] = B[j++];
}
}
```
]
Expand Down

0 comments on commit 0043c14

Please sign in to comment.