Skip to content

Instantly share code, notes, and snippets.

View ahmedengu's full-sized avatar

Ahmed Aboumalwa ahmedengu

View GitHub Profile
@ahmedengu
ahmedengu / LCS.java
Last active April 26, 2016 21:28
Consider the Longest Common Subsequence (LCS) problem. You are given two strings A and B and you are to return the longest common subsequence in A and B. A subsequence of a string is defined to be the initial string with 0 or more characters removed. For example if A=”MOHAMED”, B=”AHMED”, the length of the LCS of A and B is 4 ( “HMED” or “AMED” …
public class LCS {
public static void main(String[] args) {
String mohamed = "MOHAMED";
String ahmed = "AHMED";
int dpMatrix[][] = new int[mohamed.length() + 1][ahmed.length() + 1];
for (int i = 0; i <= mohamed.length(); i++)
for (int j = 0; j <= ahmed.length(); j++)
if (i == 0 || j == 0)
dpMatrix[i][j] = 0;
@ahmedengu
ahmedengu / sort.sh
Created May 18, 2016 08:51
bash sorting script
#!/bin/sh
read -p "enter n " n
declare -a ARR
for (( c=0; c<$n; c++ ))
do
read -p "enter " ARR[$c]
done
@ahmedengu
ahmedengu / 2producer1consumer.cpp
Last active April 2, 2017 12:55
2 producer 1 consumer semaphore
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <math.h>
#include <ctype.h>
#define NUM 15
int number = NUM, buff = 0;
char queue[NUM][NUM];
sem_t full_sem, empty_sem;
@ahmedengu
ahmedengu / 2producer1consumer.cpp
Last active May 29, 2016 15:06
2 producer 1 consumer // it cause dead lock
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <math.h>
#include <ctype.h>
#define NUM 15
int number = NUM, buff = 0;
char queue[NUM][NUM];
sem_t full_sem, empty_sem;
@ahmedengu
ahmedengu / 2producer2consumer.cpp
Last active May 18, 2016 10:15
2 producer 2 consumer reading same values
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <math.h>
#include <ctype.h>
#define NUM 15
int number = NUM, buff = 0,buff2 = 0;
char queue[NUM][NUM],queue2[NUM][NUM];
@ahmedengu
ahmedengu / 2producer2consumer.cpp
Created May 18, 2016 10:16
2 producer 2 consumer reading different values
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <math.h>
#include <ctype.h>
#define NUM 15
int number = NUM, buff = 0;
char queue[NUM][NUM];
sem_t full_sem, empty_sem;
@ahmedengu
ahmedengu / 2producer1consumer.cpp
Created May 29, 2016 15:01
2 producer 1 consumer
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <math.h>
#include <ctype.h>
#define NUM 15
int number = NUM, buff = 0;
char queue[NUM][NUM];
sem_t full_sem, empty_sem;
@ahmedengu
ahmedengu / 2producer1consumer.cpp
Last active May 29, 2016 15:14
2 producer 1 consumer // Running here: http://ideone.com/N83BRQ
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <math.h>
#include <ctype.h>
#define NUM 15
int number = NUM, buff = 0;
char queue[NUM][NUM];
sem_t full_sem, empty_sem;
@ahmedengu
ahmedengu / 2producer2consumer.cpp
Created May 30, 2016 20:15
consumer wait for the buffer to be full , http://ideone.com/X2bxFu
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
char queueOfChars[10];
@ahmedengu
ahmedengu / 2producer2consumer.cpp
Created May 30, 2016 20:16
consumer will consume whenever there is something in the buffer , http://ideone.com/Lt8qCx
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
char q[10];