필터 지우기
필터 지우기

Binary Search Tree from vector of parent pointers

조회 수: 2 (최근 30일)
Wajahat
Wajahat 2012년 10월 19일
Hi
I have a vector of parent pointers [ 0 1 1 2 2 3 3 5 5 ....] which is basically a binary tree. The index is the child and the corresponding value represents the index of its parent in the same vector.
e.g: in the above vector, if you count to index 5, the element is 2, which means that its parent lies at index 2. Again at index 2, the element is 1 which means the parent lies at index 1. At index 1 is the element is 0 which is the root node.
How can I create a binary search tree from this?
OR,
I am generating data in binary tree format in which I know the parent and corresponding children.
How can I store them in a binary search tree?
Index for children will always be greater than the parent, as shown in the vector above.
Best Regards
Wajahat
  댓글 수: 1
Doug Hull
Doug Hull 2012년 10월 23일
What is the purpose of this model? Simply for display, for later search, etc? The answer to that question will determine the best representation.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by