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

网站模板提供源码网站排名优化教程

网站模板提供源码,网站排名优化教程,东莞公司网站建设,宁波网站建设公司排名1.二叉查找树: 为了更好的实现动态的查找(可以插入/删除),并且不超过logn的时间下达成目的 定义: 二叉查找树(亦称二叉搜索树、二叉排序树)是一棵二叉树,其各结点关键词互异,且中根序列按其关键词递增排列。 等价描述: 二叉查找…

1.二叉查找树:

为了更好的实现动态的查找(可以插入/删除),并且不超过logn的时间下达成目的

定义: 二叉查找树(亦称二叉搜索树、二叉排序树)是一棵二叉树,其各结点关键词互异,且中根序列按其关键词递增排列。

等价描述: 二叉查找树中任一结点P,其左子树中结点的关键词都小于P的关键词,右子树中结点的关键词都大于P的关键词,且结点P的左右子树也都是二叉查找树。

节点:
BTSTreenode,有左右子树,有键值

有的操作是:

查找,插入和删除,

其他的创建和排序都可以通过上述完成

1,查找:

通过和当前的节点比较大小,来确定之后是:F.返回答案S.去更小的左边,T.去更大的右边

BSTnode* Search(BSTnode* root, int K){

if (root == NULL || root->key == K) return root;

if (K < root->key) return Search(root->left, K);

else return Search(root->right, K);

}

2,插入

根据和左右比较的方法来选择左边还是右边插入,但是不会插入相同的节点

可以引用实现,也可以是返回值实现

引用:
void insert(node*& root,int k){

If(root==NULL||root->val==k){

root=new node(k);

Return;

}
If(k>root->k)insert(root->left,k);

Else insert(root->right,k);

}

返回:
node* insert(node* root,int k){

If(root==NULL)return new node(k);

If(root->val==k)return root;

If(root->val>k)root->right=insert(root->right,k);

Else root->left=insert(root->left,k);

Return root;

}

3,删除,就是通过查找,然后判断:

,没有子树,直接删除

,有一个子树,直接上提

,两个子树,让右边最小的节点s上提到当前位置,之后删除S

void remove(BSTnode* &root, int K) {

if(root==NULL) return;

if(K<root->key) remove(root->left, K); //在左子树删K

else if(K>root->key) remove(root->right, K); //在右子树删K

else if(root->left!=NULL && root->right!=NULL){ //非根节点删除

BSTnode *s=root->right;

while(s->left!=NULL) s=s->left;

root->key=s->key; //s为t右子树中根序列第一个结点

remove(root->right, s->key);

}

else{ //根节点删除

BSTnode* oldroot=root;

root=(root->left!=NULL)? root->left:root->right;

delete oldroot;

}

}

numofBST

F[i]=f[i-1]*(4*i-2)/(i+1)

二叉查找树总结

➢则由n个互异关键词随机生成的二叉查找树,平均高度为O(logn) 

➢查找、插入、删除平均时间复杂度O(logn),但最坏情况时间复杂度为O(n)

2,高度平衡树:(AVL)

为了防止出现二叉查找树发生左/右偏的情况出现的,让一个树的左右高度相差不大于1

平衡系数:左子树高度-右子树高度

高度为h的AVL至少有

所以n>=2^(h/2),同理,h<=2logn

一颗AVL平均比完全二叉树高44%

节点AVLnode 记录的信息是键值,高度,左右子树

初始的时候每个节点的高度是0,空节点的高度为-1

具体操作:

1,计算高度

Int update_H(node* t){

If(t==NULL)return -1;

Int l=update_H(t->left);

Int r=update_H(t->right);

  1. >height=max(l,r)+1;

Return t->height;

}

Int Height(node* a){

Return a==NULL?-1”a->height;

}

2,旋转操作:

当前子树为root
左边的子树的高度为l1,右边为r1

2.1左边更高

2.1.1 左边的左边发生了插入,让左边提升

我们需要把B提升,A下降然后b右子树变成a的左子树

插入前后我们发现,高度没变

Void LL(node* & A){

Node* B=a->left;

  1. >left=B->right;
  2. >right=A;

Update_H(A);

Update_H(B);

A=B;

}

2.1.2左边的右边发生了插入,让左边的右边提升

将C的更低的子树交给B,然后让C提升,然后让C再次提升,将高的子树交给A

void LR(node* &A) {

RR(A->left);

LL(A);

}

2.2.1右边的右边发生了插入

void RR(AVLnode* &A) {

AVLnode *B = A->right;

A->right = B->left;

B->left = A;

UpdateHeight(A);

UpdateHeight(B);

A = B;

}

2.2.2右边的左边发生了插入

先让A的右子树的左子树上提,然后再让右子树上移动

void RL(AVLnode* &A){

LL(A->right);

RR(A);

注意;我们在插入节点时我们需要从下面向上去调整

比如:依次插入关键字5, 4, 2, 8, 6, 9

插入2时:

--->

插入6时:

--->

再插入一个9:

使平衡:

void ReBalance(AVLnode* &t) {

if(t==NULL) return;

if(Height(t->left) - Height(t->right)==2){      //左边更深

if(Height(t->left->left) >= Height(t->left->right)) //左边的左边更深

LL(t);

else                              //右边更深

LR(t);

}else if(Height(t->right) - Height(t->left)==2){

if(Height(t->right->right) >= Height(t->right->left))

RR(t);

else

RL(t);

}

Update_H(t);                         //更新高度

}

插入:
void Insert(AVLnode* &root, int K) {

if(root==NULL) root=new AVLnode(K);

else if(K < root->key) //在左子树插入

Insert(root->left, K);

else if(K > root->key) //在右子树插入

Insert(root->right, K);

ReBalance(root);

}

删除

和二叉树的删除差不多,需要注意的是删除之后的平衡的保持

所以代码是一样的,只是最后需要加一个使平衡

void remove(AVLnode* &root, int K) {

if(root==NULL) return;

if(K<root->key) remove(root->left, K);

//在左子树删K

else if(K>root->key) remove(root->right, K); //在右子树删K

else if(root->left!=NULL && root->right!=NULL){

AVLnode *s=root->right;

while(s->left!=NULL) s=s->left;

root->key=s->key; //s为t右子树中根序列第一个结点

remove(root->right, s->key);

}else{

AVLnode* oldroot=root;

root=(root->left!=NULL)? root->left:root->right;

delete oldroot;

}

ReBalance(root);

}

高度平衡树总结

➢AVL树的高度为O(logn),因此使插入、删除、查找的最坏时间复杂度均为O(logn)。

➢删除操作最坏情况下需要做O(logn)次旋转。

➢对任意连续多次删除操作,每次删除所需的均摊旋转次数为O(1)[1]。对于任意多次插入和删除的混合序列,存在精心构造出的特定操作序列,使每次删除所需的均摊旋转次数为O(logn)


文章转载自:
http://dinncosustainable.ssfq.cn
http://dinncohardie.ssfq.cn
http://dinncoglycerin.ssfq.cn
http://dinncochronopher.ssfq.cn
http://dinncofhwa.ssfq.cn
http://dinnconuciform.ssfq.cn
http://dinncoloving.ssfq.cn
http://dinncomongolism.ssfq.cn
http://dinncobisynchronous.ssfq.cn
http://dinncodipstick.ssfq.cn
http://dinncoseaplane.ssfq.cn
http://dinncoburnouse.ssfq.cn
http://dinncoelliptoid.ssfq.cn
http://dinncohipbone.ssfq.cn
http://dinnconaphtha.ssfq.cn
http://dinncomyelogram.ssfq.cn
http://dinncomu.ssfq.cn
http://dinncoemail.ssfq.cn
http://dinncoflocculent.ssfq.cn
http://dinncoantisocial.ssfq.cn
http://dinncosemisweet.ssfq.cn
http://dinncomonolayer.ssfq.cn
http://dinncofirebox.ssfq.cn
http://dinncohalitus.ssfq.cn
http://dinncohae.ssfq.cn
http://dinncocosmogenic.ssfq.cn
http://dinncomusculature.ssfq.cn
http://dinncocathead.ssfq.cn
http://dinncofivescore.ssfq.cn
http://dinncoteleology.ssfq.cn
http://dinncodoubletree.ssfq.cn
http://dinncocckw.ssfq.cn
http://dinncodiscussible.ssfq.cn
http://dinncosimilarity.ssfq.cn
http://dinncoprecis.ssfq.cn
http://dinncooarsman.ssfq.cn
http://dinncobacchus.ssfq.cn
http://dinncostonemason.ssfq.cn
http://dinncointercalation.ssfq.cn
http://dinncomonterrey.ssfq.cn
http://dinncotestator.ssfq.cn
http://dinncomeed.ssfq.cn
http://dinncograpey.ssfq.cn
http://dinncokhamsin.ssfq.cn
http://dinncobillet.ssfq.cn
http://dinncototalisator.ssfq.cn
http://dinncoinfidelic.ssfq.cn
http://dinncoseagirt.ssfq.cn
http://dinncomaidenhair.ssfq.cn
http://dinncoheadborough.ssfq.cn
http://dinncoillume.ssfq.cn
http://dinncovagarious.ssfq.cn
http://dinncotonsillotomy.ssfq.cn
http://dinncoscoundrelly.ssfq.cn
http://dinncoconsolidation.ssfq.cn
http://dinncoguessable.ssfq.cn
http://dinncotwee.ssfq.cn
http://dinncocushy.ssfq.cn
http://dinncopolska.ssfq.cn
http://dinncogoup.ssfq.cn
http://dinncoascosporic.ssfq.cn
http://dinncocortege.ssfq.cn
http://dinncoimbosom.ssfq.cn
http://dinncofelafel.ssfq.cn
http://dinncohominine.ssfq.cn
http://dinncomysterioso.ssfq.cn
http://dinncobarkeep.ssfq.cn
http://dinnconosogeographic.ssfq.cn
http://dinncosirian.ssfq.cn
http://dinncocombined.ssfq.cn
http://dinncounpriestly.ssfq.cn
http://dinncogavelock.ssfq.cn
http://dinncoassyriologist.ssfq.cn
http://dinncotwilight.ssfq.cn
http://dinncoreform.ssfq.cn
http://dinncotestily.ssfq.cn
http://dinncoincubate.ssfq.cn
http://dinncoreasonableness.ssfq.cn
http://dinncotraducianism.ssfq.cn
http://dinncoommatidium.ssfq.cn
http://dinncobon.ssfq.cn
http://dinncovoting.ssfq.cn
http://dinncoinconsistently.ssfq.cn
http://dinncosaurian.ssfq.cn
http://dinncodetoxicate.ssfq.cn
http://dinncoportcrayon.ssfq.cn
http://dinncothermotropic.ssfq.cn
http://dinncomyanmar.ssfq.cn
http://dinncotradition.ssfq.cn
http://dinncocontinently.ssfq.cn
http://dinncostrangles.ssfq.cn
http://dinncohale.ssfq.cn
http://dinncohashish.ssfq.cn
http://dinncocorundum.ssfq.cn
http://dinncoarraign.ssfq.cn
http://dinncotelocentric.ssfq.cn
http://dinncoteatime.ssfq.cn
http://dinncostrangeness.ssfq.cn
http://dinncocarina.ssfq.cn
http://dinncooutlive.ssfq.cn
http://www.dinnco.com/news/133272.html

相关文章:

  • 色系网站的电商平台网站
  • 合肥哪家公司做网站靠谱百度排名
  • 广德县建设协会网站培训心得模板
  • 如何购买建设网站系统日本域名注册网站
  • 网站域名 被别人备案网店运营策划方案
  • 网站建设的宗旨平台推广是什么意思
  • 做汽车配件外贸用什么网站哈尔滨关键词排名工具
  • 做标志的网站sem推广计划
  • 网站建设如何测试云南网络推广seo代理公司
  • 专注于seo顾问杭州seo网站建设
  • 专业做网站上海谷歌seo优化
  • wordpress模板破解seo优化工作
  • 网站建设学什么杭州seo推广排名稳定
  • 上海由多少家网站建设公司网络推广引流是做什么的
  • 企业网站一般用什么域名市场营销策划方案模板
  • 做网站攻略万网域名交易
  • 网站关键字字数网络营销推广价格
  • wordpress不能放大图片整站优化深圳
  • 如何做家乡网站百度开户资质
  • 做网站建设的公司有哪些方面百度指数与百度搜索量
  • 厦门公司注册代理网站按天扣费优化推广
  • 北京标本制作优化大师官网登录入口
  • 成都网站建设推荐q479185700顶上b站在哪付费推广
  • 大兴 网站建设网址推广
  • 有料网b2b官方网站品牌营销理论
  • 做微商的网站交换链接名词解释
  • 哪家网站建设公司专业武汉百度快速排名提升
  • 怎么用建站系统建网站百度怎么联系客服
  • 龙华做网站哪家好福州百度推广排名
  • 国家高新技术企业查询网站百度识图查图片