# Programming Assignment 2: Priority Queues and Disjoint Sets solution

\$29.99

Original Work ?

## Description

5/5 - (1 vote)

Introduction In this programming assignment, you will practice implementing priority queues and disjoint sets and using them to solve algorithmic problems. In some cases you will just implement an algorithm from the lectures, while in others you will need to invent an algorithm to solve the given problem using either a priority queue or a disjoint set union. Recall that starting from this programming assignment, the grader will show you only the first few tests (see the questions 5.4 and 5.5 in the FAQ section).
Learning Outcomes Upon completing this programming assignment you will be able to: 1. Apply priority queues and disjoint sets to solve the given algorithmic problems. 2. Convert an array into a heap. 3. Simulate a program which processes a list of jobs in parallel. 4. Simulate a sequence of merge operations with tables in a database.
Passing Criteria: 2 out of 3 Passing thisprogramming assignmentrequires passingat least2out of3code problemsfrom thisassignment. In turn, passing a code problem requires implementing a solution that passes all the tests for this problem in the grader and does so under the time and memory limits specified in the problem statement.
Contents 1 Problem: Convert array into heap 3
2 Problem: Parallel processing 5
3 Problem: Merging tables 7
1
4 General Instructions and Recommendations on Solving Algorithmic Problems 10 4.1 Reading the Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.2 Designing an Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.3 Implementing Your Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.4 Compiling Your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.5 Testing Your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.6 Submitting Your Program to the Grading System . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.7 Debugging and Stress Testing Your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5 Frequently Asked Questions 13 5.1 I submit the program, but nothing happens. Why? . . . . . . . . . . . . . . . . . . . . . . . . 13 5.2 I submit the solution only for one problem, but all the problems in the assignment are graded. Why? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.3 What are the possible grading outcomes, and how to read them? . . . . . . . . . . . . . . . . 13 5.4 How to understand why my program fails and to fix it? . . . . . . . . . . . . . . . . . . . . . 14 5.5 Why do you hide the test on which my program fails? . . . . . . . . . . . . . . . . . . . . . . 14 5.6 My solution does not pass the tests? May I post it in the forum and ask for a help? . . . . . 15 5.7 My implementation always fails in the grader, though I already tested and stress tested it a lot. Would not it be better if you give me a solution to this problem or at least the test cases that you use? I will then be able to fix my code and will learn how to avoid making mistakes. Otherwise, I do not feel that I learn anything from solving this problem. I am just stuck. . . 15
2
1 Problem: Convert array into heap Problem Introduction In this problem you will convert an array of integers into a heap. This is the crucial step of the sorting algorithmcalledHeapSort. Ithasguaranteedworst-caserunningtimeof O(nlogn) asopposedtoQuickSort’s average running time of O(nlogn). QuickSort is usually used in practice, because typically it is faster, but HeapSort is used for external sort when you need to sort huge files that don’t fit into memory of your computer.