21
jeral
7y

When I saw an O(1) algorithm solution. I was so amazed that I got goosebump. Still wondering how one is able to come up with such algorithm.

Another times when I understand how the whole thing works in a project. This class is doing this, that class is doing that, this file contains the configuration, etc. Its like everything is connected.

Other times when you see your pet project start to take shape. You just want to cuddle it.

Comments
  • 0
    @hube it is one of the best solution of an easy problem in hackerrank. So it is more straightforward. IIRC, its in one of the contest/competition. Hackerrank shows the complexity of the algorithm implemented.
  • 1
    Cooking recipts are O(1), even/odd compairison is O(1) it all depends on the task, without the code its really hard to follow your astonishment. :)
  • 1
    @Hammster Cooking recipes? Depends how many pb&j sandwiches you're making...
  • 1
    @bittersweet does not matter each sandwich is O(1), and a loop of O(1) is O(n).
  • 0
    project Euler 15 has an O(1) solution for example
  • 0
    @Hammster Yeah that's what I mean... what about platters of deviled eggs? O(mn), m for the size of the platter, n for the amount of platters. Luckily you can parallellize the process to a large degree, although eggs need to be cooked before peeling, slicing and spicing; garnishing can happen while cooking, and filling can be distributed as well.

    I just disagree that cooking recipes are always O(1).

    I'm actually working on an interpreter for the esoteric Chef language in Rust, so it supports concurrent recipes (sous-chef, I'm calling it).
  • 0
    @Hammster there is one problem that dealing with calculation. Most of the solution use a loop. But there is a solution that doesn't. I can't remember what the problem title but I remember the username. Its either uwi or uwe. Its been 3 years since I then.
  • 1
    @bittersweet you know that there is stuff like rolled eggs, cooked and ready to serve :P

    If a recipe is just list of tasks without any steps that says repeat this and that, i think of it as O(1).

    In programming terms, a assembly program that uses no jumps has to be O(1) too since it only works down a task list of assigning stuff from A to B
  • 0
    @Hammster But then you can call any algorithm O(1), when you remove the loops and just explicitly repeat the instruction a million times in the code, writing if statements in between to return when you reach the desired loop index 🤣

    print('*')
    if(n==1) return
    print('*')
    if(n==2) return
    print('*')
    if(n==3) return
    ...
  • 2
    @bittersweet your example has different exit points so it cannot be a static time ;)

    If you make a fried egg by the recipe, it is a set list of instructions, always the same instruction for any egg you fry. Therefore it is O(1)

    The operations needed to complete the algorithm does not matter, but how constant it is, early returns/loops/breaks/jumps/goto's break the constant behavior, therefore you end up with a higher complexity.
  • 0
    @Hammster how do you query which of the n receipt you want? A tree is log(n), but a hashmap isn’t REALLY O(1)...
  • 1
    Also, why are you leaving us hanging? What problem was the algorithm for?
Add Comment