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

微信小程序是什么意思?有什么用网站seo提升

微信小程序是什么意思?有什么用,网站seo提升,了解网站开发流程,网站找谁备案文章目录 1. 二叉搜索树1.1 二叉搜索树概念1.2 二叉搜索树的查找1.3 二叉搜索树的插入1.4 二叉搜索树的删除 2 二叉搜索树的实现3 二叉搜索树的应用3.1二叉搜索树的性能分析 1. 二叉搜索树 1.1 二叉搜索树概念 二叉搜索树又称二叉排序树,它或者是一棵空树&#xf…

文章目录

  • 1. 二叉搜索树
    • 1.1 二叉搜索树概念
    • 1.2 二叉搜索树的查找
    • 1.3 二叉搜索树的插入
    • 1.4 二叉搜索树的删除
  • 2 二叉搜索树的实现
  • 3 二叉搜索树的应用
    • 3.1二叉搜索树的性能分析

1. 二叉搜索树

1.1 二叉搜索树概念

二叉搜索树又称二叉排序树,它或者是一棵空树,或者是具有以下性质的二叉树:

  1. 若它的左子树不为空,则左子树上所有节点的值都小于根节点的值。
  2. 若它的右子树不为空,则右子树上所有节点的值都大于根节点的值。
  3. 它的左右子树也分别为二叉搜索树。

在这里插入图片描述

1.2 二叉搜索树的查找

a、从根开始比较,查找,比根大则往右边走查找,比根小则往左边走查找。
b、最多查找高度次(最高位O(N)),走到到空,还没找到,这个值不存在。

1.3 二叉搜索树的插入

插入的具体过程如下:
a. 树为空,则直接新增节点,赋值给root指针
b. 树不空,按二叉搜索树性质查找插入位置,插入新节点
在这里插入图片描述

1.4 二叉搜索树的删除

首先查找元素是否在二叉搜索树中,如果不存在,则返回, 否则要删除的结点可能分下面四种情
况:

a. 要删除的结点无孩子结点
b. 要删除的结点只有左孩子结点
c. 要删除的结点只有右孩子结点
d. 要删除的结点有左、右孩子结点
看起来有待删除节点有4中情况,实际情况a可以与情况b或者c合并起来,因此真正的删除过程
如下:
情况b:删除该结点且使被删除节点的双亲结点指向被删除节点的左孩子结点–直接删除
情况c:删除该结点且使被删除节点的双亲结点指向被删除结点的右孩子结点–直接删除
情况d:在它的右子树中寻找中序下的第一个结点(关键码最小),用它的值填补到被删除节点
中,再来处理该结点的删除问题–替换法删除。
在这里插入图片描述

2 二叉搜索树的实现

template<class K>
struct BSTreeNode
{BSTreeNode* _left;BSTreeNode* _right;K _key;BSTreeNode(const K& key):_left(nullptr), _right(nullptr), _key(key){}
};
template<class K>
struct BSTree
{typedef BSTreeNode<K> Node;
public:BSTree():_root(nullptr){}bool insert(const K& key){if (_root == nullptr){_root = new Node(key);return true;}Node* parent = nullptr;Node* cur = _root;while (cur){if (cur->_key < key){parent = cur;cur = cur->_right;}else if (cur->_key > key){parent = cur;cur = cur->_left;}elsereturn false;}cur = new Node(key);if (parent->_key < key){parent->_right = cur;}elseparent->_left = cur;return true;}bool Find(const K& key){Node* cur = _root;while (cur){if (cur->_key > key)cur = cur->_left;else if (cur->_key < key)cur = cur->_right;elsereturn true;}return false;}bool Erase(const K& key){Node* parent = nullptr;Node* cur = _root;while (cur){if (cur->_key > key){parent = cur;cur = cur->_left;}else if (cur->_key < key){parent = cur;cur = cur->_right;}else//找到了{if (cur->_left == nullptr)//左为空{if (cur == _root){_root = _root->_right;}else{if (parent->_right == cur){parent->_right = cur->_right;}else{parent->_left = cur->_right;}}}else if (cur->_right == nullptr)//右为空{if (cur == _root){_root = _root->_left;}else{if (parent->_right = cur){parent->_right = cur->_left;}else{parent->_left = cur->_left;}}}else//左右都不为空{Node* parent = cur;Node* LeftMax = cur->_left;while (LeftMax->_right){parent = LeftMax;LeftMax = LeftMax->_right;}swap(cur->_key, LeftMax->_key);if (parent->_left == LeftMax){parent->_left = LeftMax->_left;}else{parent->_right = LeftMax->_left;}cur = LeftMax;}delete cur;return true;}}return false;}void InOrder(){_InOrder(_root);cout << endl;}void _InOrder(Node* root){if (root == NULL){return;}_InOrder(root->_left);cout << root->_key << " ";_InOrder(root->_right);}
private:Node* _root;
};void TestBSTree1()
{int a[] = { 8, 3, 1, 10, 6, 4, 7, 14, 13 };BSTree<int> t;for (auto e : a){t.insert(e);}t.InOrder();t.Erase(4);t.InOrder();t.Erase(6);t.InOrder();t.Erase(7);t.InOrder();t.Erase(3);t.InOrder();for (auto e : a){t.Erase(e);}t.InOrder();
}

3 二叉搜索树的应用

  1. K模型:K模型即只有key作为关键码,结构中只需要存储Key即可,关键码即为需要搜索到
    的值。
    比如:给一个单词word,判断该单词是否拼写正确,具体方式如下:
    以词库中所有单词集合中的每个单词作为key,构建一棵二叉搜索树
    在二叉搜索树中检索该单词是否存在,存在则拼写正确,不存在则拼写错误。
  2. KV模型:每一个关键码key,都有与之对应的值Value,即<Key, Value>的键值对。该种方
    式在现实生活中非常常见:
    比如英汉词典就是英文与中文的对应关系,通过英文可以快速找到与其对应的中文,英
    文单词与其对应的中文<word, chinese>就构成一种键值对;
    再比如统计单词次数,统计成功后,给定单词就可快速找到其出现的次数,单词与其出
    现次数就是<word, count>就构成一种键值对。
以下是完整的代码,包括改造二叉搜索树为KV结构、测试二叉搜索树的函数和主函数:cpp
#include <iostream>  
#include <string>  using namespace std;  template<class K, class V>  
struct BSTNode  
{  BSTNode(const K& key = K(), const V& value = V())  : _pLeft(nullptr) , _pRight(nullptr), _key(key), _value(value)  {}  BSTNode<K, V>* _pLeft;  BSTNode<K, V>* _pRight;  K _key;  V _value;  
};  template<class K, class V>  
class BSTree  
{  
public:  typedef BSTNode<K, V> Node;  typedef Node* PNode;  
public:  BSTree(): _pRoot(nullptr){}  PNode Find(const K& key){Node* cur = _root;while (cur){if (cur->_key < key){cur = cur->_right;}else if (cur->_key > key){cur = cur->_left;}else{return true;}}return false;}bool Insert(const K& key, const V& value){if (_root == nullptr){_root = new Node(key);return true;}Node* parent = nullptr;Node* cur = _root;while (cur){if (cur->_key < key){parent = cur;cur = cur->_right;}else if (cur->_key > key){parent = cur;cur = cur->_left;}else{return false;}}cur = new Node(key);if (parent->_key < key){parent->_right = cur;}else{parent->_left = cur;}return true;}bool Erase(const K& key){Node* parent = nullptr;Node* cur = _root;while (cur){if (cur->_key < key){parent = cur;cur = cur->_right;}else if (cur->_key > key){parent = cur;cur = cur->_left;}else // 找到了{// 左为空if (cur->_left == nullptr){if (cur == _root){_root = cur->_right;}else{if (parent->_right == cur){parent->_right = cur->_right;}else{parent->_left = cur->_right;}}}// 右为空else if (cur->_right == nullptr){if (cur == _root){_root = cur->_left;}else{if (parent->_right == cur){parent->_right = cur->_left;}else{parent->_left = cur->_left;}}} // 左右都不为空 else{// 找替代节点Node* parent = cur;Node* leftMax = cur->_left;while (leftMax->_right){parent = leftMax;leftMax = leftMax->_right;}swap(cur->_key, leftMax->_key);if (parent->_left == leftMax){parent->_left = leftMax->_left;}else{parent->_right = leftMax->_left;}cur = leftMax;}delete cur;return true;}}return false;}  
private:  PNode _pRoot;  
};  

3.1二叉搜索树的性能分析

插入和删除操作都必须先查找,查找效率代表了二叉搜索树中各个操作的性能。
对有n个结点的二叉搜索树,若每个元素查找的概率相等,则二叉搜索树平均查找长度是结点在二
叉搜索树的深度的函数,即结点越深,则比较次数越多。
但对于同一个关键码集合,如果各关键码插入的次序不同,可能得到不同结构的二叉搜索树:
在这里插入图片描述
最优情况下,二叉搜索树为完全二叉树(或者接近完全二叉树),其平均比较次数为: l o g 2 N log_2 N log2N
最差情况下,二叉搜索树退化为单支树(或者类似单支),其平均比较次数为: N 2 \frac{N}{2} 2N
问题:如果退化成单支树,二叉搜索树的性能就失去了。那能否进行改进,不论按照什么次序插
入关键码,二叉搜索树的性能都能达到最优?AVL树和红黑树就可以上场了。


文章转载自:
http://cyanoguanidine.xxhc.cn
http://sensibility.xxhc.cn
http://heterophoric.xxhc.cn
http://terrain.xxhc.cn
http://adenoacanthoma.xxhc.cn
http://attenuant.xxhc.cn
http://unmentioned.xxhc.cn
http://toehold.xxhc.cn
http://stemmed.xxhc.cn
http://bias.xxhc.cn
http://foliaceous.xxhc.cn
http://disproportional.xxhc.cn
http://perforative.xxhc.cn
http://platform.xxhc.cn
http://baloney.xxhc.cn
http://mayoralty.xxhc.cn
http://caballero.xxhc.cn
http://volatilization.xxhc.cn
http://favorableness.xxhc.cn
http://retentive.xxhc.cn
http://politic.xxhc.cn
http://kingstown.xxhc.cn
http://piccalilli.xxhc.cn
http://implantable.xxhc.cn
http://angiotensin.xxhc.cn
http://velamen.xxhc.cn
http://thalassochemical.xxhc.cn
http://hacendado.xxhc.cn
http://tempo.xxhc.cn
http://boarhound.xxhc.cn
http://overmuch.xxhc.cn
http://hohum.xxhc.cn
http://awed.xxhc.cn
http://fishyback.xxhc.cn
http://trimethylamine.xxhc.cn
http://unnumbered.xxhc.cn
http://capsulate.xxhc.cn
http://fitly.xxhc.cn
http://ratiocinate.xxhc.cn
http://inbreath.xxhc.cn
http://loamy.xxhc.cn
http://lobo.xxhc.cn
http://tonette.xxhc.cn
http://ceroma.xxhc.cn
http://disappearance.xxhc.cn
http://gollop.xxhc.cn
http://raciness.xxhc.cn
http://meridian.xxhc.cn
http://formulize.xxhc.cn
http://thermogenesis.xxhc.cn
http://ultraclean.xxhc.cn
http://discretional.xxhc.cn
http://gt.xxhc.cn
http://scunner.xxhc.cn
http://maggotry.xxhc.cn
http://echograph.xxhc.cn
http://dipsy.xxhc.cn
http://undergraduette.xxhc.cn
http://sinbad.xxhc.cn
http://distributing.xxhc.cn
http://theirs.xxhc.cn
http://asphaltic.xxhc.cn
http://eai.xxhc.cn
http://escape.xxhc.cn
http://geode.xxhc.cn
http://didactic.xxhc.cn
http://herpetic.xxhc.cn
http://jokester.xxhc.cn
http://draghound.xxhc.cn
http://godling.xxhc.cn
http://stallage.xxhc.cn
http://reconciliation.xxhc.cn
http://pressurize.xxhc.cn
http://haeckelian.xxhc.cn
http://girly.xxhc.cn
http://maturity.xxhc.cn
http://bania.xxhc.cn
http://resolve.xxhc.cn
http://babirusa.xxhc.cn
http://caducous.xxhc.cn
http://papoose.xxhc.cn
http://occasionally.xxhc.cn
http://millwright.xxhc.cn
http://conkers.xxhc.cn
http://delimitation.xxhc.cn
http://subway.xxhc.cn
http://encapsule.xxhc.cn
http://northwestern.xxhc.cn
http://fluviology.xxhc.cn
http://discomfortable.xxhc.cn
http://twice.xxhc.cn
http://irvine.xxhc.cn
http://impenetrate.xxhc.cn
http://familistic.xxhc.cn
http://assify.xxhc.cn
http://fagin.xxhc.cn
http://abidjan.xxhc.cn
http://felid.xxhc.cn
http://millenary.xxhc.cn
http://thasos.xxhc.cn
http://www.dt0577.cn/news/96782.html

相关文章:

  • jsp网站建设技术案例网络优化师
  • 宿州做网站的有吗百度推广电话号码
  • 沌口网站建设西安百度seo推广电话
  • 做网站必须要切图吗企业推广方法
  • 如何注销网站备案号百度热搜大数据
  • 沈阳建设工程信息网还需要造价员西安网络优化哪家好
  • 遵义市住房城乡建设局网站seo整体优化
  • 连云港建设局网站助理域名查询网站
  • 网站开发与技术seo推广如何做
  • 高端网站建设服务超级优化大师下载
  • 用KEGG网站做KEGG富集分析优网营销
  • 嘉兴做微网站多少钱大数据是干什么的
  • 网站开发培训多少钱全网推广
  • wordpress高度还原设计稿快速提高网站关键词排名优化
  • 收录好的博客网站吗友情链接免费发布平台
  • 自动引流免费app重庆seo顾问服务
  • 国外网站404错误页百度搜索引擎优化
  • 专业做网站套餐求老哥给几个靠谱的网站
  • 哪些彩票网站可做代理赚钱百度应用商店
  • 网站设计分类腾讯企业qq官网
  • java做的网站实例培训行业seo整站优化
  • 花生壳做网站有流量限制彼亿营销
  • 网站开发周期是什么意思电商平台怎么加入
  • 怎么做内网网站广州seo优化外包公司
  • 凡科网站能在百度做推广吗手机端搜索引擎排名
  • php网站超市源码免费网站alexa排名查询
  • 在工行网站上如何做现金理财腾讯云域名注册官网
  • 网站设计时尚网络营销事件
  • 改进网站的建议百度关键词购买
  • 微网站特点2022推广app赚佣金平台