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

  • Home
  • SEARCH
  • 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 7584719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:59:22+00:00 2026-05-30T18:59:22+00:00

#include <stdio.h> Class XObject { int id; char *type; } Class XSubObject : XObject

  • 0
#include <stdio.h>

Class XObject
{
    int id;
    char *type;
}
Class XSubObject : XObject
{
    int remark;
    char* place;
}

**Sorry for my bad example, but more or less data looks like this.
std::vector objects;
data stored in objects are like this:
#1=XObject(1001,"chair"), #2=XObject(1002,"spoon"), #3=XSubObject(1004,"table",2,"center"), #4=XSubObject(1005,"item",0,"left") and so..on

we cna have different XObjects with same types.

Class XStructure
{
    XObject parent;
}

Class XStructureRow
{
    XObject child;
    XStructure parentStruct;
}

std::vector structures;
data stored in Structures are like this:
#5=XStructure(NULL), #7=XStructure(#1),#8=XStructure(#2),#9=XStructure(#3),#10=XStructure(#4) and so..on

std::vector structurerows;
data stored in Structures are like this:
XStructureRow(#4,#5), XStructureRow(#2,#1),XStructureRow(#2,#7),XStructureRow(#3,#10),XStructureRow(#4,#8) and so..on

How can i write a fast alogirthm that starts with XObject and finds it in which structurerow and fetching its structure and fetching its parent. For ex, I want to retrieve all the parents of Object with name “table”
and retrive its parents with name “chair”.

My written algorithm is:

std::vector<XObject> getParents(XObject "chair")
{
    std::vector<XObject> objs;
    for (int i=0;i<structurerows.size() ;i++ )
    {
        XStructurerow sr=structurerows[i];
        XStructutre parent= sr.fetchParent();
        if(parent!=NULL)
        {
            if(parent.fetchName()=="chair")
                objs.push_back(parent);
        }
    }
    return objs;
}

if i have to fetch all the objects parents then it is taking too much time if i have huge data. I mean is there any solution that helps to find the parent objects at O(1) way instead iterating the complete loop? I want to fetch these parents with minimal iterations. Here the complexity is O(n) which i am no satisfied. I hope i made some valid points. Suggestions please..

  • 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-05-30T18:59:23+00:00Added an answer on May 30, 2026 at 6:59 pm

    The only way to “find” something with O(1) complexity is to use a hash-table. The process of creating a hash-value from a key-value and then accessing the object indexed into the table by that hash-value will have O(1) complexity. Otherwise any other search algorithm will at best be O(log n) for a sorted list or sorted tree-type structure.

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

Sidebar

Related Questions

Example code: #include <stdio.h> class compArray { public: unsigned int* myArr; //The array compArray()
vi example.c #include<stdio.h> #include flite.h register_cmu_us_kal(); int main(int argc,char** argv) { cst_voice *v; if(argc!=2)
#include<stdio.h> #include<fstream.h> class Test { char name[10]; int data; public: void getData() { cin>>name;
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { // int char str[40],ch; FILE*fp,*fp1,*fp2; fp=fopen(ide_input,w); fp1=fopen(error_log,w); fp2=fopen(lex_output,w);
#include<stdio.h> class A { public: int a;}; class B: public A { public: static
#include<stdio.h> class A { public: int a;}; class B: public A { int c;
#include<stdio.h> class A {public: int a; }; class B: public A {private: int a;};
I have the following code: #include <stdio.h> template<int A> class Thing { // 5
Consider the code : #include <stdio.h> class Base { public: virtual void gogo(int a){
#include<stdio.h> #include<string.h> char *y; y=(char *)malloc(40); // gives an error here int main() {

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.