输入:a linked list of size n, which is generated from a tree, but not in any order of walks. Each item contains a unique node ID (unsigned integer>=1 ) and its parent's ID. The root has its parent ID to be 0. 输出:a tree structure restored from the linked list, and the root of the tree. 问题:有没有时间空间都为O(n)的算法?
不仅仅是你这问题,就是更复杂点的普通的 object serialization 就是 O (n) 的时间和空间。用个 hash map 而已。
=1
【在 s*******s 的大作中提到】 : 输入:a linked list of size n, which is generated from a tree, but not in : any order of walks. Each item contains a unique node ID (unsigned integer>=1 : ) and its parent's ID. The root has its parent ID to be 0. : 输出:a tree structure restored from the linked list, and the root of the : tree. : 问题:有没有时间空间都为O(n)的算法?
So, what is your requirement for output? Give a parent ID then find all children C in |C| time?
【在 s*******s 的大作中提到】 : Exactly! Here's the definition of the entry of the linked list. : struct Item{ : Item* next; : unsigned int ID; : unsigned int parentID; : };
s*g
21 楼
As long as the two of you still love each other, it is worthy to do whatever to keep the marriage. The two of you got to try hard to keep the communication, and you have to work hard to help her, of course, she has to work hard to help herself too.
s*s
22 楼
To build a tree using the following structure struct Node{ unsigned int ID; Node** pchildren_array; unsigned int child_count; };
【在 p***o 的大作中提到】 : So, what is your requirement for output? : Give a parent ID then find all children C in |C| time?
l*g
23 楼
回国,臭揍一顿再离呀,你这个人怎么这么老实! 不过我发现女人都相似,你下家不见得比她强
r*u
24 楼
Since each item contains a unique ID representing by an unsigned integer, the number of items must be a limited value, which means n must be a limited value. Therefore, you can do it with O(1) space and time complexity (or you can say O(n) if you want since n is limited).
=1
【在 s*******s 的大作中提到】 : 输入:a linked list of size n, which is generated from a tree, but not in : any order of walks. Each item contains a unique node ID (unsigned integer>=1 : ) and its parent's ID. The root has its parent ID to be 0. : 输出:a tree structure restored from the linked list, and the root of the : tree. : 问题:有没有时间空间都为O(n)的算法?
问离不离的问题不重要。怎么解决问题是关键啊。 Be a real man!! 用上你的 leadership:"胡箩卜+大棒子",哄着她读书上学,哪怕自费也值。 一来,她有事做,发的火就少. 二来,你MS受点苦,但做到仁致义尽,攒RP啊。 三来,现在出的钱,MS多,但与将来可能出现的赡养费之类的比,算个鸟鸟啊? 四来,双方独立,即使离,也容易和平解决。 口口声声的说"爱"不行啊。 爱,不是XX,不是按摩,等等感觉, 爱,是能力。
agree with the upstairs. The approach by the wife is wrong. If you cannot adapt it, then make your mind. There is zero chance you can change your wife, vice versa.