Post-order traversal sequence of the Binary Search Tree

Source: Internet
Author: User

Enter an integer array to determine whether the array is the result of a sorted traversal of a binary search tree. If Yes, Yes is output; otherwise, No is output. Assume that any two numbers in the input array are different. Input: each test case contains two rows. The first row is an integer of n (1 <= n <= 10000), indicating the length of the array. The second row contains n integers, indicating the array. The value range of the number in the array is [0,]. Output: corresponds to each test case. If the input array is a result of a forward traversal of a binary search tree, Yes is output; otherwise, No is output. Sample input: 75 7 6 9 11 10 847 4 6 5 sample output: YesNo code AC: idea: the tree needs to be traversed. The binary tree is characterized by lchild. key <root. key <rchild. then we use the sub-governance idea to separate left and right sub-trees by using the above features. The first sub-tree is greater than root. after the key (right side) is the sub-tree, If we encounter less than root when traversing the sub-tree. in the case of key, it is the wrong sequence .... [Cpp] // use sub-governance! # Include <stdio. h> # include <stdlib. h> long int * num; int fun (long int low, long int high) {long int I, l, tmp_idx, flag = 1; if (low> = high) {return 1 ;}for (I = low; I

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.