• Victor@lemmy.world
    link
    fedilink
    arrow-up
    44
    arrow-down
    1
    ·
    edit-2
    8 days ago

    How in the hell does anyone f— up so bad they get O(n!²)? 🤯 That’s an insanely quickly-growing graph.

    Curious what the purpose of that algorithm would have been. 😅

    • magic_lobster_party@kbin.run
      link
      fedilink
      arrow-up
      32
      ·
      8 days ago

      You have two lists of size n. You want to find the permutations of these two lists that minimizes a certain distance function between them.

      • catastrophicblues@lemmy.ca
        link
        fedilink
        arrow-up
        2
        ·
        7 days ago

        Surely you could implement this via a sorting algorithm? If you can prove the distance function is a metric and both lists contains elements from the same space under that metric, isn’t the answer to sort both?

    • petersr@lemmy.world
      link
      fedilink
      arrow-up
      23
      ·
      8 days ago

      Let me take a stab at it:

      Problem: Given two list of length n, find what elements the two list have in common. (we assume that there are not duplicates within a single list)

      Naive solution: For each element in the first list, check if it appears in the second.

      Bogo solution: For each permutation of the first list and for each permutation of the second list, check if the first item in each list is the same. If so, report in the output (and make sure to only report it once).

      • Victor@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        7 days ago

        lol, you’d really have to go out of your way in this scenario. First implement a way to get every single permutation of a list, then to ahead with the asinine solution. 😆 But yes, nice one! Your imagination is impressive.

      • Victor@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        7 days ago

        I guess, yeah, that’ll do it. Although that’d probably be yet one or a few extra factors involving n.