shift/reduce parsing: the difference between LALR (1) and LR (1) is that LALR is based
on an LR (0) automaton.
Operationally they are the same: shift when you have to shift, reduce when you have to
reduce and give an error message when there is a mismatch between the set of expected tokens
and the received token
Hi all, just seeking some advice please on how to approach this problem.
I need to create an algorithm for a small courier company.
The basic parameters would be x amount of drivers and a list of deliveries, pickup and drop-off postcodes with delivery time slots.
My thinking is to first create a matrix of all the pick up and delivery job postcodes and populate it with distance and journey times using Google’s API, then somehow loop through the jobs and match journey time’s with the delivery slots but not really sure where to start or even if this is a viable approach.
All I can offer is that you should check whether the API returns the actual driving distance, or the "as the crow flies" straight-line distance. Once you start taking things like rivers and one-way systems into account, someone who is geographically closer to a destination might take considerably longer to reach it than someone who is technically further away.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Kindly help me out to solve this question fro the book "Foundation of Algorithm"
There are two algorithms called Alg1 and Alg2 for a problem of size n. Alg1 runs in n2 microseconds and Alg2 runs in 100n log n microseconds. Alg1 can be implemented using 4 hours of programmer time and needs 2 minutes of CPU time. On the other hand, Alg2 requires 15 hours of programmer time and 6 minutes of CPU time. If programmers are paid 20 dollars per hour and CPU time costs 50 dollars per minute, how many times must a problem instance of size 500 be solved using Alg2 in order to justify its development cost?
I've come very close a couple of times, but I just can't get it right.
I know one person on Code Project that knows how, but I don't think he's telling. Fair enough.
Does anyone know of any resources on this? Something not math heavy, or at least not math exclusive. I'd prefer sample code or a high level description at least. Any programming language, though I prefer C family languages except java. I'll take java though, as it's what most of academia uses, and this is an academic exercise primarily.
I really would like to solve this for the parser generators I've built.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
Here is the question requirement:
There is a map shown in below
WWWW S W
WWWW WWWW W
WWWW WWWW W
B ES E W
W is the wall that the player cannot move to
S is the score can the player option
E is the energy can gain
B is beginning point
D is the ending point
First, player has 0 energy and they need to go to E to gain energy first. Then when they gain energy, they can go to S to gain score. However, every E and S contains different energies, energies required and scores. Here is the clear description of the map:
<5 0> is B (Begining point)
<5 4> is E (energy point, contain 20 energy)
<3 4> is S (Score, require 6 energy to gain and contain 30 scores)
<5 5> is S (Score, require 2 energy to gain and contain 230 scores)
<5 8> is E (energy, contain 30 energy)
<3 10> is S (Score, require 16 energy to gain and contain 30 scores)
<1 8> is S (Score, require 8 energy to gain and contain 10 scores)
The final score is in this formula:
energy + scores - steps*2
The best path is B -> <5 4> -> <3 4> -> <5 5> -> <5 8> -> <3 10> -> D
The key point is that how to let the program or algorithm detect the optimal path (With the minimum steps and know which score should get as in the above example, the <1 8> Score is ignored.)
I am now figuring how can let the computer know going the <3 4> and go back the <5 4> and go to <5 5> is the best path instead of going to <5 5> -> <5 4> -> <3 4> -> <5 5>. I know the later one is a stupid path. But what I can think of is that to do the best path, we may need to search all path with factorial times loop which is not accepted in term of running time.
This kind of problem is basically solved by brute force because you have to check all paths.
But some techniques allow reducing the workload, like memorizing partial results to avoid recalculating them every time. Memoization - Wikipedia[^]
For example, all path will start with 'B -> <5 4>' because of the map.
You must put some thinking to understand how the problem works and what simplifications can be done.
“Everything should be made as simple as possible, but no simpler.” Albert Einstein