当前位置: 首页 > news >正文

手机网站有哪些类型行业门户网站大全

手机网站有哪些类型,行业门户网站大全,电子商务服务平台,字节跳动小程序开发教程树、二叉树、二叉搜索树Description: 描述#xff1a; This article describes how to check whether a given tree is BST or not? This problem came in coding round of Microsoft. 本文介绍如何检查给定的树是否是BST #xff1f; 这个问题来自微软的编码回合。 Probl…树、二叉树、二叉搜索树Description: 描述 This article describes how to check whether a given tree is BST or not? This problem came in coding round of Microsoft. 本文介绍如何检查给定的树是否是BST 这个问题来自微软的编码回合。 Problem Statement: 问题陈述 Given a binary tree check whether it is a binary search tree or not. 给定二叉树请检查它是否为二叉搜索树。 Solution 解 Algorithm: 算法 From the definition of BST, it may seem that for a binary tree to be BST, it’s enough to check for each node if the node on its left is smaller node on its right is greater. But this is actually the wrong approach since it will give wrong output for many test-cases. 从BST的定义来看对于一棵二叉树来说似乎BST足以检查每个节点如果其左侧的节点较小而其右侧的节点较大。 但这实际上是错误的方法因为它将为许多测试用例提供错误的输出。 The correct algorithm is to check for each node whether the maximum of the left subtree is lesser than the node the minimum of the right subtree is greater than the node. This algorithm works perfect but not efficient in terms of time complexity. 正确的算法是检查每个节点的左子树的最大值是否小于该节点以及右子树的最小值是否大于该节点。 该算法在时间复杂度方面工作完美但效率不高。 Intuition says that the in-order traversal for the BST results in a sorted list of nodes and we use this in our algorithm. 直觉说BST的有序遍历会导致节点的排序列表我们在算法中使用了它。 1. Set prev to INT_MIN. 2. From main function call checkBST(root, prev) //passing prev by reference to update it every time checkBST(root, prev) 3. if(rootNULL) return 1; //null tree is BST 4. do in-order traversal and checking whether all tree node data is sorted or not if(!(checkBST(root-left,prev))) //check left subtree return 0; //root-data must be greater than prevsince BST results in //sorted list after in-order traversal. 5. if(root-dataprev) return 0; 6. prevroot-data; //update prev value 7. return checkBST(root-right,prev);//check right subtree .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } Example 1: 范例1 Clearly Example 1 is a binary search tree. We will check out further through our function. 显然示例1是一个二进制搜索树。 我们将通过功能进一步检查。 Example 2: 范例2 Clearly Example 2 is not a binary tree. We will check out through our function. 显然示例2不是二叉树。 我们将通过我们的功能签出。 树的C 类实现 (C class implementation for tree) // tree node is defined class tree{ public: int data; tree *left; tree *right; }; C 函数checkBST实现 (C function checkBST for implementation) //passing reference of prev int checkBST(tree* root,int prev){ //null tree is BST if(rootNULL) return 1; //doing inorder traversal and checking whether //all tree node data is sorted or not if(!(checkBST(root-left,prev))) return 0; if(root-dataprev) return 0; prevroot-data; //update prev value return checkBST(root-right,prev); } 用于创建树节点的C 实现 (C implementation for creating tree nodes) // creating new node tree* newnode(int data) { tree* node (tree*)malloc(sizeof(tree)); node-data data; node-left NULL; node-right NULL; return(node); } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } 主驱动程序功能例如 (Main driver function for example1) #include bits/stdc.h using namespace std; int main() { //**same tree is builted as shown in example** int c,prevINT_MIN;//prev initialized to INT_MIN coutTree is built like the example 1 aforesaidendl; tree *rootnewnode(8); root-left newnode(3); root-right newnode(10); root-right-rightnewnode(14); root-right-right-leftnewnode(13); root-left-leftnewnode(1); root-left-rightnewnode(6); root-left-right-leftnewnode(4); root-left-right-rightnewnode(7); coutbuilting the binary tree like example 1......endl; ccheckBST(root,prev); if(c) coutThis binary tree is binary search treeendl; else coutThis is not a binary search tree; return 0; } 主驱动程序功能例如 (Main driver function for example2) #include bits/stdc.h using namespace std; int main() { //**same tree is builted as shown in example** int c,prevINT_MIN;//prev initialized to INT_MIN coutTree is built like the example 2 aforesaidendl; tree *rootnewnode(2); root-left newnode(7); root-right newnode(5); root-right-rightnewnode(9); root-right-right-leftnewnode(4); root-left-leftnewnode(2); root-left-rightnewnode(6); root-left-right-leftnewnode(5); root-left-right-rightnewnode(11); coutbuilting the binary tree like example 2......endl; ccheckBST(root,prev); if(c) coutThis binary tree is binary search treeendl; else coutThis is not a binary search tree; return 0; } Output 1 输出1 Tree is built like the example 1 aforesaid builting the binary tree like example 1...... This binary tree is binary search tree Output 2 输出2 Tree is built like the example 2 aforesaid builting the binary tree like example 2...... This is not a binary search tree 翻译自: https://www.includehelp.com/icp/check-whether-a-binary-tree-is-bst-binary-search-tree-or-not.aspx树、二叉树、二叉搜索树
http://www.zqtcl.cn/news/634527/

相关文章:

  • 网站解析不了wordpress 密码失败
  • 临沂企业建站系统模板扮家家室内设计
  • 做简单网站用什么软件网站开发国外研究现状
  • 江苏seo推广网站建设湖南软件定制开发
  • 台州商务网站手机端seo
  • 网站的切换语言都是怎么做的有哪些开发网站公司
  • 上海人才中心网站湖州建设公司网站
  • 网站的前台后台网站建设公司新报
  • 菜鸟式网站建设图书深圳建站公司好坏
  • 品牌网站建设熊掌号一级消防工程师考试通过率多少
  • 网站建设淘宝客模板湖口网站建设
  • 拱墅区建设局网站做设计的搜素材上什么网站
  • 济南烨铭网站建设外贸建网站免费模板
  • 那些网站可以做反链浏览器网站大全
  • 泉州网站建设推广企业网页兼容性站点
  • 怎样做视频上网站赚钱推广计划怎么做推广是什么
  • 台州外贸网站建设做网站开发一般用什么语言
  • 咸阳做网站的公司漯河网做网站
  • 红酒网站模板下载做网站加推广
  • 免费网站服务器域名在线手机网站建设
  • 北京网站ui设计公司在线设计装修
  • 大学生网站作业北京网站优化技术
  • 静安区网站开发固原网络推广
  • WordPress网站修改志成网站设计制作
  • 做网站需要注意的昭通网站seo优化
  • 站群软件lanyun网站开发
  • 固始网站制作html美食网页设计源码
  • 软件研发过程管理岳阳seo
  • 舟山网站建设代理门户网站建设流程
  • 天水建设银行网站网站建设方案免费下载