File: root - text - article - 2019 - 10 - find-cycles-in-a-graph.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | English | Home Page | Category: Computing | 386 Views, 20314 Search Bots | 72 Words
| Browse | Archive
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | English | Home Page | Category: Computing | 386 Views, 20314 Search Bots | 72 Words
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
Hi, here's your problem today. This problem was recently asked by Facebook:
Given an undirected graph, determine if a cycle exists in the graph.
Here is a function signature:
Can you solve this in linear time, linear space?
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | English | Home Page | Cateogry: Computing | 386 Views, 20314 Search Bots | 72 Words Given an undirected graph, determine if a cycle exists in the graph.
Here is a function signature:
def find_cycle(graph):
# Fill this in.
graph = {
'a': {'a2':{}, 'a3':{} },
'b': {'b2':{}},
'c': {}
}
print find_cycle(graph)
# False
graph['c'] = graph
print find_cycle(graph)
# True
Can you solve this in linear time, linear space?
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
Related Articles
- Generate All IP Addresses
- Daily Interview Problem: Product of Array Except Self
- Delphi Dynamic Array
- Daily Interview Problem: Reverse Words in a String
- Absolute Path
- [Daily Problem] Longest Increasing Subsequence
- [Daily Problem] Add two numbers as a linked list
- Daily Interview Problem: Reconstrunct Binary Tree from Preorder and Inorder Traversals
- Daily Interview Problem: Jump to the End
- Invert a Binary Tree
©2006~2024 SteakOverCooked - 0.01602 Seconds(s) - 1222.227 KB/s - 15 Online
Memory: 496.7 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">
![](/images/top.jpg)
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !