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的更多相关文章

  1. leetcode:Maximum Depth of Binary Tree【Python版】

    # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self ...

  2. 【LeetCode】572. 另一个树的子树 Subtree of Another Tree(Python & Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:先序遍历 方法二:DFS + DFS 方法三 ...

  3. leetcode Binary Search Tree Iterator python

    # Definition for a binary tree node # class TreeNode(object): # def __init__(self, x): # self.val = ...

  4. leetcode Binary Tree Paths python

    # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...

  5. 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 ...

  6. leetcode:Same Tree【Python版】

    1.p或q为None的情况用开始的两个if语句进行判断: 2.类中递归调用函数需要使用self进行调用: 3.代码很简洁,最后几行通过同时为None和同时非None的条件进行判断: # Definit ...

  7. 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变 ...

  8. 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 ...

  9. 决策树(Decision Tree)算法 python简单实现

    "" """ import numpy as np from math import log import operator import json ...

随机推荐

  1. hive怎样处理多分隔符数据

    问题描写叙述:     大数据维稳需求中,客户提供的測试数据为多个字符做分隔符('|#'),在pig中会直接报错,hive中仅仅认第一个分隔符. 因为数据量比較大(160G),在文本中替换成单个字符分 ...

  2. 极限挑战—C#+ODP 100万条数据导入Oracle数据库仅用不到1秒

    链接地址:http://www.cnblogs.com/armyfai/p/4646213.html 要:在这里我们将看到的是C#中利用ODP实现在Oracle数据库中瞬间导入百万级数据,这对快速批量 ...

  3. UIViewController加载过程

    UIViewController是视图和数据的桥梁,UIViewController是所有controller的基类,ios内置了很多试图控制器,如导航控制器,tableViewController等 ...

  4. boost 轻量级信号量

    #include <boost/thread/condition_variable.hpp> #include <boost/thread/mutex.hpp>     #in ...

  5. <Win32_12>程序员求爱的创意程序——升级版^_^

    前段时间,我编写了一个创意程序,并用于向自己目前的女朋友表白,结果效果还不错,得到了她的芳心. 于是我将自己的创意程序共享到csdn资源上,大多数网友认为创意不错,就是简单了些——呵呵,其实我个人也这 ...

  6. 一个Sqrt谋杀触发功能

    我们平时常常会有一些数据运算的操作,须要调用sqrt,exp,abs等函数,那么时候你有没有想过:这个些函数系统是怎样实现的?就拿最常常使用的sqrt函数来说吧.系统怎么来实现这个常常调用的函数呢? ...

  7. 重操JS旧业第九弹:函数表达式

    函数表达式,什么概念,表达式中的函数表达式. 1 函数申明 function 函数名([函数参数]){ //函数体 } js中无论像这样的显示函数什么放在调用之前还是调用之后,都不影响使用,因为js解 ...

  8. Swift - 系统声音服务的使用(播放声音,提醒,震动)

    1,系统声音服务介绍: 系统声音服务提供了一个Api,用于播放不超过30秒的声音.它支持的文件格式有限,具体的说只有CAF.AIF和使用PCM或IMA/ADPCM数据的WAV文件. 但此函数没有提供操 ...

  9. C++学习之路—运算符重载(二)运算符重载作为类的成员函数和友元函数

    (根据<C++程序设计>(谭浩强)整理,整理者:华科小涛,@http://www.cnblogs.com/hust-ghtao转载请注明) 对运算符重载的函数有两种处理方式:(1)把运算符 ...

  10. Net MVC微信扫码支付

    微信扫码支付+Asp.Net MVC 这里的扫码支付指的是PC网站上面使用微信支付,也就是官方的模式二,网站是Asp.net MVC,整理如下. 一.准备工作 使用的微信API中的统一下单方法,关键的 ...