0% found this document useful (0 votes)
12 views4 pages

HW2 Seng313

Uploaded by

metinkul895
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

HW2 Seng313

Uploaded by

metinkul895
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

General Instructions (READ CAREFULLY)

1. Format for Submission:

o Solutions to all theoretical problems must be submitted as a PDF


document.

o For coding problems, submit the source code as .py( or other) files (one
file per question).

o Include appropriate comments in your code to explain your logic.

2. Submission Guidelines:

o Submit your homework via the LMS (Learning Management System).

o If there are any issues with uploading to the LMS, you must email your
submissions to me.

3. Email Structure (if only LMS is not working):

o Subject: Algorithm Analysis Homework 2 Submission - [Your Full


Name and Student ID]

Dear Dr,

I am attaching my submission for the Algorithm Analysis homework


assignment.

Attached files:

1. PDF file containing theoretical solutions.

2. Separate coding files for coding questions.

Thank you.

Best regards,

[Your Full Name] [Your Student ID]

Deadlines:

• Homework 2 (Dynamic Programming and Greedy Algorithms): [29.11.2024 at


23:59]

• No extensions will be granted, so ensure timely submission.

Evaluation Criteria:

• Correctness of solutions.

• Clarity of explanations and code readability.


• Proper formatting and adherence to submission instructions.

• Following the homework instructions.

Plagiarism:

• All work must be your own. Any copied or plagiarized work will result in zero credit
for the assignment.

Homework 2: Dynamic Programming and Greedy Algorithms


Submission Deadline: 29.11.2024 at 23:59.
Instructions:

• Solve all questions and include code for implementation tasks.

• Provide detailed explanations of your solutions and approaches.

• Use Python or a preferred programming language for coding questions.

Part 1: Dynamic Programming

1. Longest Increasing Subsequence (LIS)

o Write a program to find the length of the longest increasing subsequence


in a given array.

o Input: An array of integers.

o Output: The length of the LIS.

o Example:
Input: arr=[10,9,2,5,3,7,101,18] Output: 4 (LIS = [2,3,7,101])

o Additional Task: Explain the time complexity of your solution.

2. Knapsack Problem

o Solve the 0/1 Knapsack Problem using dynamic programming.

o Input: Weights and values of n items and the capacity of the knapsack.

o Output: Maximum value that can be achieved and the selected items.

o Example:
Input:Weights = [2,3,4,5], Values = [3,4,5,6] , Capacity = 5
Output: Max Value = 7, Selected items = [Item 2]
Additional Task: Discuss how this problem can be adapted for a fractional
knapsack (Greedy approach).
3. Coding: Edit Distance

o Implement a dynamic programming algorithm to compute the minimum


edit distance between two strings X and Y.

o Input: Two strings.

o Output: Minimum number of operations (insert, delete, replace) required


to convert X into Y.

o Example: Input: X="sunday",Y="saturday"

o Output: 3
Additional Task: Provide an optimized version using space reduction
techniques.

Part 2: Greedy Algorithms

4. Huffman Encoding

o Implement the Huffman coding algorithm to compress a given set of


characters with their frequencies.

o Input: A list of characters and their respective frequencies.

o Output: Huffman codes for each character.

o Example:
Input:
Characters = [a,b,c,d,e,f], Frequencies = [5,9,12,13,16,45],

o Output: Huffman codes (e.g., a:110,b:111,…)


Additional Task: Discuss how Huffman coding can fail for non-optimal
frequency distributions.

5. Job Scheduling Problem

o Write a greedy algorithm to solve the job scheduling problem with


deadlines and profits.

o Input: A list of jobs with deadlines and profits.

o Output: The sequence of jobs that maximizes profit.

o Example:
Input:Jobs = [Job1,Job2,Job3], Deadlines = [2,1,2], Profits = [100,50,200]
Output: Maximum profit = 250, Job sequence = [Job3,Job1]
6. Discussion

o Compare the effectiveness of Dynamic Programming and Greedy


algorithms. Provide real-world examples where one approach is more
suitable than the other.

You might also like