//--------------------------------------------------------------------------------------------------------------------------------------- //4.Worst-fit decreasing algorithm using Priority queue. -------------------------------------------------------------------------------- //Button: Worst-fit decreasing algorithm using Priority queue. /*Overall Complexity:First for loop(𝞱(N))+Max(Merge Sort(O(N log N)),Second for loop(𝞱(N log M))+traverse(𝞱(N+M))+traverse_copy(𝞱(N+M))) * =𝞱(N)+Max(N log N,N log M)=O(N log N) */ private void button6_Click(object sender, EventArgs e) { Stopwatch StpW = Stopwatch.StartNew(); folder_name = "[2] WorstFit Decreasing"; Names_Durations list = new Names_Durations(); for (int i = 0; i < durations.Count; i++)//First for loop:𝞱(N) { list.name.Add(names[i]); list.duration.Add(durations[i]); } Names_Durations NewList = MergeSort(list);//O(N log N) int count = 2; double duration_of_each_file = double.Parse(textBox1.Text); Node node = new Node(duration_of_each_file - NewList.duration[0], "F1"); node.list_names.Add(NewList.name[0]); node.list_durations.Add(NewList.duration[0]); max_binary_heap h = new max_binary_heap(node); for (int i = 1; i < NewList.duration.Count; i++) //Overall Complexity of the Second for loop:𝞱(N log M),Number of iteration = N { if (h.root.total_remaining_time >= NewList.duration[i]) //Overall Complexity:𝞱(log M) { h.root.list_names.Add(NewList.name[i]); h.root.list_durations.Add(NewList.duration[i]); h.root.total_remaining_time -= NewList.duration[i]; h.max_heapify1(h.root);//𝞱(log M) } else//Overall Complexity:𝞱(log M) { node = new Node(duration_of_each_file - NewList.duration[i], "F" + count.ToString()); node.list_names.Add(NewList.name[i]); node.list_durations.Add(NewList.duration[i]); count++; h.insert(node);//𝞱(log M) } } // h.traverse(double.Parse(textBox1.Text));//𝞱(N+M) StpW.Stop(); MessageBox.Show(StpW.Elapsed.ToString()); // h.traverse_Copy(double.Parse(textBox1.Text));//𝞱(N+M) MessageBox.Show("Done !"); }
//Button: Worst-fit algorithm using Priority queue. //Overall Complexity: for loop(O(N log M))+traverse(𝞱(N+M))+traverse_copy(𝞱(N+M)) = O(N log M). private void button5_Click(object sender, EventArgs e) { Stopwatch StpW = Stopwatch.StartNew(); folder_name = "[1] WorstFit"; int count = 2; double duration_of_each_file = double.Parse(textBox1.Text); Node node = new Node(duration_of_each_file - durations[0], "F1"); node.list_names.Add(names[0]); node.list_durations.Add(durations[0]); max_binary_heap h = new max_binary_heap(node); for (int i = 1; i < durations.Count(); i++) //Overall Complexity:O(N log M),Number of iteration=N { if (h.root.total_remaining_time >= durations[i]) //Overall Complexity:O(log M) { h.root.list_names.Add(names[i]); h.root.list_durations.Add(durations[i]); h.root.total_remaining_time -= durations[i]; h.max_heapify1(h.root);//O(log M) } else//Overall Complexity:O(log M) { node = new Node(duration_of_each_file - durations[i], "F" + count.ToString()); node.list_names.Add(names[i]); node.list_durations.Add(durations[i]); count++; h.insert(node);//O(log M) } } h.traverse(double.Parse(textBox1.Text));//𝞱(N+M) StpW.Stop(); MessageBox.Show(StpW.Elapsed.ToString()); h.traverse_Copy(double.Parse(textBox1.Text));//𝞱(N+M) MessageBox.Show("Done !"); }