I need to build an optimal binary search tree with an array of strings and frequency received from the user.in C
PLEASE GIVE IT A THUMBS UP
#include <stdio.h>
#include <limits.h>
int sum(int freq[], int i, int j)
{
int s = 0;
for (int k = i; k <=j; k++)
s += freq[k];
return s;
}
int costbst(int freq[], int i, int j)
{
if (j < i)
return 0;
if (j == i)
return freq[i];
int funcsum = sum(freq, i, j);
int min = INT_MAX;
for (int r = i; r <= j; ++r)
{
int cost = costbst(freq, i, r-1) +
costbst(freq, r+1, j);
if (cost < min)
min = cost;
}
return min + funcsum;
}
int binary_optimal(char keys[3][10], int freq[], int n)
{
return costbst(freq, 0, n-1);
}
int main()
{
char keys[3][10];
int freq[3],i;
for(i=0;i<3;i++){
printf("Enter key and freq for %d\n",i+1 );
scanf("%s",keys[i]);
scanf("%d",&freq[i]);
}
printf("Optimal binary tree cost is %d ", binary_optimal(keys,
freq, 3));
return 0;
}
I need to build an optimal binary search tree with an array of strings and frequency...
I am building an optimal binary search tree. I have its root table and main table, and i am trying to construct the binary tree from the root table. I do not know how, can you please build a program that does so? for more info, my array is 600 strings, and the frequencies are randomly chosen. Thank You! In C Please!
How do I insert an unsorted array into a Binary Search Tree as a Doubly Linked List in C++?
I need help on question 12 please An inorder tree traversal of a binary search tree produces a listing of the tree nodes in alphabetical or numerical order. Construct a binary search tree for "To be or not to be, that is the question, " and then do an inorder traversal. Construct a binary search tree for "In the high and far off times the Elephant, O Best Beloved, had no trunk, " and then do an inorder traversal.
This is binary search tree problem. The program reads the text file, and creates a binary search tree based on the words in the file. I can create the tree but I also have to store 'the order of insertion' in each node. For example, if text includes "the" 3 times and it is the 1st, 5th, and 9th word in the file, in binary search tree, one node should have string value "the" and array list{1, 5, 9}. How...
I need question 9-10 answered. Thank you Question 1 iShow the resulting binary search tree if we are to insert following elements into the tree in given order, [34, 12, 23, 27,31,9,11,45, 20, 37. i) Show the resulting balanced binary search tree if we are to insert following sorted elements into the tree, [9,12,21, 23, 29, 31, 34, 45, 48, 52, 55] iii What is the pre-order traversal of the balanced binary search tree? v) What is the post-order traversal...
given array: 2,15,30,30,27,27,2,8,22,22,11,27 G-7 pts) Transform the binary search tree of (c) to a min heap.
Consider the given binary search tree (BST). 1. What is the maximum size of the array required to implement the above BST? 2. Draw the array-based binary tree that represents the given BST (use the Table tool above to draw the array or just write it on one line and explain it) 3. Print the given BST using the in-order traversal pattern (don't write code, just show the output) HTML Editor BIVA -A- IEE311 X, EE Do NVX 12pt Paragraph...
1. What is the worst case time complexity of insertion into a binary search tree with n elements? You should use the most accurate asymptotic notation for your answer. 2. A binary search tree is given in the following. Draw the resulting binary search tree (to the right of the given tree) after deleting the node with key value 8. 10 3. You have a sorted array B with n elements, where n is very large. Array C is obtained...
I need help in C++ implementing binary search tree. I have the .h file for the binary search tree class. I have 4 classic texts, and 2 different dictionaries. Classic Texts: Alice In Wonderland.txt A Tale of Two Cities.txt Pride And Prejudice.txt War and Peace.txt 2 different dictionaries: Dictionary.txt Dictionary-brit.txt The data structures from the standard template library can not be used.The main program should open the text file, read in the words, remove the punctuation and change all the...
Trees-related questionsBeginning with an empty binary search tree, what binary search tree is formed when you add the following letters in the order given? J, N, B, A, W, E, TRepresent the following binary tree with an array What is the result of adding 3 and 4 to the 2-3 tree shown below?Why does a node in a red-black tree require less memory than a node in a 2-3-4 tree?Why can’t a Red-Black Tree have a black child node with exactly...