Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public MergeSortModel() {

private void buildOps(int l, int r) {
if (l >= r) return;
int m = (l + r) / 2;
int m = l + (r - l) / 2;
buildOps(l, m);
buildOps(m + 1, r);
ops.add(new int[] {l, m, r});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/data/algorithmCodeSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ function merge(L: number[], R: number[]): number[] {
code: `function binarySearch(arr: number[], target: number): number {
let lo = 0, hi = arr.length - 1;
while (lo <= hi) { // loop
const mid = Math.floor((lo + hi) / 2);
const mid = lo + Math.floor((hi - lo) / 2);
if (arr[mid] === target) return mid; // found!
if (arr[mid] < target) lo = mid + 1; // narrow right
else hi = mid - 1; // narrow left
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/data/gymChallenges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export const BUG_HUNT_CHALLENGES: BugHuntChallenge[] = [

while (low <= high) {
// 鈿狅笍 Bug line below:
const mid = Math.floor((low + high) / 2);
const mid = low + Math.floor((high - low) / 2);

if (arr[mid] === target) {
return mid;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/workers/simulationWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function simulateSingleSortingAlgorithm(
// MergeSort
function mergeSort(l: number, r: number) {
if (l < r) {
const m = Math.floor((l + r) / 2);
const m = l + Math.floor((r - l) / 2);
mergeSort(l, m);
mergeSort(m + 1, r);
merge(l, m, r);
Expand Down Expand Up @@ -535,7 +535,7 @@ function simulateSingleSearchingAlgorithm(
let right = arr.length - 1;

while (left <= right) {
const mid = Math.floor((left + right) / 2);
const mid = left + Math.floor((right - left) / 2);
comparisons++;
steps++;

Expand Down
Loading