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 ...
随机推荐
- ARM相关知识
ARM7采用冯·诺依曼(Von-Neumann)结构,数据存储器和程序存储器重合在一起. 同时,此结构也被大多数计算机所采用. ARM7为三级流水线结构(取指,译码,执行),平均功耗为0.6mW ...
- 关于js基础easy忘记的那些事儿
1.Number() 通过这个函数转化后的值仅仅有两个:数值和NaN,通过parseInt也能转化为数值.可是像"134df"转化后的值为134,而Number("134 ...
- iphone分辨率终极指南(含有iphone6/6+)
如文本不清楚.请 "对->图片另存为" 下载大图后, ------------------------- 原文及翻译文本 Points点 At the beginning, ...
- HTTP协议之ETag字段
整理者:华科小涛:http://www.cnblogs.com/hust-ghtao/ 前段时间参加某公司的面试,问我ETag字段,当时说的不是很清楚,找了些资料,整理为此篇. 简单的说ETag即类似 ...
- package、import、java及javac的相关介绍(转)
Package: package中所存放的文件 所有文件,不过一般分一下就分这三种 1.java程序源文件,扩展名为.java: 2.编译好的java类文件,扩展名为.class: 3.其他文件,也称 ...
- jquery-easyui实现页面布局和增删改查操作(SSH2框架支持)转载
http://blessht.iteye.com/blog/1069749/ 已注册:ooip 关联的csdn 前几天心血来潮用jquery-easyui+spring.struts2.hiberna ...
- 在webform中调用JS的技巧
一,执行删除操作,点击按钮时弹出对话框询问是否确认删除,点击确定,删除并在删除完成后弹出删除成功:点击取消不删除 1.在aspx源 代码中加入JavaScript代码 <script langu ...
- Qt之开机自启动及拥有管理员权限
源地址:http://blog.sina.cn/dpool/blog/s/blog_a6fb6cc90101feia.html Windows开机自启动的程序很多,包括系统软件.杀毒软件.一些其他安装 ...
- Qt中使用OpenCV库
原地址:http://blog.sina.com.cn/s/blog_5c70dfc80100qwi3.html 心情真是好啊,曾经一度想放弃使用Qt加OpenCV进行数字图像处理了,幸好坚持住了,今 ...
- 14.10.2 File Space Management 文件空间管理:
14.10.2 File Space Management 文件空间管理: 数据文件 你定义在配置文件形成了InnoDB的系统表空间, 文件是逻辑连接形成表空间,没有条带化使用. 你不能定义你的表在表 ...