58 *
k++ = node->get_key();
92int main(
int argc,
char * argv[])
97 try { n = std::stoi(argv[1]); }
98 catch (...) { n = 10; }
103 cerr <<
"n must be greater than 0" << endl;
110 try { prob = std::stod(argv[2]); }
111 catch (...) { prob = 0.5; }
114 unsigned int t =
static_cast<unsigned int>(time(
nullptr));
117 try { t =
static_cast<unsigned int>(std::stoul(argv[3])); }
118 catch (...) { t =
static_cast<unsigned int>(time(
nullptr)); }
123 cout << argv[0] <<
" " << n <<
" " << prob <<
" " << t <<
" " << endl;
125 std::vector<int>
keys(
static_cast<size_t>(n));
131 for (
int i = 0; i < n; i++)
135 value =
static_cast<int>(10.0 * n * rand() / (RAND_MAX + 1.0));
149 std::vector<double> p(
static_cast<size_t>(n));
150 for (
int i = 0; i < n; i++)
152 p[
static_cast<size_t>(i)] =
bin_coef(n, i) *
pow(prob, i) *
pow((1 - prob), n - i);
153 printf(
"%.5f ", p[
static_cast<size_t>(i)]);
157 build_optimal_tree<BinNode<int>,
int>(
keys.data(), p.data(),
static_cast<size_t>(n));
size_t size_t int32_t value
Node for binary search tree.
Node * insert(Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >)
Insert a node in the tree.
Node *& getRoot() noexcept
Return the root of tree.
Node * search(const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
Search a key.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_min_function > > min(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_pow_function > > pow(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in preorder a binary tree.
int inOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively inorder a binary tree.
void destroyRec(Node *&root) noexcept
Free all the memory occupied by the tree root
Main namespace for Aleph-w library functions.
Optimal Binary Search Tree construction using dynamic programming.
Binary search tree with nodes without virtual destructors,.
void print(BinNode< int > *node, int, int)
void assign(BinTree< int >::Node *node, int, int)
double bin_coef(int n, int k)
Utility functions for binary tree operations.
Generic unbalanced binary search tree.