Loser tree in Python | Christan Christens
Loser tree in Python | Christan Christens
I am taking an Advanced Data Structures and Algorithms class with Dr. Sahni at UF. I used a data structure discussed in this class as an opportunity to learn Python a little better. I implemented the loser tree. The loser tree is a complete binary tree with n external nodes and n-1 internal nodes. The root of the tree has the overall winner. The loser tree is a more efficient version of a winner tree which are both types of Tournament Trees. In the winner tree the winner of each competition is inside the nodes, however it is more efficient to keep the loser of the competitions in side the nodes and bubble the winner up the tree.The loser tree has applications in areas such as Run Generations during external sorts, Bin-Packing Problems (Truck Loading), and others.
I am not yet sure of how to transfer my c++ knowledge of pointer to Python, so I used an array representation of the binary tree to keep track of the nodes. If anybody knows how I could implement a tree with pointers, I would love to know.
In anycase, below is my code. It isnt great code, and any suggestions would be great! Thanks to Yet Another Coding Blog for the code highlighting tip.
Loser tree in Python | Christan Christens的更多相关文章
- leetcode:Maximum Depth of Binary Tree【Python版】
# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self ...
- 【LeetCode】572. 另一个树的子树 Subtree of Another Tree(Python & Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:先序遍历 方法二:DFS + DFS 方法三 ...
- leetcode Binary Search Tree Iterator python
# Definition for a binary tree node # class TreeNode(object): # def __init__(self, x): # self.val = ...
- leetcode Binary Tree Paths python
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...
- leetcode:Minimum Depth of Binary Tree【Python版】
1.类中递归调用添加self: 2.root为None,返回0 3.root不为None,root左右孩子为None,返回1 4.返回l和r最小深度,l和r初始为极大值: # Definition f ...
- leetcode:Same Tree【Python版】
1.p或q为None的情况用开始的两个if语句进行判断: 2.类中递归调用函数需要使用self进行调用: 3.代码很简洁,最后几行通过同时为None和同时非None的条件进行判断: # Definit ...
- leetcode:Symmetric Tree【Python版】
#error caused by:#1:{} 没有考虑None输入#2:{1,2,2} 没有控制h和t#3:{4,-57,-57,#,67,67,#,#,-97,-97} 没有考虑负号,将s从str变 ...
- leetcode 【 Convert Sorted List to Binary Search Tree 】python 实现
题目: Given a singly linked list where elements are sorted in ascending order, convert it to a height ...
- 决策树(Decision Tree)算法 python简单实现
"" """ import numpy as np from math import log import operator import json ...
随机推荐
- MFC 之 截图工具
这个截图工具能实现最主要的截图功能,并保存为bmp图片. 编写环境是vs2005,使用Unicode,基于对话框. 没什么难度,直接看代码 项目名称为CutOut // CutOutDlg.h : 头 ...
- 设计模式(Abstract Factory)抽象工厂
1. 需求: 设计一个电脑组装程序,对于组装品牌电脑. 用零件组装(主板.硬盘.显示器)由品牌提供的所有. 让我们组装一台联想电脑,板子.由联想提供. (眼下仅仅有Lenovo和Dell两种品牌) 2 ...
- Swift - 网络请求报App Transport Security has blocked a cleartext错
使用Xcode7编写iOS9应用时,如果获取http://数据时会报如下错误: App Transport Security has blocked a cleartext HTTP (http:// ...
- C#调用存储过程实现分页(个人代码笔记)
分页的存储过程: drop proc LoadPageMain create Proc LoadPageMain @pageIndex )) Fid ) ].Rows ) ...
- Cocos2d-x使用android拍照功能加载照片内存过大,通过另存照片尺寸大小解决
使用2dx调用android拍照功能,拍照结束后在2dx界面显示拍照照片,如果不对照片做处理,会出现内存过大的问题,导致程序崩溃,如果仅仅另存拍照照片,则照片质量大小均下降,导致照片不够清晰,后来发现 ...
- nexus搭建
Nexus是Maven仓库管理软件,可以用来搭建私服.主页 http://www.sonatype.org/nexus/ 下载地址 http://www.sonatype.org/nexus/down ...
- Python,PIL压缩裁剪图片
自己写了用来压缩 DC 照片的,批量处理整目录文件,非常方便.需要安装 PIL #!/usr/bin/env python import Image import os import os.path ...
- 一个Sqrt谋杀触发功能
我们平时常常会有一些数据运算的操作,须要调用sqrt,exp,abs等函数,那么时候你有没有想过:这个些函数系统是怎样实现的?就拿最常常使用的sqrt函数来说吧.系统怎么来实现这个常常调用的函数呢? ...
- linux 压缩和解压文件
一.压缩:20120715文件下面所有的文件 如下: tar -zcvf 20120715.tar.gz 20120715* 二.解压20120715.tar.gz压缩包 如下: tar -xzvf ...
- kali之ARP欺骗获取图片流
其实很简单,就两步: 1. 后接三个参数: 网卡:eth0 网关:10.0.0.1 攻击目标:10.0.0.128 2.启动监听 会弹出一个框 里面就会显示攻击目标通过浏览器访问的页面上的 ...