Time analysis

M

mathon

hello,

i have a question regarding time analysis, respectively calculating the
Big O. For example when i have this function:

Code:
void sequence::attach(const value_type& entry)
{
	if(!(is_item()))
	{
		cursor = tail_ptr;
	}

	if(cursor == NULL)
	{
		list_head_insert(head_ptr, entry);
		cursor = head_ptr;
		tail_ptr = head_ptr;
	}
	else
	{
		list_insert(cursor, entry);
		precursor = cursor;
		cursor = cursor->link();
	}

    ++many_nodes;

	node* cursor1;
	node* precursor1;
	for(cursor1 = head_ptr; cursor1 != NULL; cursor1 = cursor1->link())
	{
		precursor1 = cursor1;
	}
	tail_ptr = precursor1;
}

Does there exist an easy concept how i can calculate the Big O for the
previous function for example...?

matti
 
M

mlimber

hello,

i have a question regarding time analysis, respectively calculating the
Big O. For example when i have this function:

Code:
void sequence::attach(const value_type& entry)
{
	if(!(is_item()))
	{
		cursor = tail_ptr;
	}

	if(cursor == NULL)
	{
		list_head_insert(head_ptr, entry);
		cursor = head_ptr;
		tail_ptr = head_ptr;
	}
	else
	{
		list_insert(cursor, entry);
		precursor = cursor;
		cursor = cursor->link();
	}

++many_nodes;

	node* cursor1;
	node* precursor1;
	for(cursor1 = head_ptr; cursor1 != NULL; cursor1 = cursor1->link())
	{
		precursor1 = cursor1;
	}
	tail_ptr = precursor1;
}

Does there exist an easy concept how i can calculate the Big O for the
previous function for example...?

First, this is not a C++ *language* question and so is off-topic here
(see http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9).
You should ask in comp.programming or similar.

Second, we're not here to do your homework for you
(http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2).

I can tell you that the standard C++ linked list is O(1) to insert and
O(N) to traverse (cf. http://www.sgi.com/tech/stl/List.html).

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top