Course Hero Logo

Lab session 06 greedy algorithm part 2 date of the

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 46 - 51 out of 96 pages.

LAB SESSION 06: GREEDY ALGORITHM PART 2Date of the Session: ___/___/___Time of the Session: _____to______Pre-Lab:1)Explain why 0-1 Knapsack problems cannot be solved using greedy method unlike fractionalknapsack.
20CI2206R DESIGN & ANALYSIS OF ALGORITHMS462)Categorize the Following as single source or multiple source shortest path algorithms.Floyd-Warshall algorithmDijkstra’s algorithm –Bellman-Ford algorithmSolution:3)List down various shortest path greedy algorithms.Solution:
20CI2206R DESIGN & ANALYSIS OF ALGORITHMS47In-Lab:1)Given an array of size n that has the following specifications:a.Each element in the array contains either a police officer or a thief.b.Each police officer can catch only one thief.c.A police officer cannot catch a thief who is more than K units away from the police officer.We need to find the maximum number of thieves that can be caught.Inputarr [] = {'P', 'T', 'T', 'P', 'T'},k = 1.Output2Here maximum 2 thieves can be caught; first police officer catches first thief and second policeofficer can catch either second or third thief.Solution:
20CI2206R DESIGN & ANALYSIS OF ALGORITHMS2)Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). nvertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines,which, together with the x-axis forms a container, such that the container contains the most water.Notice that you may not slant the container.Inputheight = [1,8,6,2,5,4,8,3,7]Output
48Solution:
20CI2206R DESIGN & ANALYSIS OF ALGORITHMS49Post-Lab:1)Given an array of jobs where every job has a deadline and associated profit if the job is finishedbefore the deadline. It is also given that every job takes a single unit of time, so the minimumpossible deadline for any job is 1. How to maximize total profit if only one job can be scheduled ata time.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 96 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
iii
Tags
Design Analysis of Algorithms

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture