20172304 Summary of the sixth week of program design and data structure

Source: Internet
Author: User
20172304 Summary of the sixth week of program design and data structure

This week, I learned about the tree content. The tree consists of nodes and edges. The lower-layer node in the tree is the child of the upper node. A node has only one parent. The two nodes with the same parent are called brothers. A node without any children is called a leaf. A non-root node with at least one child is called an internal node. If a node is located on another node in the path starting from the beginning, the node is its ancestor. The node that can be reached along the path of a specific node is the child of the node.
10.1.1 Tree Classification
The maximum number of children that any node in the tree can have. The unlimited number of children contained in a node is called a generalized tree. Each node is first called an N-yuan tree for a tree with no more than N children. A tree with a maximum of two children is called a binary tree. If all the leaves of a tree are on the same layer or at least each other is not more than one layer, it is called a balance. The height of a balanced N-element Tree Containing M nodes is lognm.
Full tree: If a tree is balanced and all the leaves are on the left of the tree, the tree is considered completely. The full tree has 2 ^ K nodes on each k layer.
Full tree: A tree is full if all the leaves of a tree N and a metatree are on the same layer and no node is either a leaf or have exactly n Children.
10.2 implement the tree Policy
The array of the 10.2.1 tree implements a value calculation policy.
Use arrays to store a tree: For any element stored at position N of the array, the left child of the element is stored at position 2n + 1, the right child of the element is stored in the location (2 × n + 1.
Simulation of link strategy for Array Implementation of 10.2.2 numbers
Tree traversal: pre-order traversal, middle-order traversal, post-order traversal, and sequence traversal.

Name Content
Forward Traversal Access each node and its children from the root node
Sequential Traversal Starting from the root node, access the left child of the node, then the node, and then any remaining node.
Post-order traversal Start from the root node, access the child of the node, and then the node.
Sequence Traversal Access all nodes of each layer from the root node Kass and one layer at a time

Forward Traversal

Visit node Traverse(left child)Traverse(right child)

Sequential Traversal

Traverse(left child)Visit node Traverse(right child)

Sequence Traversal

Create a queue called nodesCreate an unordered list called resultsEnqueue the root onto the nodes queueWhile the root onto the nodes queueWhile the nodes queue is not empty {     Dequeue the first element from the  queue     If that element is not null         Add that element to the rear of the results list         Enqueue the children of the element      Else         Add null on the result list  }Return an iterator for the result list

10.4 Binary Tree
Binary Tree Operation Method

Operation Description
Getroot Returns a reference pointing to a binary tree.
Isempty Determines whether the tree is empty.
Size Number of elements in the decision tree
Contains Determine whether the target is in the tree
Find If a specified element is found, a reference pointing to it is returned.
Tostring Returns the string representation of the tree.
Itertorinorder Returns an iterator for the middle-order traversal of the tree.
Itertorpreorder Returns an iterator for the previous traversal of the tree.
Itertorpostorder Returns an iterator for subsequent tree traversal.
Itertorlevelorder Returns an iterator for tree sequence traversal.

Binary Tree application: Expression Tree, back pain diagnoses
Binary Tree using linked list

Problems and Solutions in teaching material Learning
  • Question 1:
  • Problem 1 solution:
  • Question 2:
  • Problem 2 solution:
Issues and Solutions in code debugging
  • Question 1: xxxxxx
  • Problem 1 solution: xxxxxx
  • Question 2: xxxxxx
  • Problem 2 solution: xxxxxx

    Summary of incorrect questions

Code hosting

(Running result of statistics. Sh script)

Summary of last week's exam errors

-Incorrect Question 1

-Q: the reason for this error is that I mistakenly regard the time complexity of the search in the book as the time complexity of the binary tree. The time complexity of the List is related to the search method, but the binary tree search must traverse each element. Therefore, the time complexity should be O (n ).

  • Error 2

    -Answer: if the error occurs, continuous allocation is not allowed.
  • Error 3

    -Answer: traverse the left child of the node starting from the root node in the middle order, then the node, and then any remaining node.
Blog and code commented on by students
  • Blog peer evaluation last week
    20172304 Guo Kai's blog is excellent. He summarized the teaching materials carefully and gave in-depth thoughts and answers to the problems he found in the teaching materials. The whole process looks pleasing to the eye and gives us a wonderful experience.
    20172328 Li Xinyu's blog is complete and rich, reflecting her earnest learning attitude.

    Others (perception, thinking, etc., optional)

    After learning about the tree this week, the tree is not so much a data structure as a logical structure. It is built on the basic data structure, such as arrays, stacks, or linked lists. The wood of the hug, born at the end of the ml; the Nine-layer platform, starting from the ground; a journey of thousands of miles, began in the foot. Only after full accumulation. Only by fully learning the basic data structure can we make more excellent code. In order to build socialism with Chinese characteristics better.

Learning progress bar
Number of lines of code (Add/accumulate) Blog volume (New/accumulated) Learning time (Add/accumulate) Important Growth
Target 5000 rows 30 articles 400 hours
WEEK 1 30/30 1/1 10/10
Week 2 766/796 1/2 40/50
Week 3 817/1613 1/3 20/70
Week 4 1370/3983 2/5 30/100
Week 5 1235/5214 1/6 10/110
Week 6

20172304 Summary of the sixth week of program design and data structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.