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 | 619 Views, 23699 Search Bots | 72 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | English | Home Page | Category: Computing | 619 Views, 23699 Search Bots | 72 Words
| Browse | Archive
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 | 619 Views, 23699 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?
Related Articles
- Sort a Partially Sorted List
- Making a Height Balanced Binary Search Tree
- Plus One
- New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
- Daily Interview Problem: Full Binary Tree
- Spectrum Master
- Algorithm Interview Question: Max and Min with Limited Comparisons
- Daily Interview Problem: Given two arrays, write a function to compute their intersection.
- [Daily Problem] Longest Palindromic Substring
- [Daily Problem] Remove Consecutive Nodes that Sum to 0
©2006~2024 SteakOverCooked - 0.00816 Seconds(s) - 2235.03 KB/s - 25 Online Memory: 491.82 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="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !