由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问个题目
相关主题
问一题C++ 面试题目分享(1)
一道C面试题Programming interview exposed 上面的那道NULL or Cycle的linked list题
"简单的"linklist的问题How can one determine whether a singly linked list has a cycle?
linklist exercise说一道关于unbalanced树的面试题 (转载)
reverse链表ebay applied researcher
一道G家题目Link nodes at same level in a binary tree 怎么做?
请教linked list, 删除最后一个节点Google Front-end Software Engineer Phone Interview
关于python interviewGiven a node of a tree, find all nodes on the same level
相关话题的讨论汇总
话题: node话题: fastptr话题: nodes话题: cycle话题: number
进入JobHunting版参与讨论
1 (共1页)
h*********y
发帖数: 49
1
suppose that you have a set of nodes with no null pointers (each node points
to itself or to some other node in the set), given a pointer to a node, how
to find the number of different nodes that it ultimately researches by
following links from that node, without modifying any nodes. DO NOT use more
than a constant amount of extra memory space.
s***t
发帖数: 49
2
use a hash-table to store all the visited node, if a hit happens, stop.
The size of the hash-table is the the number of nodes that it ultimately
can reach.

points
how
more

【在 h*********y 的大作中提到】
: suppose that you have a set of nodes with no null pointers (each node points
: to itself or to some other node in the set), given a pointer to a node, how
: to find the number of different nodes that it ultimately researches by
: following links from that node, without modifying any nodes. DO NOT use more
: than a constant amount of extra memory space.

g*******y
发帖数: 1930
3
each node has only one link? then it's the classic problem of detecting
loop in linklist.

points
how
more

【在 h*********y 的大作中提到】
: suppose that you have a set of nodes with no null pointers (each node points
: to itself or to some other node in the set), given a pointer to a node, how
: to find the number of different nodes that it ultimately researches by
: following links from that node, without modifying any nodes. DO NOT use more
: than a constant amount of extra memory space.

c*********n
发帖数: 1057
4
I think the key point is how to fix the cycle with out modifying the list.
Any ideas?

【在 g*******y 的大作中提到】
: each node has only one link? then it's the classic problem of detecting
: loop in linklist.
:
: points
: how
: more

a****n
发帖数: 1887
5
why fix cycle?

【在 c*********n 的大作中提到】
: I think the key point is how to fix the cycle with out modifying the list.
: Any ideas?

z***e
发帖数: 5393
6
你们居然看明白这个题?我就没搞懂在说什么,什么叫“that it ultimately
researches by following links from that node”---这是英语??

points
how
more

【在 h*********y 的大作中提到】
: suppose that you have a set of nodes with no null pointers (each node points
: to itself or to some other node in the set), given a pointer to a node, how
: to find the number of different nodes that it ultimately researches by
: following links from that node, without modifying any nodes. DO NOT use more
: than a constant amount of extra memory space.

s***t
发帖数: 49
7
should be "reach" right? :)

【在 z***e 的大作中提到】
: 你们居然看明白这个题?我就没搞懂在说什么,什么叫“that it ultimately
: researches by following links from that node”---这是英语??
:
: points
: how
: more

c*********n
发帖数: 1057
8
in other words, how to detect the number of nodes before going to the cycle?

【在 a****n 的大作中提到】
: why fix cycle?
a****n
发帖数: 1887
9
for single linkedlist, u don't need that number.
1.
get nodes number in cycle = N
2.
for (fastptr = givennode; fastptr < N; fastptr=fastptr->next)
printnode(fastptr);
3.
slowptr = givennode;
do{
printnode(fastptr)
}while (++fastptr != ++slowptr);

cycle?

【在 c*********n 的大作中提到】
: in other words, how to detect the number of nodes before going to the cycle?
c*********n
发帖数: 1057
10

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~they have the same speed, how to meet?

【在 a****n 的大作中提到】
: for single linkedlist, u don't need that number.
: 1.
: get nodes number in cycle = N
: 2.
: for (fastptr = givennode; fastptr < N; fastptr=fastptr->next)
: printnode(fastptr);
: 3.
: slowptr = givennode;
: do{
: printnode(fastptr)

相关主题
一道G家题目C++ 面试题目分享(1)
请教linked list, 删除最后一个节点Programming interview exposed 上面的那道NULL or Cycle的linked list题
关于python interviewHow can one determine whether a singly linked list has a cycle?
进入JobHunting版参与讨论
a****n
发帖数: 1887
11
cycle length is N

【在 c*********n 的大作中提到】
:
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~they have the same speed, how to meet?

c*********n
发帖数: 1057
12
then?
could you elaborate more?

【在 a****n 的大作中提到】
: cycle length is N
a****n
发帖数: 1887
13
我说的是单链表
第一个指针先走N步(cycle length is N)。
然后两个指针一起走, 第二个指针走到环入口的地方, 第一个指针是不是应该走完了
环。
环入口的地方和出口的地方是同一个node吧
c*********n
发帖数: 1057
14
啊。。。恍然大悟,谢谢

【在 a****n 的大作中提到】
: 我说的是单链表
: 第一个指针先走N步(cycle length is N)。
: 然后两个指针一起走, 第二个指针走到环入口的地方, 第一个指针是不是应该走完了
: 环。
: 环入口的地方和出口的地方是同一个node吧

h*********y
发帖数: 49
15
呵呵,typo,typo
大家都做题做多了,灵犀一点通阿,呵呵

【在 s***t 的大作中提到】
: should be "reach" right? :)
h*********y
发帖数: 49
16
不好意思问句,怎么找出N来?

【在 a****n 的大作中提到】
: for single linkedlist, u don't need that number.
: 1.
: get nodes number in cycle = N
: 2.
: for (fastptr = givennode; fastptr < N; fastptr=fastptr->next)
: printnode(fastptr);
: 3.
: slowptr = givennode;
: do{
: printnode(fastptr)

c*********n
发帖数: 1057
17
1. 2个pointer一起走,一个快一个慢,直到相遇,然后记下这个点
2. 循环一次直到再次走到这个点

【在 h*********y 的大作中提到】
: 不好意思问句,怎么找出N来?
h*********y
发帖数: 49
18
恍然大悟,
谢谢
谢谢

【在 c*********n 的大作中提到】
: 1. 2个pointer一起走,一个快一个慢,直到相遇,然后记下这个点
: 2. 循环一次直到再次走到这个点

1 (共1页)
进入JobHunting版参与讨论
相关主题
Given a node of a tree, find all nodes on the same levelreverse链表
amazon一道面试题一道G家题目
求教一道经典面题的解法请教linked list, 删除最后一个节点
bloomberg onsite题关于python interview
问一题C++ 面试题目分享(1)
一道C面试题Programming interview exposed 上面的那道NULL or Cycle的linked list题
"简单的"linklist的问题How can one determine whether a singly linked list has a cycle?
linklist exercise说一道关于unbalanced树的面试题 (转载)
相关话题的讨论汇总
话题: node话题: fastptr话题: nodes话题: cycle话题: number