Sunday, February 2, 2014

Efficient algorithms

I just started reading algorithms again. I can hardly move past the 1st one.

While thinking of algos, you know a few things.
A problem can have multiple solutions. Each one could be optimized for different things - either time or memory or simply easier code. Or, you could simply follow a rote method and solve it. Disregard any optimization.

Likewise, the many things we do in the REAL life have multiple solutions.
If you really want to optimize, you can.

You want to buy vegetables.

a) How many days stock do you need? Are you willing to shop 2-3 times for the week?
b) What all are must-haves? Are there any leftovers in the fridge?
c) Where do you want to shop? Super market, pushcart or small shops near your house or sabzi mandi? Price - quality and choice of vegetables at each place - ease of getting all that you need in one roof - convenience and a/c - distance from your house - availability of parking, weather conditions, time you have in hand, day of week, do I like the shopkeeper?- all of this could affect that one decision.

d) Do you have specific items which you want to pick from specific store or you can adjust with quality from one store? that means you make 3-4 trips.
e) Do u want to carry your own bags? - you need to plan and spend time arranging bags.
f) Do you want pre-packed veggies or pre-cut veggies? Do you really want to pick greens, because cleaning greens takes a long time?
g) Do you care about seasonal produce? Do you want to take the pains to go to Lalbagh or GKVK to pick some rare, seasonal stuff? Is it worth the pains?
h) Do you have enough cash? Else withdraw cash.
i) Do you want to walk or use the car? Does the car have fuel?
j) Do you have any parties lined up for the week? Is so, you need to plan for specific stuff and re-adjust the quantities.

Then, starts the post processing:
Step 1:
You can come back from shopping and rest. Some of the greens may wither.
OR
You can either dump them all in the fridge as is.
Or
seggregate and dump.
OR
wash them. seggregate and dump.
OR
wash them, immerse in water to remove pesticides, segregate and dump.
OR
wash them, immerse in water to remove pesticides, segregate, clean the greens and dump.
OR
wash them, immerse in water to remove pesticides, segregate, clean the greens, plan and dump.
Here - while you seggregate you make a list of what recipe you want to use with that veggie.
You can seggregate ones that will go bad faster (like greens) on top and use them first. You can draw a list and post it on your fridge.

Then over the next few days, you check if you're using the veggies properly. Check if you've run out of something. Check if something is about to go bad. If it has already gone bad, trash it and get thrashed.

By the end of the cycle, you need special planning because you're left with an assortment of vegetables which cannot be used individually but need to be very creatively combined to make for a tasty dish. If you have no time for that, you may have to trash these minute quantities.

Now, you're free.. atlast when your fridge is free...and you feel relaxed that you no longer need to plan for the vegetables in the fridge...the next cycle starts. The whole family is hungry.

No comments:

Post a Comment