找出组的标识元素的算法?

时间:2013-10-27 14:54:52

标签: algorithm pseudocode

我做了类似的事(伪代码):

 for x = 0 to 3
  for y = 0 to 3
    id1 = m[x][y] * m[y][x];
    id2 = m[y][x] * m[x][y];
    if id1 != m[x][y] or id1 != id2 then
      nn = nn + 1;
    else
      en = id1;
    endif
  endfor
 endfor
 if nn = 0 then
      print("There is an identity element: ", en);
      a := a + 1;
 else
      print("There isn't an identity element.");
 endif

当我运行它时,使用1,2,3,4作为我的设置和乘法作为操作,它返回“没有标识元素。”,所以我猜我的逻辑在这里有问题。有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

你经常增加nn。因此,您几乎总能找到nn!= 0.因此,您的代码几乎总会得出结论,即没有身份。恕我直言,你的整个逻辑完全不清楚,因为已经不清楚id1和id2是什么了。它从m [x] [y]实际上是什么开始。

您还应该考虑完全避免暴力搜索。那就是:如果G是有限群,根据Lagrange's theorem,对于G中的每个x,你有x ^ | G | = e。因此,您可以直接计算e。如果你事先不知道G是否是一个群,那么x ^ | G |仍然是唯一可能的候选人。