Skip to content

Instantly share code, notes, and snippets.

View amrmusharrafa's full-sized avatar

Amr Musharrafa amrmusharrafa

View GitHub Profile
@amrmusharrafa
amrmusharrafa / BruteForceSearch.java
Created December 20, 2023 18:51
The BruteForceSearch program is designed to compare the performance of two search algorithms: Brute-Force Search and Binary Search. It loads data from two text files, "largeW.txt" and "largeT.txt," representing two arrays of integers. It then measures and compares the running time of the Brute-Force Search and Binary Search algorithms when searc…
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
public class BruteForceSearch {
public static void main(String[] args) {
// Load data from files
int[] whitelist = loadData("largeW.txt");
@amrmusharrafa
amrmusharrafa / DiceSimulation.java
Created December 19, 2023 21:57
The code simulates the throwing of two six-sided dice, calculates the exact probabilities for each sum through combinatorics, and compares these theoretical results with empirical outcomes obtained through simulation to determine the required sample size for convergence.
/*
* Dice Simulation
*
* Overview:
* This Java program simulates the throwing of two six-sided dice, calculates the exact
* probabilities for each sum, and compares them with empirical results obtained through simulation.
*
* Calculation of Exact Probabilities:
* The code calculates the exact probabilities for the sum of two dice using a nested loop
* that considers all possible combinations of two dice rolls. The results are stored in the 'dist' array.
@amrmusharrafa
amrmusharrafa / Random.java
Created December 19, 2023 19:16
This code demonstrates a simple randomization process for integers within an array. It achieves this without relying on external libraries, implementing the Fisher-Yates shuffle algorithm from scratch.
/* *****************************************************************************
* Name: Amr Musharrafa
* Last modified: December 19, 2023
**************************************************************************** */
public class Random {
public static void main(String[] args) {
int[] dataArray = new int[6];
fillArraySequentially(dataArray); // Call the method to fill the array
@amrmusharrafa
amrmusharrafa / matrix_spiral_copy.js
Created October 29, 2023 15:23
Matrix 2D Spiral copy
// A function that copies a 2D array in a spiral order
function spiralCopy(inputMatrix) {
// Initialize an empty array to store the result
let result = [];
// Define the boundaries of the matrix
let topRow = 0;
let bottomRow = inputMatrix.length - 1;
let leftCol = 0;