spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Partitioning a weighted tree to equally weighted subtrees


Assume you can't modify the tree other than to remove edges to create subtrees.

First understand that you cannot guarantee that by simply removing edges that you will have subtrees within an arbitrary bound. You can create tree that when you split them there is no way to create subtrees within a target bound. For example:

a(b(c,d,e,f),g)

You cannot split that into two balanced sections. The best you can do is remove the edge from a to b:

a(g) and b(c,d,e,f)

Also this criteria is a little underdefined when k > 2. What is better a split 10,10,10,1 or 10,10,6,5?

But you can come up with a method to split trees up in the most balanced way possible.

Implement you tree such that each node holds a count of all of its children. You can add this pretty efficiently to any tree. ( E.g. when you add a node you have to iterate up the chain of parent node incrementing the count. Remove a node and you iterate up subtracting from the count )

Then starting from the root iterate down, in a breadth first manner until you find a set of nodes that dominate child nodes in a way that is most balanced. I don't have an algorithm for this at the ready - but I think you can find one pretty readily.

I think something where when you want to divide into k subtrees you create an array of k tree roots. One of those nodes must always be the root of the current tree, then you iterate down looking for nodes to replace on of the k-1 candidates that improves the partitioning. You'll want some kind of terminating condition where you don't interate down to every leaf node. E.g. it never makes sense to subdivide anything by the largest candidate node.


Categories : Algorithm

Related to : Partitioning a weighted tree to equally weighted subtrees
Computing the un-weighted length of a weighted shortest path
In get.shortest.paths, there is a weights argument! If you read ?get.shortest.paths you will find that weights is Possibly a numeric vector giving edge weights. If this is NULL and the graph has a weight edge attribute, then the attribute is used. If this is NA then no weights are used (even if the graph has a weight attribute). So you should set weights = NA. See below for an example: requ

Categories : R
Image filtering by changing weighted elements along an edge
One option: use NaN (Not a Number) in a pre-processing step: bin(~mask)=NaN; Such that bin looks like: NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0 0 0 NaN 0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 0 0

Categories : Matlab
How to iterate through all cases when partitioning objects
I managed to find a solution through a combination of recursion and loop. Here's the pseudo code (I have no idea how to write pseudo code...I'm denoting a list by [a; b; c ...]: // Returns a list of integers in range [0, k]. function num_list k = ... // Recursively generate all the possible partitions with [total] objects // and [groups] partitions. Returns a list of list of integers. function

Categories : Algorithm
Clojure: 'folding' a sequence (partitioning, as it turned out)
(->> '(1 2 3 4 5 6 7 8 9) (partition 3) (map vec)) Take the original list and then partition it by 3 and finally map each partition to a vector. I think using the ->> macro makes it read nicer.

Categories : Clojure
Recently Add
why this assembly piece of code do jmp forever
Find out if segment is fully inside of polygon
Algorithm for coloring a hexagon tile map with minimum distance (3) for reoccurring colors
Sort pairs to be more consecutive
To find three unique numbers whose number of occurrence is even
Dealing with duplication between unit and integration tests
reflection and symmetry in back tracking queens
Big O analysis for method with multiple parameters
Divide Huge Array of Numbers in Buckets
Algorithm to find adjacent cells in a matrix
Why this code gives WA for Petersen Graph(codechef)?
Complexity of this prime number search algorithm
How to detect if a file has changed?
Given string x,y and z. Determine if z is a shuffle
Basic decryption for simple encryption algorithm
An efficient way to assign user_ids to huge dataset under certain conditions
What's a more efficient implementation of this puzzle?
Generating prime numbers in poly-time
What if I do not use G transpose in calculating Strongly Connected Components?
Dividing an array into optimum no of equal sum sublists
Counting derangements
How to iterate through all cases when partitioning objects
Algorithm: How to find closest element, having coordinates and dimension
Developing player rankings with ELO
How to transform two set of discrete points ( vectors ) to help plotting them on a common scale
Heap Sort Space Complexity
complex root finding algorithm
Every possible combination algorithm
RSA Cryptosystem - Retrieve m
Heap-like data structure with fast random access?
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.