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 6209491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:59:37+00:00 2026-05-24T05:59:37+00:00

I would like to build a website that has some elements of a social

  • 0

I would like to build a website that has some elements of a social network.

So I have been trying to think of an efficient way to store a friend list (somewhat like Facebook).

And after searching a bit the only suggestion I have come across is making a “table” with two “ids” indicating a friendship.

That might work in small websites but it doesn’t seem efficient one bit.

I have a background in Java but I am not proficient enough with PHP.

An idea has crossed my mind which I think could work pretty well, problem is I am not sure how to implement it.

the idea is to have all the “id”s of your friends saved in a tree data structure,each node in that tree resembles one digit from the friend’s id.

first starting with 1 node, and then adding more nodes as the user adds friends.
(A bit like Lempel–Ziv).

every node will be able to point to 11 other nodes, 0 to 9 and X.

“X” marks the end of the Id.

for example see this tree:

An Example

In this tree the user has 4 friends with the following “id”s:

  • 0
  • 143
  • 1436
  • 15

Update: as it might have been unclear before, the idea is that every user will have a tree in a form of multidimensional array in which the existence of the pointers themselves indicate the friend’s “id”.

If every user had such a multidimensional array, searching if id “y” is a friend of mine, deleting id “y” from my friend list or adding id “y” to my friend list would all require constant time O(1) without being dependent on the number of users the website might have, only draw back is, taking such a huge array, serializing it and pushing it into each row of the table just doesn’t seem right.

-Is this even possible to implement?

-Would using serializing to insert that tree into a table be practical?

-Is there any better way of doing this?

The benefits upon which I chose this is that even with a really large number of ids (millions or billions) the search,add,delete time is linear (depends of the number of digits).

I’d greatly appreciate any help with implementing this or any suggestions for alternative ways to improve or change this method.

  • 1 1 Answer
  • 1 View
  • 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-24T05:59:38+00:00Added an answer on May 24, 2026 at 5:59 am

    I would strongly advise against this.

    • Storage savings are not significant, and may (probably?) be worse. In a real dataset, the actual space-savings afforded to you with this approach are minimal. Computing the average savings is a very difficult problem, but use some real numbers and try a few samples with random IDs. If you have a million users, consider a user with 15 friends. How much data do you save with this approch? You may actually use more space, since tree adjacency models can require significant data.

    • “Rendering” a list of users requires CPU investment.

    • Inserts are non-deterministic and non-trivial. When you add a new user to an existing tree, you will have a variety of methods of inserting them. Assuming you don’t choose arbitrarily, it is difficult to compute which approach is the best (and would only be based on heuristics).

    This are the big ones that came to my mind. But generally, I think you are over-thinking this.

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

Sidebar

Related Questions

I'm trying to build a website that has a Member section, and I'm struggling
I just started learning PHP, and have been trying to build a website to
I would like to retrieve the categories of my website in order to build
we have a modularized website built on the MVC pattern. We would like to
I would like to build a php script that automatically generates a new id
I would like to build a web application that heavily relies on the Yodlee
I would like to build a query that will pull the number of rows
I build a website focussing on loading only data that has to be loaded.
I have an ASP.NET website that I built that has grown considerably in size
I am trying to build a website and I want to have a map

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.