小编Vla*_*che的帖子

图中的后边缘

我很难理解Tarjan的发音点算法。我目前在这里关注此教程:https : //www.hackerearth.com/practice/algorithms/graphs/articulation-points-and-bridges/tutorial/。我真正看不到的东西,以及在其他任何教程中都看不到的东西,正是“后边缘”的含义。考虑到此处给出的图形,我知道3-1和4-2是后边缘,但是2-1、3-2和4-3也是后边缘吗?谢谢。在此处输入图片说明

algorithm graph-theory graph depth-first-search tarjans-algorithm

5
推荐指数
2
解决办法
4201
查看次数

这里计算(+1)多少次?

在我的函数式编程考试中,我有以下问题:

以下代码中,(+ 1)个函数计算了多少次?

(map (+ 1) [1 .. 10]) !! 5
Run Code Online (Sandbox Code Playgroud)

索引函数的定义如下:

(h:_) !! 0 = h
(_:t) !! x = t !! (x-1)
Run Code Online (Sandbox Code Playgroud)

我会说6次,但正确答案似乎是1次,我不明白为什么。我在Haskell中找不到足够好的解释懒惰的评估,所以我想知道什么是正确的答案以及为什么。先感谢您!

haskell functional-programming lazy-evaluation ghc

5
推荐指数
2
解决办法
109
查看次数

为什么 os.scandir() 和 os.listdir() 一样慢?

我尝试在 Windows 上使用 os.scandir() 而不是 os.listdir() 来优化用 Python 编写的文件浏览功能。但是,时间保持不变,大约2分半钟,我不知道为什么。以下是原始和修改的功能:

os.listdir() 版本:

def browse(self, path, tree):
    # for each entry in the path
    for entry in os.listdir(path):
        entity_path = os.path.join(path, entry)
        # check if support by git or not
        if self.git_ignore(entity_path) is False:
            # if is a dir create a new level in the tree
            if os.path.isdir( entity_path ):
                tree[entry] = Folder(entry)
                self.browse(entity_path, tree[entry])
            # if is a file add it to the tree
            if os.path.isfile(entity_path):
                tree[entry] = File(entity_path)
Run Code Online (Sandbox Code Playgroud)

os.scandir() 版本: …

python windows filesystems scandir listdir

5
推荐指数
1
解决办法
1707
查看次数

Haskell中的"多种类型"

我对函数式编程和Haskell都很陌生,所以我不确定我是否正确地提出了这个问题,或者它是否有意义,但我决定尝试,因为我没有找到任何有用的东西.我基本上试图实现一个可以返回a Int,a String或List 的函数.我知道我可以用它Either来返回两种类型中的一种,但我想返回三种或更多种中的一种.我尝试定义一个新类型,但我卡住了.

data Rets = Int | String | Bool

checkInt :: Rets -> Bool
check x = case x of
    Int x -> True
Run Code Online (Sandbox Code Playgroud)

checkInt应该返回,True如果给出Int,它只是为了测试,但无论如何我包括它.

我知道我的问题很乱,所以我会感谢任何解释.提前致谢!

haskell functional-programming

1
推荐指数
1
解决办法
118
查看次数