chore: remove unncessary paths

pull/229/head
Ming Tsai 2021-04-18 10:34:27 -04:00
parent 799b40b7e3
commit eef58b85d1
19 changed files with 17 additions and 689 deletions

View File

@ -1,7 +1,7 @@
# C++
## Arrays
1. [Count Inversions](Arrays/count_inversions.cpp)
1. [Counting Inversions](Arrays/counting-inversions.cpp)
2. [Dutch Flag Algorithm](Arrays/dutch-flag-algo.cpp)
3. [Left Rotation](Arrays/left-rotation.cpp)
4. [Max Subarray Sum](Arrays/max-subarray-sum.cpp)
@ -27,6 +27,7 @@
2. [Jump Search](Searching/jump-search.cpp)
3. [Binary Search](Searching/binary-search.cpp)
4. [Finding squareroot using Binary search](Searching/sqrt-monotonic-binary-search.cpp)
3. [KMP String Searching](Searching/kmp.cpp)
## Stacks
1. [Balancing Parenthesis](Stacks/balanced-parenthesis.cpp)
@ -36,7 +37,7 @@
2. [Insertion Sort](Sorting/insertion-sort.cpp)
3. [Quicksort](Sorting/quick-sort.cpp)
4. [Selection Sort](Sorting/selection-sort.cpp)
5. [3 way Quick Sort](Sorting/3way_quick_sort.cpp)
5. [3 way Quick Sort](Sorting/3way-quick-sort.cpp)
6. [Bucket Sort](Sorting/bucket-sort.cpp)
7. [Comb Sort](Sorting/comb-sort.cpp)
8. [Counting Sort](Sorting/counting-sort.cpp)

View File

@ -1,7 +1,7 @@
# Python
## Arrays
1. [Count Inversions](arrays/count_inversions.py)
1. [Count Inversions](arrays/counting_inversions.py)
## Linked Lists
1. [Doubly](linked_lists/doubly.py)

View File

@ -2,17 +2,7 @@
# Algorithms related to arrays
### C or C++
### C
1. [Counting Inversions](c-or-cpp/count-inversions.cpp)
2. [Dutch Flag Algo](c-or-cpp/dutch-flag-algo.cpp)
3. [Left Rotation of Array](c-or-cpp/left-rotation.cpp)
4. [Shift Negatives in Array](c-or-cpp/shift-negatives.cpp)
5. [Maximum Subarray Sum](c-or-cpp/max-subarray-sum.cpp)
6. [Unique Elements in an Array](c-or-cpp/unique-elements-in-an-array.c)
7. [Sorting arrays](c-or-cpp/array.cpp)
8. [Division of no.](c-or-cpp/division.cpp)
9. [Finding large no.](c-or-cpp/finding-large-number.cpp)
10. [Variable declaration](c-or-cpp/variable-declaration.cpp)
11. [Data before and after sorting](c-or-cpp/data-before-sort.cpp)
12. [Even and odd no. ](c-or-cpp/even-and-odd.c)
1. [Unique Elements in an Array](c-or-cpp/unique-elements-in-an-array.c)
2. [Even and odd no. ](c-or-cpp/even-and-odd.c)

View File

@ -1,8 +1,6 @@
# Graphs
### C or C++
### C
1. [Kruskal Algorithm](c-or-cpp/kruskal-algorithm.cpp)
2. [Bellman Ford Algorithm](c-or-cpp/bellman-ford.cpp)
3. [Prim's Algorithm](c-or-cpp/Prim's-algorithm.c)
1. [Prim's Algorithm](c-or-cpp/Prim's-algorithm.c)

View File

@ -1,11 +1,5 @@
# Linked Lists
### C or C++
### C
1. [Singly Linked List](c-or-cpp/singly.cpp)
2. [Reversing Linked List](c-or-cpp/reverse.cpp)
3. [Doubly Linked List](c-or-cpp/doubly.cpp)
4. [Circular Linked List](c-or-cpp/circular.cpp)
5. [Insertion Linked List](c-or-cpp/all-possible-insertion.cpp)
6. [Josephus Problem Using Circular Linked List](c-or-cpp/josephus-problem.c)
7. [Merge Two Singly linked List](c-or-cpp/merge.cpp)
1. [Josephus Problem Using Circular Linked List](c-or-cpp/josephus-problem.c)

View File

@ -1,9 +0,0 @@
# Multiplication algorithms
### C or C++
1. [Karatsuba Multiplication](c-or-cpp/karatsuba.cpp)
### Python
1. [Karatsuba Multiplication](python/karatsuba.py)

View File

@ -1,7 +1,5 @@
# Queues
### C or C++
### C
1. [Queue using linked list](c-or-cpp/queue-linked-list.cpp)
2. [Circular Queue using linked list](c-or-cpp/circular-queue-linked-list.cpp)
3. [Double Ended Queue (using arrays)](c-or-cpp/double-ended-queue-using-array.c)
1. [Double Ended Queue (using arrays)](c-or-cpp/double-ended-queue-using-array.c)

View File

@ -1,5 +0,0 @@
# Scheduling Algorithms
### Python
1. [Interval Scheduling](python/interval-scheduling.py)

View File

@ -1,321 +0,0 @@
/**
* @author Tawfik Yasser
* @since 4-2021
* */
// Program imports below
import java.util.ArrayList;
import java.util.Scanner;
// The following class to represent the process
// ** In future i will fix the name "process" to "Process"
class process {
String name;
int burset_time;
int arrive_time;
int waiting_time;
int turn_round_time;
int temp_time;
int queueNumber;
//Priority Algorithm
private int processID;
private int priority;
public process() {
this.processID = 0;
this.priority = 0;
this.arrive_time = 0;
this.burset_time = 0;
}
public process(String name, int burset_time, int arrive_time) {
this.arrive_time = arrive_time;
this.burset_time = burset_time;
this.name = name;
this.temp_time = burset_time;
}
public process(String name, int burset_time, int arrive_time, int queueNumber) {
this.name = name;
this.burset_time = burset_time;
this.arrive_time = arrive_time;
this.queueNumber = queueNumber;
}
public process(int processID, int priority, int arrivingTime, int burstTime) {
this.processID = processID;
this.priority = priority;
this.arrive_time = arrivingTime;
this.burset_time = burstTime;
}
public int getProcessID() {
return processID;
}
public void setProcessID(int processID) {
this.processID = processID;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public void setWaiting_time(int waiting_time) {
this.waiting_time = waiting_time;
}
public void setTurn_round_time(int turn_round_time) {
this.turn_round_time = turn_round_time;
}
public void setTemp_burset_time(int temp_burset_time) {
this.temp_time = temp_burset_time;
}
public int getWaiting_time() {
return waiting_time;
}
public int getTurn_round_time() {
return turn_round_time;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setBurset_time(int burset_time) {
this.burset_time = burset_time;
}
public void setArrive_time(int arrive_time) {
this.arrive_time = arrive_time;
}
public int getBurset_time() {
return burset_time;
}
public int getTemp_burset_time() {
return temp_time;
}
public int getArrive_time() {
return arrive_time;
}
public int getQueueNumber() {
return queueNumber;
}
public void setQueueNumber(int queueNumber) {
this.queueNumber = queueNumber;
}
public void reduceTime(int time) {
if(burset_time >= time)
burset_time = burset_time - time;
}
}
// ****************** The following class to start the MLQ Algorithm, Called from the main
class MultiLevelQueueScheduling {
public MultiLevelQueueScheduling() {
}
public void MLQ(int number,process[] processes,int quantum){
float totalwt = 0, totaltat = 0;
int[] completionTime = new int[number], waitingTime = new int[number], turnaroundTime = new int[number];
ArrayList<Integer> RRQueue = new ArrayList<Integer>(); // Queue to store Round Robin Processes Indexes
ArrayList<Integer> FCFSQueue = new ArrayList<Integer>(); // Queue to store FCFS Processes Indexes
for (int i = 0; i < number; i++) {
if (processes[i].getQueueNumber() == 1) {
RRQueue.add(i);
}else{
FCFSQueue.add(processes[i].getQueueNumber());
}
}
int[] highPriorityProcessArray = new int[number]; // Array to work on it instead of the RRQueue
for (int i = 0; i < RRQueue.size(); i++) {
highPriorityProcessArray[i] = RRQueue.get(i);
}
int rem_bt[] = new int[RRQueue.size()]; // Array to store the burst time of each process from RRQueue and work on it.
for (int i = 0; i < RRQueue.size(); i++) {
rem_bt[i] = processes[highPriorityProcessArray[i]].getBurset_time();
}
int rem_bt_2[] = new int[FCFSQueue.size()]; // Array to store the burst time of each process from FCFSQueue and work on it.
for (int i =0;i<FCFSQueue.size();i++){
rem_bt_2[i] = processes[FCFSQueue.get(i)].getBurset_time();
}
int t = completionTime[0]; // t is the starting time of executing processes (t=0)
int flag =0;
//Starting to execute the processes
while (true) {
boolean done = true;
// Starting of executing the Round Robin Queue Processes
for (int i = 0; i < RRQueue.size(); i++)
{
//Checking if the process arrived and still has burst time
if (processes[RRQueue.get(i)].getArrive_time() <= t && rem_bt[i] > 0) {
//System.out.println("Process "+processes[RRQueue.get(i)].getName()+" Arrived Now - Time: "+t);
// Check again for burst time if still greater than 0
if (rem_bt[i] > 0) {
done = false; // Processes still working
//Checking if the process still has burst time
if (rem_bt[i] > quantum) {
System.out.println("Process "+processes[RRQueue.get(i)].getName()+" Running Now.");
// Increase the value of t of the program and shows how much time a process has been processed.
t += quantum;
// Decrease the burst_time of current process by quantum
rem_bt[i] -= quantum;
}
// If burst time is smaller than or equal to quantum. So this is the last loop this process
else {
System.out.println("Process "+processes[RRQueue.get(i)].getName()+" Running Now.");
// Increase the value of t
t = t + rem_bt[i];
completionTime[highPriorityProcessArray[i]] = t; //Calculate that process completion time.
//--> [Turnaround Time = Completion Time - Arrival Time]
turnaroundTime[highPriorityProcessArray[i]] = completionTime[highPriorityProcessArray[i]]
- processes[highPriorityProcessArray[i]].getArrive_time();//Calculate the process turnaround time
//--> [Waiting Time = Turnaround Time - Burst Time]
waitingTime[highPriorityProcessArray[i]] = turnaroundTime[highPriorityProcessArray[i]]
- processes[highPriorityProcessArray[i]].getBurset_time();//Calculating the process waiting time
// And finally that process finished its work so the burst time will be ZERO now.
rem_bt[i] = 0;
System.out.println("Process "+processes[RRQueue.get(i)].getName()+" Finished Work - Time: "+t);
}
}
}
//Here we are check if there are another processes need to work in the second queue.
flag=0;
for(int k = 0 ; k <RRQueue.size();k++){
if(rem_bt[k] == 0 || processes[RRQueue.get(k)].getArrive_time() > t){
flag++;
}
}
}
//Position a variable to store the position of the processes from the second queue.
int position =0;
if(flag==RRQueue.size()){
//Looping on the second queue and execute the processes until the first queue filled again.
for (int j = 0; j < FCFSQueue.size(); j++) {
String fl = " ";//Flag
do{
//System.out.println("Process "+processes[FCFSQueue.get(j)].getName()+" Arrived Now - Time: "+t);
//The following loop to get the process position.
for(int y =0;y<number;y++){
if(processes[FCFSQueue.get(j)].getName().equals(processes[y].getName())){
position = y;
break;
}
}
//Calculating the Completion time and turnaround time and waiting time for each process in FCFSQueue.
completionTime[position] = t;
turnaroundTime[position] = completionTime[position] - processes[position].getArrive_time();
waitingTime[position] = turnaroundTime[position] - processes[position].getBurset_time();
if(rem_bt_2[j]==0){
System.out.println("Process "+processes[FCFSQueue.get(j)].getName()+" Finished Work - Time: "+t);
}else {
System.out.println("Process "+processes[FCFSQueue.get(j)].getName()+" Running Now.");
}
t++;//Increase the time.
rem_bt_2[j] -= 1;//Decrease the process burst time.
//Every unit of time checking if there are new process in the first queue.
//So we should stop the FCFS queue execution and go back to the first queue because the first queue has higher priority.
for(int h = 0 ; h<RRQueue.size();h++){
if(t == processes[RRQueue.get(h)].getArrive_time()){
System.out.println("Process "+processes[FCFSQueue.get(j)].getName()+" Blocked Temporary (X) at Time: "+t);
fl = "out";
break;
}
}
}while(fl.equals(" ") && rem_bt_2[j] >0);
if(!fl.equals(" ")){
break;
}
}
}
// If all processes are done their execution.
if (done == true)
break;
}
//Printing the final results of execution.
System.out.println("\nProcess Name\t\t Queue Number \tBurst Time \tCompletion Time \tWaiting Time \tTurnaround Time");
for (int i = 0; i < number; i++) {
System.out.println("\n\t" + processes[i].getName() + "\t\t\t\t\t" + processes[i].getQueueNumber() + "\t\t\t\t" + processes[i].getBurset_time() + "\t\t\t\t" + completionTime[i] + "\t\t\t\t" + waitingTime[i] + "\t\t\t\t" + turnaroundTime[i]);
}
//Calculating the AVG Waiting Time and Turnaround Time
for (int i = 0; i < number; i++) {
totalwt += waitingTime[i];
totaltat += turnaroundTime[i];
}
System.out.println("\n" + "Average Waiting Time is: " + totalwt / number);
System.out.println("Average Turnaround Time is : " + totaltat / number);
}
}
// The following is the Main function to run the program
public class Main {
public static void main(String[] args) {
System.out.print("\n");
System.out.println("Welcome to the CPU Scheduler Simulator >>>>> (OS)");
System.out.println("-------------------------------------------------");
System.out.println("Running the Multi-Level Queue Scheduling Algorithm");
multiLevelScheduling();
}
public static void multiLevelScheduling() {
int quantum = 0;
int number;
System.out.println("Enter number of processes: ");
Scanner scanner = new Scanner(System.in);
number = scanner.nextInt();
process[] processes = new process[number];
for (int i = 0; i < number; i++) {
System.out.println("Enter the name of process " + (i + 1) + " : ");
String name = scanner.next();
System.out.println("Enter the arrival time of process " + (i + 1) + " : ");
int arrival = scanner.nextInt();
System.out.println("Enter the burst time of process " + (i + 1) + " : ");
int burst = scanner.nextInt();
System.out.println("Enter the queue number of process " + (i + 1) + " : ");
int qNumber = scanner.nextInt();
process process = new process(name, burst, arrival, qNumber);
processes[i] = process;
}
System.out.println("Enter the quantum time: ");
quantum = scanner.nextInt();
MultiLevelQueueScheduling multiLevelQueueScheduling = new MultiLevelQueueScheduling();
multiLevelQueueScheduling.MLQ(number,processes,quantum);
}
}

View File

@ -1,279 +0,0 @@
/**
* @author Tawfik Yasser
* @since 4-2021
* */
// Program imports below
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Collections;
import java.util.Comparator;
// The following class to represent the process
// ** In future i will fix the name "process" to "Process"
class process {
String name;
int burset_time;
int arrive_time;
int waiting_time;
int turn_round_time;
int temp_time;
int queueNumber;
//Priority Algorithm
private int processID;
private int priority;
public process() {
this.processID = 0;
this.priority = 0;
this.arrive_time = 0;
this.burset_time = 0;
}
public process(String name, int burset_time, int arrive_time) {
this.arrive_time = arrive_time;
this.burset_time = burset_time;
this.name = name;
this.temp_time = burset_time;
}
public process(String name, int burset_time, int arrive_time, int queueNumber) {
this.name = name;
this.burset_time = burset_time;
this.arrive_time = arrive_time;
this.queueNumber = queueNumber;
}
public process(int processID, int priority, int arrivingTime, int burstTime) {
this.processID = processID;
this.priority = priority;
this.arrive_time = arrivingTime;
this.burset_time = burstTime;
}
public int getProcessID() {
return processID;
}
public void setProcessID(int processID) {
this.processID = processID;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public void setWaiting_time(int waiting_time) {
this.waiting_time = waiting_time;
}
public void setTurn_round_time(int turn_round_time) {
this.turn_round_time = turn_round_time;
}
public void setTemp_burset_time(int temp_burset_time) {
this.temp_time = temp_burset_time;
}
public int getWaiting_time() {
return waiting_time;
}
public int getTurn_round_time() {
return turn_round_time;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setBurset_time(int burset_time) {
this.burset_time = burset_time;
}
public void setArrive_time(int arrive_time) {
this.arrive_time = arrive_time;
}
public int getBurset_time() {
return burset_time;
}
public int getTemp_burset_time() {
return temp_time;
}
public int getArrive_time() {
return arrive_time;
}
public int getQueueNumber() {
return queueNumber;
}
public void setQueueNumber(int queueNumber) {
this.queueNumber = queueNumber;
}
public void reduceTime(int time) {
if(burset_time >= time)
burset_time = burset_time - time;
}
}
// ****************** The following class to start the Round Robin Algorithm, Called from the main
class RoundRobin {
public ArrayList<process> round_processes=new ArrayList<>();
private int Quantum_time;
private int total_time;
public void setContext_switching(int context_switching) {
this.context_switching = context_switching;
}
public int getContext_switching() {
return context_switching;
}
private int context_switching;
void setQuantum_time(int q)
{
this.Quantum_time=q;
}
private void sort_process ()
{
Collections.sort(round_processes, Comparator.comparing(process :: getArrive_time));
}
void round_robien ()
{
sort_process();
int flag=0,i=0,temp;
while (flag!=round_processes.size())
{
if (round_processes.get(i).getBurset_time()!=0)
{
if (round_processes.get(i).getBurset_time()>=Quantum_time)
{
System.out.println("process :"+round_processes.get(i).getName()+"is running");
total_time+=Quantum_time;
temp=round_processes.get(i).getBurset_time();
temp-=Quantum_time;
round_processes.get(i).setBurset_time(temp);
if (temp==0)
{
flag++;
round_processes.get(i).setTurn_round_time(total_time);
System.out.println("process :"+round_processes.get(i).getName()+"is terminated");
i++;
}
else {
System.out.println("process :"+round_processes.get(i).getName()+"is waiting");
i++;}
total_time+=context_switching;
}
else if (round_processes.get(i).getBurset_time()<Quantum_time)
{
System.out.println("process :"+round_processes.get(i).getName()+"is running");
total_time+=round_processes.get(i).getBurset_time();
round_processes.get(i).setBurset_time(0);
round_processes.get(i).setTurn_round_time(total_time);
flag++;
System.out.println("process :"+round_processes.get(i).getName()+"is terminated");
i++;
total_time+=context_switching;
}
}
else
i++;
if (i==round_processes.size())
i=0;
}
}
public double calculate_average_waiting() {
double av=0;
for (int i = 0; i < round_processes.size(); i++) {
av+=round_processes.get(i).getTurn_round_time()-round_processes.get(i).getTemp_burset_time();
}
return (av/round_processes.size());
}
public double calculate_average_turnround() {
double av=0;
for (int i = 0; i < round_processes.size(); i++) {
av+=round_processes.get(i).getTurn_round_time();
}
return (av/round_processes.size());
}
public void print ()
{
for (int i=0;i<round_processes.size();i++)
{
System.out.print("Name: "+round_processes.get(i).getName()+" ");
System.out.println("turn round time: "+round_processes.get(i).getTurn_round_time());
System.out.print("waiting time: "+(round_processes.get(i).getTurn_round_time()-round_processes.get(i).getTemp_burset_time())+"\n");
}
System.out.println("average waiting time : "+calculate_average_waiting());
System.out.println("average turn_round_time : "+calculate_average_turnround());
}
}
// The following is the Main function to run the program
class Main {
public static void main(String[] args) {
System.out.print("\n");
System.out.println("Welcome to the CPU Scheduler Simulator >>>>> (OS)");
System.out.println("-------------------------------------------------");
System.out.println("Running the Round Robin Scheduling Algorithm");
RRAlgorithm();
}
public static void RRAlgorithm() {
RoundRobin r1=new RoundRobin();
int number,quantam,burset_time,arrive_time,con;
Scanner input=new Scanner(System.in);
System.out.println("enter number of process");
number=input.nextInt();
process p2;
String name;
for (int i=0;i<number;i++)
{
System.out.println("enter burset_time of process");
burset_time=input.nextInt();
System.out.println("enter arrive_time of process");
arrive_time=input.nextInt();
System.out.println("enter name of process");
name=input.nextLine();
name=input.nextLine();
p2=new process(name,burset_time,arrive_time);
r1.round_processes.add(p2);
}
System.out.println("enter quantam time");
quantam=input.nextInt();
System.out.println("enter context switching");
con=input.nextInt();
r1.setContext_switching(con);
r1.setQuantum_time(quantam);
r1.round_robien();
r1.print();
}
}

View File

@ -1,9 +0,0 @@
# Searching algorithms
### C or C++
1. [Linear Search](c-or-cpp/linear-search.cpp)
2. [Binary Search](c-or-cpp/binary-search.cpp)
3. [Jump Search](c-or-cpp/jump-search.cpp)
4. [finding squareroot using binary search](c-or-cpp/sqrt-monotonic-binary-search.cpp)
5. [Interpolation Search](c-or-cpp/interpolation-search.cpp)

View File

@ -1,16 +1,5 @@
# Sorting algorithms
### C or C++
### C
1. [Bubble Sort](c-or-cpp/bubble-sort.cpp)
2. [Insertion Sort](c-or-cpp/insertion-sort.cpp)
3. [Selection Sort](c-or-cpp/selection-sort.cpp)
4. [Merge Sort](c-or-cpp/merge-sort.c)
5. [Quick Sort](c-or-cpp/quick-sort.cpp)
6. [Heap Sort](c-or-cpp/heap-sort.cpp)
7. [Counting Sort](c-or-cpp/counting-sort.cpp)
8. [Bucket Sort](c-or-cpp/bucket-sort.cpp)
9. [Radix Sort](c-or-cpp/radix-sort.cpp)
10. [Shell Sort](c-or-cpp/shell-sort.cpp)
11. [Comb Sort](c-or-cpp/comb-sort.cpp)
12. [3 Way Quick Sort](c-or-cpp/3way_quick_sort.cpp)
1. [Merge Sort](c-or-cpp/merge-sort.c)

View File

@ -1,5 +0,0 @@
# Stacks
### C or C++
1. [Balanced Parenthesis](c-or-cpp/balanced-parenthesis.cpp)

View File

@ -3,10 +3,5 @@
### C or C++
1. [Palindrome Check](c-or-cpp/palindrome.c)
2. [All subsequences](c-or-cpp/sequence.cpp)
3. [KMP String Searching](c-or-cpp/kmp.cpp)
4. [Rabin Karp String Searching](c-or-cpp/rabin-karp.cpp)
5. [String Tokeniser](c-or-cpp/string-tokeniser.cpp)
6. [String Reversal](c-or-cpp/string-reverse.cpp)
7. [Permutation of String](c-or-cpp/Permutation-of-String.c)
8. [Count Words](c-or-cpp/count-words.c)
2. [Permutation of String](c-or-cpp/Permutation-of-String.c)
3. [Count Words](c-or-cpp/count-words.c)

View File

@ -1,9 +0,0 @@
# Trees
### C or C++
1. [Pre, In & Post Order Traversals](c-or-cpp/pre-in-post-traversal.cpp)
2. [Level Order Traversal](c-or-cpp/level-order-traversal.cpp)
3. [Build Binary Tree using Pre,In & Post Order](c-or-cpp/build-binary-tree.cpp)
4. [Count and find the Sum of nodes in a Binary Tree](c-or-cpp/count-and-sum-of-nodes-in-binary-tree.cpp)