Match the cost behavior that is described with the proper cost type. The unit cost of an item is
$30 per unit when activity is 10,000 units and $15 per unit when activity is 20,000 units. The
total cost of an item is $30,000 when activity is 10,000 units and $30,000 when activity is 20,000
units. The total cost of an item is $30,000 when activity is 10,000 units and $50,000 when
activity is 20,000 units. 1. Variable cost 2. Fixed Cost The unit cost of an item is $30 per unit
when activity is 10,000 units and $20 per unit when activity is 20,000 units 3. Mixed Cost The
total cost of an item is $30,000 when activity is 10,000 units and $60,000 when activity is 20,000
units. The unit cost of an item is $30 per unit when activity is 10,000 units and $30 per unit when
activity is 20,000 units.
Solution
Variable cost is constant or same in per unit but varies in total with change in output
Fixed cost is constant in total but varies in per unit [ that is doesnot change with change in
output]
Mixed cost is neither constant in total nor in per unit
A)Fixed cost ,since same in total [10000*30 = 300000 or 15*20000 = 300000]
B)Fixed cost ,since same in total
C)Mixed cost,neither constant in per unit nor in total
D)Mixed cost ,neither constant in per unit nor in total
E)Variable cost ,constant in per unit [30000/10000 or 60000/20000 = $ 3 per unit]
F)Variable cost .
c).
Modify this code to do an Insert function for an AVL tree, instead o.pdf
1. Modify this code to do an Insert function for an AVL tree, instead of a B-Tree .
Please compile in Microsoft Visual studio, as it is the IDE that is required for my course.
Here is the code for the header file and the Source file.
Soure File :
#include
#include "bTree.h"
using namespace std;
int main()
{
bTree treeRoot;
int num;
cout << "Enter numbers ending with -999" << endl;
cin >> num;
while (num != -999)
{
treeRoot.insert(num);
cin >> num;
}
cout << "Inorder traversal data: ";
treeRoot.inOrder();
cout << endl;
return 0;
Header File:
#ifndef H_bTree
#define H_bTree
#include
#include
using namespace std;
//*************************************************************
// Author: D.S. Malik
//
// class bTree
// This class specifies the basic operations to implement a
// B-tree.
2. //*************************************************************
template
struct bTreeNode
{
int recCount;
recType list[bTreeOrder - 1];
bTreeNode *children[bTreeOrder];
};
template
class bTree
{
public:
bool search(const recType& searchItem);
//Function to determine if searchItem is in the B-tree.
//Postcondition: Returns true if searchItem is found in the
// B-tree; otherwise, returns false.
void insert(const recType& insertItem);
//Function to insert insertItem in the B-tree.
//Postcondition: If insertItem is not in the the B-tree, it
// is inserted in the B-tree.
void inOrder();
//Function to do an inorder traversal of the B-tree.
bTree();
//constructor
//Add additional members as needed
protected:
bTreeNode *root;
private:
void searchNode(bTreeNode *current,
const recType& item,
bool& found, int& location);
void insertBTree(bTreeNode *current,
const recType& insertItem,
recType& median,
bTreeNode* &rightChild,
bool& isTaller);
6. }
}
} //insertBTree
template
void bTree::insertNode
(bTreeNode *current,
const recType& insertItem,
bTreeNode* &rightChild,
int insertPosition)
{
int index;
for (index = current->recCount; index > insertPosition;
index--)
{
current->list[index] = current->list[index - 1];
current->children[index + 1] = current->children[index];
}
current->list[index] = insertItem;
current->children[index + 1] = rightChild;
current->recCount++;
} //end insertNode
template
void bTree::splitNode
(bTreeNode *current,
const recType& insertItem,
bTreeNode* rightChild,
int insertPosition,
bTreeNode* &rightNode,
recType &median)
{
rightNode = new bTreeNode;
int mid = (bTreeOrder - 1) / 2;
if (insertPosition <= mid) //new item goes in the first
//half of the node
{
int index = 0;
7. int i = mid;
while (i < bTreeOrder - 1)
{
rightNode->list[index] = current->list[i];
rightNode->children[index + 1] =
current->children[i + 1];
index++;
i++;
}
current->recCount = mid;
insertNode(current, insertItem, rightChild,
insertPosition);
(current->recCount)--;
median = current->list[current->recCount];
rightNode->recCount = index;
rightNode->children[0] =
current->children[current->recCount + 1];
}
else //new item goes in the second half of the node
{
int i = mid + 1;
int index = 0;
while (i < bTreeOrder - 1)
{
rightNode->list[index] = current->list[i];
rightNode->children[index + 1] =
current->children[i + 1];
index++;
i++;
}
current->recCount = mid;
rightNode->recCount = index;
median = current->list[mid];
insertNode(rightNode, insertItem, rightChild,
insertPosition - mid - 1);
rightNode->children[0] =
8. current->children[current->recCount + 1];
}
} //splitNode
template
void bTree::inOrder()
{
recInorder(root);
} // end inOrder
template
void bTree::recInorder
(bTreeNode *current)
{
if (current != NULL)
{
recInorder(current->children[0]);
for (int i = 0; i < current->recCount; i++)
{
cout << current->list[i] << " ";
recInorder(current->children[i + 1]);
}
}
} //end recInorder
#endif
Solution
In a binary tree the balance issue of a node N is described to be the height distinction
BalanceFactor(N) := –peak(LeftSubtree(N)) + height(RightSubtree(N)) [6]
of its infant subtrees. A binary tree is defined to be an AVL tree if the invariant
BalanceFactor(N) –1,zero,+1
holds for each node N in the tree.
A node N with BalanceFactor(N) < 0 is called "left-heavy", one with BalanceFactor(N) > 0 is
known as "proper-heavy", and one with BalanceFactor(N) = 0 is once in a while clearly called
"balanced".
statement
inside the sequel, because there's a one-to-one correspondence among nodes and the subtrees
9. rooted via them, we every so often depart it to the context whether the call of an object stands for
the node or the subtree.
properties[edit]
balance factors can be saved up to date through knowing the preceding balance elements and the
exchange in top – it is not important to recognize absolutely the height. for containing the AVL
balance statistics, two bits in keeping with node are enough.[7]
the height h of an AVL tree with n nodes lies within the c programming language:[8]
log2(n+1) h < c log2(n+2)+b
with the golden ratio := (1+5) 2 1.618, c := 1 log2 1.44, and b := c2 log2 5 – 2 –zero.328. that
is due to the fact an AVL tree of top h includes at the least Fh+2 – 1 nodes where Fh is the
Fibonacci collection with the seed values F1 = 1, F2 = 1.