Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:43:00+00:00 2026-06-11T18:43:00+00:00

Given a node with the following structure class Node { int data, Node* P1,

  • 0

Given a node with the following structure

class Node {
int data,
Node* P1,
Node* p2;
}

We need to determine, if the node represents a Circular Doubly Link List OR a Binary Tree.
In my opinion We need to start traversing the given node in one direction

node = givenNode;
while(node->P1 != null && node->P1 != givenNode)
{
  node = node->p1
}

if(node == givenNode) // It means Circular DLL
else if(node == null)  // It means Tree

And it would take O(n) time to detect this.

Please suggest if there is any better approach than this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:43:01+00:00Added an answer on June 11, 2026 at 6:43 pm

    I suggest you could check if its a doubl-linked list or not with this piece of code:

    node = givenNode;
    if(givenNode->P1 == null || givenNode->P2 == null)
     // It can not be double link list (circular)
    else if(givenNode->p1->p2 == givenNode || givenNode->p2->p1 == givenNode)
    {
    //It is a double linked list
    }
    else
    {
    It is not a double linked list
    }
    

    And we have O(1) complexity

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following tree structure in Haskell: data Tree = Leaf Int | Node
I did the following algorithm involving a Binary Heap structure: Algorithm: heapMinimum(node) Input :
I have a structure of the following type struct Node { int word; int
Given the following algorithm for inserting elements into BST : void InsertNode(Node* &treeNode, Node
I have list of objects type Node ( items ). And Node class has
there's something I can't get my head round... Basically I'm given the following data
I was asked the following Question: How would you store the data given below(which
Basically what I need to do is form a tree-structure from an unsorted list
I have an application that requires a data structure with the following characteristics: in-order
Given a node x in an undirected graph that is known to be part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.