CE Home
Navigation
Go Back   CrazyEngineers Forum > CE : Technical Discussions > Computer Science & IT Engineering
Notices


Advertisements
Reply
 
LinkBack (1) Thread Tools Display Modes

  #11 (permalink)
Old 2nd March 2008, 12:05 PM
CE - Regular Member
 
pradeep_agrawal's Avatar
 
Join Date: 4th May 2006
I'm a Crazy Computer Engineer
Posts: 50
Default Re: Data Structure/Algorithm Challenger I

Great work Sahana, good going.

I had few more solution, but this is the most optimized option among that. The algorithm has a time complexity of O(n) and very much optimized in terms of space complexity.

-Pradeep
pradeep_agrawal is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #12 (permalink)
Old 10th November 2008, 11:54 AM
CE - Regular Member
 
pradeep_agrawal's Avatar
 
Join Date: 4th May 2006
I'm a Crazy Computer Engineer
Posts: 50
Default Re: Data Structure/Algorithm Challenger I

Posting a sample code as per the solution stated by Sahana.

Code:
int IsCircle(node* head) {
    node *tmp1;
    node *tmp2;
    int result = 0;        //Specify no circular path exist

    tmp2 = tmp1 = head;
    while((tmp1 != NULL) && (tmp2 != NULL)) {
        //increment tmp1 by 1 and tmp2 by 2
        tmp1 = tmp1->next;
        tmp2 = tmp2->next;
        if(tmp2 != NULL) {
            tmp2 = tmp2->next;
        } else {
            break;
        }

        if((tmp1 == tmp2) && (tmp2 != NULL)){
            result = 1;        //specify existence of circular path
            break;
        }
    }

    return result;
}
-Pradeep
pradeep_agrawal is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.crazyengineers.com/forum/computer-science-engineering/2078-data-structure-algorithm-challenger-i.html
Posted By For Type Date
Uniting Engineers Across The World ! This thread Refback 22nd February 2008 08:38 PM


All times are GMT +5.5. The time now is 12:11 PM.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Member comments are owned by the poster. Copyright © 2005-2008 CrazyEngineers.com. All rights reserved.

Advertisements