greedy Questions

4

Solved

I came across a coding challenge on the internet the question is listed below: Have the function FoodDistribution(arr) read the array of numbers stored in arr which will represent the hunger level...
Oppugnant asked 19/5 at 14:28

14

Solved

Can somebody tell me why Dijkstra's algorithm for single source shortest path assumes that the edges must be non-negative. I am talking about only edges not the negative weight cycles.
Playoff asked 31/10, 2012 at 13:41

3

Someone asked me this question: You are given a list of intervals. You have to design an algorithm to find the sequence of non-overlapping intervals so that the sum of the range of intervals is max...
Convolve asked 15/8, 2013 at 21:23

8

I am trying to implement the Hungarian Algorithm but I am stuck on the step 5. Basically, given a n X n matrix of numbers, how can I find minimum number of vertical+horizontal lines such that the z...
Fifi asked 30/4, 2014 at 4:23

9

Solved

I have a small problem solving the Car fueling problem using the Greedy Algorithm. Problem Introduction You are going to travel to another city that is located 𝑑 miles away from your home city. Y...
Pentalpha asked 3/5, 2020 at 6:40

5

Solved

When searching in a tree, my understanding of uniform cost search is that for a given node A, having child nodes B,C,D with associated costs of (10, 5, 7), my algorithm will choose C, as it has a l...
Riddle asked 17/1, 2010 at 20:38

9

Solved

In the game Hangman, is it the case that a greedy letter-frequency algorithm is equivalent to a best-chance-of-winning algorithm? Is there ever a case where it's worth sacrificing preservation of ...
Foible asked 30/3, 2012 at 12:23

4

I did search and looked at these below links but it didn't help . Point covering problem Segments poked (covered) with points - any tricky test cases? Need effective greedy for covering a line se...
Heredia asked 21/6, 2016 at 5:56

3

Solved

Given a M * N grid and location of two players p1 and p2on grid. There are n balls placed on different positions on the grid. Let the location of these balls be B(1), B(2), B(3) ..., B(n). We need...
Unaffected asked 1/10, 2016 at 10:36

27

Solved

I'm trying to use sed to clean up lines of URLs to extract just the domain. So from: http://www.suepearson.co.uk/product/174/71/3816/ I want: http://www.suepearson.co.uk/ (either with or without ...
Gaslight asked 9/7, 2009 at 10:47

4

Solved

Before I start, yes this is a homework. I would not have posted here if I haven't been trying as hard as I could to solve this one for the last 14 hours and got nowhere. The problem is as follows:...
Vitrine asked 3/1, 2012 at 1:29

5

Solved

I feel like Kadane's algorithm is a modified version of the true dynamic programming solution of maximum subarray problem.Why do I feel so? I feel because the way to calculate the maximum subarray ...
Webby asked 1/7, 2015 at 7:37

7

I understand how the greedy algorithm for the coin change problem (pay a specific amount with the minimal possible number of coins) works - it always selects the coin with the largest denomination ...
Turaco asked 26/11, 2012 at 2:42

3

Solved

Input (1) the maximum distance that a car can travel with a full tank: L km; (2) an integer array, [0, x1, x2, …, xn, xn+1], each integer represents the distance between a location and a source po...
Heterotrophic asked 7/5, 2020 at 7:10

7

Given heights of n towers and a value k. We need to either increase or decrease height of every tower by k (only once) where k > 0. The task is to minimize the difference between the heights of ...
Possess asked 20/7, 2020 at 16:43

1

import java.util.*; import java.io.*; public class CarFueling { static int compute_refills(int dist,int tank,int stops[],int n){ int current_refills=0; int num_refills=0; int last_refill=0; ...
Breakdown asked 16/9, 2020 at 7:37

10

What is the use of greedy algorithms? An real example?
Mapel asked 1/2, 2011 at 20:19

1

Solved

Why I created a duplicate thread I created this thread after reading Longest increasing subsequence with K exceptions allowed. I realised that the person who was asking the question hadn't really u...
Socage asked 25/12, 2019 at 1:21

4

Solved

In this Job Sequencing Problem, how do we prove that the solution which greedy approach will provide is a optimal one? Moreover, I am also not able to figure out the O(n) solution as the author l...
Trout asked 13/1, 2015 at 11:59

8

Solved

Does the opposite of Kruskal's algorithm for minimum spanning tree work for it? I mean, choosing the max weight (edge) every step? Any other idea to find maximum spanning tree?
Boroughenglish asked 14/2, 2011 at 13:26

2

Solved

I need some help with a problem. I recently got this in an interview and I was trying to solve it but having no luck. Here's the question: Code an algorithm for a game consisting of two players. T...
Originate asked 19/6, 2019 at 0:11

4

Why does Kruskal's algorithm find the minimum spanning tree if it's greedy? Isn't a minimum spanning tree a global optimization problem? Isn't the point of being greedy is that there is a chance yo...
Nadianadine asked 10/12, 2016 at 2:42

3

Solved

I came across this question in a programming contest: We are given an array consisting of n elements. At each iteration, you can select any two elements ai and aj and replace ai with ai & aj...
Mephitis asked 25/2, 2019 at 12:58

6

Solved

What is the main difference between dynamic programming and greedy approach in terms of usage? As far as I understood, the greedy approach sometimes gives an optimal solution; in other cases, the ...
Malleolus asked 22/5, 2013 at 11:11

3

I was trying to solve one Interview problem that is: Given a matrix of n*n. Each cell contain 0, 1, -1. 0 denotes there is no diamond but there is a path. 1 denotes there is diamond at that lo...
Psychosomatics asked 21/10, 2015 at 8:26

© 2022 - 2024 — McMap. All rights reserved.