Php: tree structure algorithm _ PHP Tutorial

Source: Internet
Author: User
Php: tree structure algorithm. In terms of product classification, multi-level tree structure forums, mail lists, and many other places, we all encounter the following problem: how to store multi-level structured data? In PHP applications, the following data product categories, multi-level tree structure forums, mailing lists, and many other places are all faced with the following problem: how to store multi-level structured data?

In PHP applications, relational databases are usually used to store background data. they can store a large amount of data and provide efficient data retrieval and update services. However, the basic form of relational data is an interactive table, which is a flat structure. if you want to store a multi-level tree structure in a relational database, you need to perform reasonable translation work. Next, I will discuss what I have seen and some practical experiences with you.

There are basically two common design methods for storing hierarchical data in a flat database:

Adjacency list model)

Pre-sorted traversal tree algorithm (modified preorder tree traversal algorithm)

I am not a computer professional and have never learned anything about data structures. Therefore, these two names are literally translated by myself. if they are wrong, please give me more advice.

These two things seem very scary and easy to understand. Here I use a simple food directory as our sample data. Our data structure is as follows:

Food

|

| --- Fruit

|

| --- Red

|

| -- Cherry

|

| --- Yellow

|

| -- Banana

|

| --- Meat

|

| -- Beef

|

| -- Pork

To take care of PHP fans who are confused about English

Food: Food

Fruit: Fruit

Red: Red

Cherry: Cherry

Yellow: Yellow

Banana: Bananas

Meat: Meat

Beef: Beef

Pork: Pork


Why? In PHP applications, the number of backend servers is provided...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.