dev6546
dev6546

Reputation: 1442

Binary search tree analysis

I create my tree using a read function, which uses a while loop to retrieve lines from a text file, in that loop I create a node, and then use an insert method to insert the node into the correct place in tree.

For my copy constructor I do something similar, I pass in the root to a helper function a little like my insert function, then copy over the name of the node passed in to a node in the function. looks a little like this:

newNode->name  = pNode->name;           
newNode->left  = copyConstructorHelper(pNode->left);            
newNode->right = copyConstructorHelper(pNode->right); 

I then return a new node.

After running the sampling built into visual studio, the read method uses up %36 percent of the memory whilst the copy constructor only uses up %4. This is a massive difference, could someone explain why please?

Upvotes: 2

Views: 215

Answers (1)

Scott Hunter
Scott Hunter

Reputation: 49803

Part is likely the file IO; make a version of your first method that gets its data from a string (or array of same) and see what difference that makes.

Upvotes: 1

Related Questions