Skip to content

Instantly share code, notes, and snippets.

View ahmedengu's full-sized avatar

Ahmed Aboumalwa ahmedengu

View GitHub Profile
@ahmedengu
ahmedengu / Main.java
Last active April 2, 2016 10:42
Best frist search
import javafx.util.Pair;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static int[][] cities = {
//0 1 2 3 4 5
{-1, 20, 30, -1, -1, -1},
@ahmedengu
ahmedengu / fork.c
Last active April 6, 2016 22:31
threads and fork example
#include <stdio.h>
int id;
int main() {
id = fork();
if (id == 0) {
printf("Child : Child ID: %d, Parent ID: %d\n", getpid(), getppid());
}
else {
@ahmedengu
ahmedengu / SchedulingProblem.java
Last active November 28, 2016 18:46
Design an efficient algorithm to solve the following scheduling problem. Provide a pseudocode and a worst case complexity analysis for your algorithm. You are given a set of n jobs with a processing time ti and a weight wi for each job. You want to order the jobs so as to minimize the weighted some of the completion times,   n i ii Cw 1 . Exam…
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
public class SchedulingProblem {
static Vector<Integer> processTime = new Vector<>();
static Vector<Integer> processWeight = new Vector<>();
static SortedMap<Integer, Double> timeWeightRatio = new TreeMap<Integer, Double>() {
};
@ahmedengu
ahmedengu / ChangeMaking.java
Last active April 12, 2016 22:00
Write the pseudocode of the greedy algorithm for the change-making problem, with an amount n and coin denominations d1, d2, …, dn as its input. What is the time efficiency class of your algorithm?
import java.util.Comparator;
import java.util.TreeSet;
public class ChangeMaking {
static TreeSet<Integer> coins = new TreeSet<>(Comparator.reverseOrder());
static int amount = 126;
public static void main(String[] args) {
coins.add(50);
coins.add(25);
@ahmedengu
ahmedengu / main.cpp
Last active April 13, 2016 09:48
read text and convert it to uppercase
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <ctype.h>
char inputString[100],uppercaseString[100];
sem_t len;
void *reader() {
printf("Enter first text:");
scanf("%s", inputString);
@ahmedengu
ahmedengu / main.cpp
Last active April 13, 2016 09:57
generate random char and convert it to uppercase
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <math.h>
#include <ctype.h>
int number = 10, buff = 0;
char queue[10];
sem_t full_sem, empty_sem;
@ahmedengu
ahmedengu / main.cpp
Created April 13, 2016 09:57
generate random text and convert it to uppercase
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <math.h>
#include <ctype.h>
int number = 10, buff = 0;
char queue[10][10];
sem_t full_sem, empty_sem;
@ahmedengu
ahmedengu / Huffman.java
Last active March 9, 2022 20:15
Huffman coding and decoding in java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeMap;
/* Huffman coding , decoding */
public class Huffman {
static final boolean readFromFile = false;
@ahmedengu
ahmedengu / GeneticOperators.java
Last active April 26, 2016 01:04
Sudoku Genetic Algorithm java
import java.util.Random;
public class GeneticOperators {
public static int[] initialize(int[] gene) {
int dimensions = (int) Math.sqrt(gene.length);
for (int i = 0; i < gene.length; i++) {
if (gene[i] == 0) gene[i] = new Random().nextInt(dimensions) + 1;
}
@ahmedengu
ahmedengu / CoinOfValues.java
Created April 26, 2016 20:19
Consider a country having monetary coins of values (2,3,7). a. Using dynamic programming, write an algorithm that finds the number of ways to construct an amount N. b. What is the complexity of your algorithm? c. Show the dynamic programming table for an input of N=10. For N=10 the solution is 3: (2,2,2,2,2) (2,2,3,3) (3,7).
public class CoinOfValues {
public static void main(String[] args) {
int number = 10;
int[] coins = {2, 3, 7};
int[][] dpMatrix = new int[coins.length + 1][number + 1];
for (int i = 0; i <= coins.length; i++)
dpMatrix[i][0] = 1;
for (int i = 1; i <= number; i++)
dpMatrix[0][i] = 0;