Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
Update google面经集合.py
Browse files Browse the repository at this point in the history
  • Loading branch information
UmassJin committed Aug 12, 2015
1 parent f78ef96 commit 8bbfb50
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Experience/google面经集合.py
Original file line number Diff line number Diff line change
Expand Up @@ -4302,8 +4302,22 @@ def compress_string(string):
You can assume you are given a function to fetch the page and extract the inner links, e.g.:
List<String> fetchPageAndExtractUrls(String url);
'''
def fetch_pages(url):
visited = {}
total_url = [0]
fetch_helper(url, total_url, visited)
return total_url[0]


def fetch_helper(url, total_url, visited):
children = fetchPageAndExtractUrls(url)
if not children:
return
for child in children:
if child not in visited:
visited[child] = True
total_url[0] += 1
fetch_helper(child, total_url, visited)


'''
137.
Expand All @@ -4315,7 +4329,16 @@ def compress_string(string):
I load an arbitrary unknown program onto this computer..
How long do we have to wait in wall-clock time before we can prove the program has an infinite loop?
'''
因为数据和程序都在内存中,所以,如果在某这两个时间点,内存中的内容处于完全相同的状态,
那么从这两个时间点之后的所有状态也一定会完全相同(除非这是台量子计算机)。
那么,如果一个程序在开始执行之后,内存先后出现两个完全相同的状态的话,那么这个程序一定是死循环。.

1kilobyte = 2^13 bit, 所以该计算机内存可能存在的不同状态是2^14种。
因为每次instruction都一定会改变内存的状态(因为但凡有一次不改变,那就已经死循环了),
所以这个计算机最大能执行的不相同操作是2^14次(因为如果程序在2^14次操作中还没能停机,
那第2^14+1次操作一定和之前的2^14次操作中的某一个相同)。
又因为运行速度是1秒10^6 = 2^20次操作,因此在2^(-6) = 0.016秒内,就能够进行2^14次操作。
也就是说,如果0.016秒内还没能停下的程序,就永远不会停下了。


========================================================================================
Expand Down

0 comments on commit 8bbfb50

Please sign in to comment.