Applied Mathematics, 2021, 12, 1210-1215 https://www.scirp.org/journal/am ISSN Online: 2152-7393 ISSN Print: 2152-7385 DOI: 10.4236/am.2021.1212077 Dec. 23, 2021 1210 Applied Mathematics Counting and Randomly Generating k-Ary Trees James F. Korsh Computer and Information Science Department, Temple University, Philadelphia, USA Abstract k-ary trees are one of the most basic data structures in Computer Science. A new method is presented to determine how many there are with n nodes. This method gives additional insight into their structure and provides a new algorithm to efficiently generate such a tree randomly. Keywords Combinatorial Problems, k-Ary Trees, Random Generation 1. Introduction The number, , bn k , of k-ary trees with n nodes is well known and given in [1] as ( ) ( ) ( ) , 1 1 C kn n k n + where ( ) , Cnk denotes the number of ways to choose k places from n places, which is ( ) ! ! ! n k n k . This paper generalizes the results from [2] on binary trees with n nodes to k-ary trees with n nodes by providing a simple direct approach to finding , bn k and a new method to generate a ran- dom k-ary tree with n nodes efficiently. The direct approach here to finding , bn k relies on the detailed structure of the trees developed here rather than the standard recursive description of the tree and solving the resultant recurrence relations. Another approach for the random generation is given in [3]. The nu- meration of k-ary trees is done in [4]. The generation of binary and k-ary trees has been and continues to be of interest [5] [6] [7] [8]. 2. Representation of k-Ary Trees with n Nodes For any n > 0, a k-ary tree with n nodes can be uniquely represented by a se- quence of n k-tuples of 0’s and 1’s, one k-tuple for each node. In a node’s k-tuple, the ith entry specifies whether the node’s ith child is non-null or null: 1 for non- null and 0 for null. The k-tuples appear in the order in which the nodes are ac- How to cite this paper: Korsh, J.F. (2021) Counting and Randomly Generating k-Ary Trees. Applied Mathematics, 12, 1210-1215. https://doi.org/10.4236/am.2021.1212077 Received: October 29, 2021 Accepted: December 20, 2021 Published: December 23, 2021 Copyright © 2021 by author(s) and Scientific Research Publishing Inc. This work is licensed under the Creative Commons Attribution International License (CC BY 4.0). http://creativecommons.org/licenses/by/4.0/ Open Access