[SOLVED] CSCI 3070U -Analysis and Design of Algorithms Assignment- #3

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Assignment-3-0zm0nt.zip (54.2 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

 

 

Topic:               Linear sorting, greedy algorithms

 

Part 1

For this part of the assignment, you will implement a radix sort procedure for sorting numbers between 0 (inclusive) and 1,000,000 (exclusive) (i.e. 6-digit numbers).  Your procedure will use a modified version the counting sort implementation that you developed in tutorial #5 in order to sort by each digit (modified to sort by digit, of course).

 

You may find the following code (which determines the value of an arbitrary digit) useful:

 

function getDigit(num, digit) {

working = num / 10digit-1;

return workingmod 10;

}

Part 2

Write a greedy algorithm to solve the fractional knapsack problem, as described below:

 

Given a number of items with weight and value, select a percentage (0.0-1.0) for each item(s) to include in your knapsack such that the weight capacity (W) of the knapsack is not exceeded, and the total value (V, the sum of the value of all included items) is maximal.

 

One way that you could implement this problem is to pass 2 arrays into your procedure:  1) weights, where weights[i] is the weight of element i, and 2) values, where values[i] is the value of element i.

Part 3

Write an implementation of Huffman coding, which is a greedy implementation of assigning prefix codes.  This will require a program that does the following:

  1. Read through a simple ASCII text file (passed as an argument), determining the frequency of each character in the file
  2. Use these frequencies to calculate the optimal prefix codes for each character (Huffman)
    • Print a complete table of prefix codes for the characters in the document (print only characters with frequencies > 0)
  3. Normally, you would then encode each character using its prefix code
    • However, actually implementing this requires some trick bit manipulation (which, for some languages, is difficult to do)
    • Instead, calculate the length of the entire document before and after using the prefix codes

 

  • Assignment-3-0zm0nt.zip