The length and depth of a generalized table and the footer operation of the table head

Source: Internet
Author: User
Tags data structures

Generalized table definitions

Generalized table (Lists, aka list) is a kind of nonlinear data structure, and it is a generalization of linear table. The generalized table relaxes the atomic limits on the table elements, allowing them to have their own structure. It is widely used in the field of artificial intelligence and other fields of table processing language in Lisp language. In Lisp language, generalized table is one of the most basic data structures, even the program of Lisp language is expressed as a series of generalized tables.

A generalized table is a finite sequence of A1,a2,...,ai,...,an of N (n≥0) elements.

which

①ai--is either an atom or a generalized table.

② generalized tables are usually written as: ls= (A1,a2,...,ai,...,an).

③ls is the name of the generalized table, and n is its length.

④ If the AI is a generalized table, it is called the sub-table of LS.

Attention:

① generalized tables are usually enclosed in parentheses, separating the elements with commas.

② in order to distinguish between atoms and generalized tables, write with uppercase letters representing generalized tables, with lowercase letters representing atoms.

③ if the generalized table LS is non-null (n≥1), then Al is the table header of LS, and the remaining elements of the table (A1,a2,...,an) are called the footer of LS.

④ Generalized tables are recursive-defined

I. Generalized table characteristics:
1. Hierarchy: The element of the generalized table can be a child table, and the element of the child table can be a child table, thus, the generalized table is a multi-level structure;
2. Sharing: Generalized tables can be shared by other tables.
3. Recursive table: A generalized table can be a sub-table of its own.


Second, depth and length

The Generalized table ((A, B, (), c), D), E, ((f), G)) is the length of ____, and the depth is ____.

The generalized table length is the number of commas in the first layer of parentheses to see that only one element is ((A, B, (), c), D), E, ((f), G), so the length is 1, the depth is the number of parentheses, and the depth is 4.


Third, the table head and the footer

According to the definition of table header and footer, the header of any non-null generalized table is the first element in a table, which can be an atom or a child table, and its footer must be a child table. That is, the head operation of the generalized table, what is the element taken out, and what is the result. However, the tail operation takes out an element that must be added to a table-"()" Problem: Known generalized table ls= ((a,b,c), (d,e,f)), the use of head and tail function to remove LS Zhongyuan sub-e operation is.
Known generalized table ls= ((a,b,c), (d,e,f)) therefore: tail (ls) = ((D,e,f)) head (tail (ls)) = (d,e,f) tail (head (tail (ls))) = (e,f) head (t AIL (Head (tail (LS))) =e


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.