diff --git a/algorithms/CPlusPlus/Arrays/count-inversions.cpp b/algorithms/CPlusPlus/Arrays/counting-inversions.cpp similarity index 100% rename from algorithms/CPlusPlus/Arrays/count-inversions.cpp rename to algorithms/CPlusPlus/Arrays/counting-inversions.cpp diff --git a/algorithms/CPlusPlus/README.md b/algorithms/CPlusPlus/README.md index 3370934a..737fe097 100644 --- a/algorithms/CPlusPlus/README.md +++ b/algorithms/CPlusPlus/README.md @@ -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) diff --git a/strings/c-or-cpp/kmp.cpp b/algorithms/CPlusPlus/Searching/kmp.cpp similarity index 100% rename from strings/c-or-cpp/kmp.cpp rename to algorithms/CPlusPlus/Searching/kmp.cpp diff --git a/algorithms/CPlusPlus/Sorting/3way_quick_sort.cpp b/algorithms/CPlusPlus/Sorting/3way-quick-sort.cpp similarity index 100% rename from algorithms/CPlusPlus/Sorting/3way_quick_sort.cpp rename to algorithms/CPlusPlus/Sorting/3way-quick-sort.cpp diff --git a/algorithms/Python/README.md b/algorithms/Python/README.md index 32c123e7..85c6d435 100644 --- a/algorithms/Python/README.md +++ b/algorithms/Python/README.md @@ -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) diff --git a/algorithms/Python/arrays/count_inversions.py b/algorithms/Python/arrays/counting_inversions.py similarity index 100% rename from algorithms/Python/arrays/count_inversions.py rename to algorithms/Python/arrays/counting_inversions.py diff --git a/arrays/README.md b/arrays/README.md index a2060995..fe8a70e9 100644 --- a/arrays/README.md +++ b/arrays/README.md @@ -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) diff --git a/graphs/README.md b/graphs/README.md index 58af7401..f84ac887 100644 --- a/graphs/README.md +++ b/graphs/README.md @@ -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) diff --git a/linked-lists/README.md b/linked-lists/README.md index cd0052ca..f7953351 100644 --- a/linked-lists/README.md +++ b/linked-lists/README.md @@ -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) diff --git a/multiplication/README.md b/multiplication/README.md deleted file mode 100644 index 19370599..00000000 --- a/multiplication/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Multiplication algorithms - -### C or C++ - -1. [Karatsuba Multiplication](c-or-cpp/karatsuba.cpp) - -### Python - -1. [Karatsuba Multiplication](python/karatsuba.py) diff --git a/queues/README.md b/queues/README.md index 958080a3..745d77c4 100644 --- a/queues/README.md +++ b/queues/README.md @@ -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) diff --git a/scheduling/README.md b/scheduling/README.md deleted file mode 100644 index bd30ba55..00000000 --- a/scheduling/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Scheduling Algorithms - -### Python - -1. [Interval Scheduling](python/interval-scheduling.py) diff --git a/scheduling/java/multi-level-queue-scheduling.java b/scheduling/java/multi-level-queue-scheduling.java deleted file mode 100644 index 07776e4b..00000000 --- a/scheduling/java/multi-level-queue-scheduling.java +++ /dev/null @@ -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 RRQueue = new ArrayList(); // Queue to store Round Robin Processes Indexes - ArrayList FCFSQueue = new ArrayList(); // 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 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 it’s 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 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;y0); - 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); - - } -} \ No newline at end of file diff --git a/scheduling/java/round-robin.java b/scheduling/java/round-robin.java deleted file mode 100644 index 41f5b4cd..00000000 --- a/scheduling/java/round-robin.java +++ /dev/null @@ -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 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()>>>> (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