TAILIEUCHUNG - Lecture Data Structures & Algorithms: Chapter 7

Lecture Data Structures & Algorithms: Chapter 7 - Trees presented the concept of trees, binary tree and representation, binary tree traversal, binary search tree. | Data Structures & Algorithms 1 Trees 1. THE CONCEPT OF TREES 2. BINARY TREE AND REPRESENTATION 3. BINARY TREE TRAVERSAL 4. BINARY SEARCH TREE 1. THE CONCEPT OF TREES A tree is a set of one or more nodes T: there is a specially designated node called a root The remaining nodes are partitioned into n disjointed set of nodes T1, T2, ,Tn, each of which is a tree. 1. THE CONCEPT OF TREES Example 1. THE CONCEPT OF TREES It’s not a tree Tree 1. THE CONCEPT OF TREES: Some terminology Root Child (left,right) Parent Leaf node Subtree Ancestor of a node Descendant of a node 1. THE CONCEPT OF TREES Degree of a Node of a Tree The degree of a node of a tree is the number of subtrees having this node as a root. Degree of a Tree The degree of a tree is defined as the maximum of degree of the nodes of the tree Level of a Node level of the root node as 1, and incrementing it by 1 as we move from the root towards the subtrees. 2. BINARY TREE AND REPRESENTATION BINARY TREE no node can have a degree of more than 2. The maximum number of nodes at level i will be 2i−1 If k is the depth of the tree then the maximum number of nodes that the tree can have is 2k − 1 = 2k−1 + 2k−2 + + 20 2. BINARY TREE AND REPRESENTATION BINARY TREE A full binary tree is a binary of depth k having 2k − 1 nodes. If it has < 2k − 1, it is not a full binary tree What is the height h of a full tree with N nodes? The max height of a tree with N nodes is N (same as a linked list) The min height of a tree with N nodes is log(N+1) 2. BINARY TREE AND REPRESENTATION 3=22-1 7=23-1 15=24-1 full binary 2. BINARY TREE AND REPRESENTATION struct node { int data; node *left; node *right; }; Tree traversal Used to print out the data in a tree in a certain order inorder (LDR ) Postorder (LRD ) preorder (DLR ) Pre-order traversal Print the data at the root Recursively print out all data in the left subtree Recursively print out all data in the right subtree Preorder, Postorder and Inorder Preorder traversal node, left, right .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.