[go: nahoru, domu]

Jump to content

Editing List (abstract data type)

You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to a username, among other benefits.
Content that violates any copyrights will be deleted. Encyclopedic content must be verifiable through citations to reliable sources.
Latest revision Your text
Line 1: Line 1:
{{Short description|Finite, ordered collection of items}}
{{short description|Abstract data type used in computer science}}
{{About|sequential data structures|the fundamental concept of information ordering|List|random-access data structures|Array (data type)}}
{{about|sequential data structures|random-access data structures|Array data type}}
In [[computer science]], a '''list''' or '''sequence''' is [[collection (abstract data type)|collection]] of items that are finite in number and in a particular [[order theory|order]]. An [[Instance (computer science)|instance]] of a list is a computer representation of the [[mathematics|mathematical]] concept of a [[tuple]] or finite [[sequence]].
In [[computer science]], a '''list''' or '''sequence''' is an [[abstract data type]] that represents a countable number of ordered [[value (computer science)|values]], where the same value may occur more than once. An instance of a list is a computer representation of the [[mathematics|mathematical]] concept of a finite [[sequence (mathematics)|sequence]]; the (potentially) infinite analog of a list is a [[Stream (computing)|stream]].<ref>{{cite book |title=[[Structure and Interpretation of Computer Programs]] |first1=Harold |last1=Abelson |first2=Gerald Jay |last2=Sussman |year=1996 |publisher=MIT Press}}</ref>{{rp|§3.5}} Lists are a basic example of [[Container (abstract data type)|containers]], as they contain other values. If the same value occurs multiple times, each occurrence is considered a distinct item.


[[Image:Singly linked list.png|thumb|right|A singly linked list structure, implementing a list with 3 integer elements.]]
A list may contain the same value more than once, and each occurrence is considered a distinct item.
The name '''list''' is also used for several concrete [[data structures]] that can be used to implement abstract lists, especially [[linked list]]s.


Many [[programming language]]s provide support for '''list data types''', and have special syntax and semantics for lists and list operations. A list can often be constructed by writing the items in sequence, separated by [[comma]]s, [[semicolon]]s, and/or [[Space (punctuation)|spaces]], within a pair of delimiters such as [[parentheses]] '()', [[brackets]] '[]', [[Braces (punctuation)|braces]] '{}', or [[angle brackets]] '<>'. Some languages may allow list types to be [[Array index|indexed]] or [[array slicing|sliced]] like [[array data type|array type]]s, in which case the data type is more accurately described as an array. In [[object-oriented programming language]]s, lists are usually provided as [[instance (computer science)|instance]]s of subclasses of a generic "list" class, and traversed via separate [[iterator]]s. List data types are often implemented using [[array data structure]]s or linked lists of some sort, but other [[data structures]] may be more appropriate for some applications. In some contexts, such as in [[Lisp programming language|Lisp]] programming, the term list may refer specifically to a linked list rather than an array.
[[File:Singly-linked-list.svg|thumb|right|A singly-linked list structure, implementing a list with three integer elements.]]
The term ''list'' is also used for several concrete [[data structure]]s that can be used to implement [[abstract type|abstract]] lists, especially [[linked list]]s and [[array data structure|array]]s. In some contexts, such as in [[Lisp programming language|Lisp]] programming, the term list may refer specifically to a linked list rather than an array. In [[class-based programming]], lists are usually provided as [[instance (computer science)|instance]]s of subclasses of a generic "list" class, and traversed via separate [[iterator]]s.

Many [[programming language]]s provide support for '''list data types''', and have special syntax and semantics for lists and list operations. A list can often be constructed by writing the items in sequence, separated by [[comma]]s, [[semicolon]]s, and/or [[space (punctuation)|space]]s, within a pair of delimiters such as [[parentheses]] '()', [[bracket]]s '[]', [[brace (punctuation)|brace]]s '{}', or [[angle bracket]]s '<>'. Some languages may allow list types to be [[array index|index]]ed or [[array slicing|slice]]d like [[array data type|array type]]s, in which case the data type is more accurately described as an array.


In [[type theory]] and [[functional programming]], abstract lists are usually defined [[inductive type|inductively]] by two operations: ''nil'' that yields the empty list, and ''cons'', which adds an item at the beginning of a list.<ref>{{cite book|last1=Reingold|first1=Edward|last2=Nievergelt|first2=Jurg|last3=Narsingh|first3=Deo|title=Combinatorial Algorithms: Theory and Practice|date=1977|publisher=Prentice Hall|location=Englewood Cliffs, New Jersey|isbn=0-13-152447-X|pages=38–41}}</ref>
In [[type theory]] and [[functional programming]], abstract lists are usually defined [[inductive type|inductively]] by two operations: ''nil'' that yields the empty list, and ''cons'', which adds an item at the beginning of a list.<ref>{{cite book|last1=Reingold|first1=Edward|last2=Nievergelt|first2=Jurg|last3=Narsingh|first3=Deo|title=Combinatorial Algorithms: Theory and Practice|date=1977|publisher=Prentice Hall|location=Englewood Cliffs, New Jersey|isbn=0-13-152447-X|pages=38–41}}</ref>

A [[stream (abstract data type)|stream]] is the potentially infinite analog of a list.<ref>{{cite book |title=[[Structure and Interpretation of Computer Programs]] |first1=Harold |last1=Abelson |first2=Gerald Jay |last2=Sussman |year=1996 |publisher=MIT Press}}</ref>{{rp|§3.5}}


==Operations==
==Operations==
Implementation of the list data structure may provide some of the following [[operation (mathematics)|operations]]:
Implementation of the list data structure may provide some of the following [[operation (mathematics)|operations]]:
* a [[constructor (computer science)|constructor]] for creating an empty list;

* an operation for testing whether or not a list is empty;
* [[constructor (computer science)|create]]
* an operation for prepending an entity to a list
* test for empty
* an operation for appending an entity to a list
* add item to beginning or end
* access the first or last item
* an operation for determining the first component (or the "head") of a list
* an operation for referring to the list consisting of all the components of a list except for its first (this is called the "tail" of the list.)
* access an item by index
* an operation for accessing the element at a given index.


==Implementations==
==Implementations==
Line 28: Line 25:
The standard way of implementing lists, originating with the programming language [[Lisp (programming language)|Lisp]], is to have each element of the list contain both its value and a pointer indicating the location of the next element in the list. This results in either a [[linked list]] or a [[tree data structure|tree]], depending on whether the list has nested sublists. Some older Lisp implementations (such as the Lisp implementation of the [[Symbolics]] 3600) also supported "compressed lists" (using [[CDR coding]]) which had a special internal representation (invisible to the user). Lists can be manipulated using [[iteration]] or [[recursion]]. The former is often preferred in [[imperative programming|imperative programming languages]], while the latter is the norm in [[functional language]]s.
The standard way of implementing lists, originating with the programming language [[Lisp (programming language)|Lisp]], is to have each element of the list contain both its value and a pointer indicating the location of the next element in the list. This results in either a [[linked list]] or a [[tree data structure|tree]], depending on whether the list has nested sublists. Some older Lisp implementations (such as the Lisp implementation of the [[Symbolics]] 3600) also supported "compressed lists" (using [[CDR coding]]) which had a special internal representation (invisible to the user). Lists can be manipulated using [[iteration]] or [[recursion]]. The former is often preferred in [[imperative programming|imperative programming languages]], while the latter is the norm in [[functional language]]s.


Lists can be implemented as [[self-balancing binary search tree]]s holding index-value pairs, providing equal-time access to any element (e.g. all residing in the fringe, and internal nodes storing the right-most child's index, used to guide the search), taking the time logarithmic in the list's size, but as long as it doesn't change much will provide the illusion of [[random access]] and enable swap, prefix and append operations in logarithmic time as well.<ref>{{cite web|last1=Barnett|first1=Granville|last2=Del tonga|first2=Luca|title=Data Structures and Algorithms|url=http://www.mta.ca/~rrosebru/oldcourse/263114/Dsa.pdf|website=mta.ca|access-date=12 November 2014|date=2008}}</ref>
Lists can be implemented as [[self-balancing binary search tree]]s holding index-value pairs, providing equal-time access to any element (e.g. all residing in the fringe, and internal nodes storing the right-most child's index, used to guide the search), taking the time logarithmic in the list's size, but as long as it doesn't change much will provide the illusion of [[random access]] and enable swap, prefix and append operations in logarithmic time as well.<ref>{{cite web|last1=Barnett|first1=Granville|last2=Del tonga|first2=Luca|title=Data Structures and Algorithms|url=http://www.mta.ca/~rrosebru/oldcourse/263114/Dsa.pdf|website=mta.ca|accessdate=12 November 2014|date=2008}}</ref>


==Programming language support==
==Programming language support==
Some [[Computer language|languages]] do not offer a list [[data structure]], but offer the use of [[associative array]]s or some kind of table to emulate lists. For example, [[Lua programming language|Lua]] provides tables. Although Lua stores lists that have numerical indices as arrays internally, they still appear as dictionaries.<ref>{{cite book|last1=Lerusalimschy|first1=Roberto|title=Programming in Lua (first edition)|date=December 2003|publisher=Lua.org|isbn=8590379817|edition=First|url=http://www.lua.org/pil/11.3.html|access-date=12 November 2014}}</ref>
Some languages do not offer a list [[data structure]], but offer the use of [[associative array]]s or some kind of table to emulate lists. For example, [[Lua programming language|Lua]] provides tables. Although Lua stores lists that have numerical indices as arrays internally, they still appear as dictionaries.<ref>{{cite book|last1=Lerusalimschy|first1=Roberto|title=Programming in Lua (first edition)|date=December 2003|publisher=Lua.org|isbn=8590379817|edition=First|url=http://www.lua.org/pil/11.3.html|accessdate=12 November 2014}}</ref>


In [[Lisp programming language|Lisp]], lists are the fundamental data type and can represent both program code and data. In most dialects, the list of the first three prime numbers could be written as <code>(list 2 3 5)</code>. In several dialects of Lisp, including [[Scheme (programming language)|Scheme]], a list is a collection of pairs, consisting of a value and a pointer to the next pair (or null value), making a singly linked list.<ref>{{cite book|last1=Steele|first1=Guy|title=Common Lisp|date=1990|publisher=Digital Press|isbn=1-55558-041-6|pages=29–31|edition=Second}}</ref>
In [[Lisp programming language|Lisp]], lists are the fundamental data type and can represent both program code and data. In most dialects, the list of the first three prime numbers could be written as <code>(list 2 3 5)</code>. In several dialects of Lisp, including [[Scheme (programming language)|Scheme]], a list is a collection of pairs, consisting of a value and a pointer to the next pair (or null value), making a singly linked list.<ref>{{cite book|last1=Steele|first1=Guy|title=Common Lisp|date=1990|publisher=Digital Press|isbn=1-55558-041-6|pages=29–31|edition=Second}}</ref>


==Applications==
==Applications==
As the name implies, lists can be used to store a list of elements. However, unlike in traditional [[array data structure|arrays]], lists can expand and shrink, and are stored dynamically in memory.

Unlike in an [[array data structure|array]], a list can expand and shrink.


In computing, lists are easier to implement than sets. A finite [[set (mathematics)|set]] in the mathematical sense can be realized as a list with additional restrictions; that is, duplicate elements are disallowed and order is irrelevant. Sorting the list speeds up determining if a given item is already in the set, but in order to ensure the order, it requires more time to add new entry to the list. In efficient implementations, however, sets are implemented using [[self-balancing binary search tree]]s or [[hash table]]s, rather than a list.
In computing, lists are easier to implement than sets. A finite [[set (mathematics)|set]] in the mathematical sense can be realized as a list with additional restrictions; that is, duplicate elements are disallowed and order is irrelevant. Sorting the list speeds up determining if a given item is already in the set, but in order to ensure the order, it requires more time to add new entry to the list. In efficient implementations, however, sets are implemented using [[self-balancing binary search tree]]s or [[hash table]]s, rather than a list.
Line 85: Line 81:


Lists form a [[monoid]] under the ''append'' operation. The identity element of the monoid is the empty list, ''nil''. In fact, this is the [[free monoid]] over the set of list elements.
Lists form a [[monoid]] under the ''append'' operation. The identity element of the monoid is the empty list, ''nil''. In fact, this is the [[free monoid]] over the set of list elements.

==References==
{{reflist}}


==See also==
==See also==
{{Wiktionary|list}}
{{Wiktionary|list}}
* {{Annotated link|Array data type}}
*[[Array data type|Array]]
* {{Annotated link|Queue (abstract data type)|Queue}}
*[[Queue (abstract data type)|Queue]]
* {{Annotated link|Set (abstract data type)|Set}}
*[[Set (abstract data type)|Set]]
* {{Annotated link|Stack (abstract data type)|Stack}}
*[[Stack (abstract data type)|Stack]]
* {{Annotated link|Stream (computing)|Stream}}
*[[Stream (computing)|Stream]]

==References==
{{Reflist}}

{{Data structures}}
{{Data structures}}
{{Data types}}
{{Data types}}
{{Authority control}}


{{DEFAULTSORT:List (Computing)}}
{{DEFAULTSORT:List (Computing)}}
By publishing changes, you agree to the Terms of Use, and you irrevocably agree to release your contribution under the CC BY-SA 4.0 License and the GFDL. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel Editing help (opens in new window)

Copy and paste: – — ° ′ ″ ≈ ≠ ≤ ≥ ± − × ÷ ← → · §   Cite your sources: <ref></ref>


{{}}   {{{}}}   |   []   [[]]   [[Category:]]   #REDIRECT [[]]   &nbsp;   <s></s>   <sup></sup>   <sub></sub>   <code></code>   <pre></pre>   <blockquote></blockquote>   <ref></ref> <ref name="" />   {{Reflist}}   <references />   <includeonly></includeonly>   <noinclude></noinclude>   {{DEFAULTSORT:}}   <nowiki></nowiki>   <!-- -->   <span class="plainlinks"></span>


Symbols: ~ | ¡ ¿ † ‡ ↔ ↑ ↓ • ¶   # ∞   ‹› «»   ¤ ₳ ฿ ₵ ¢ ₡ ₢ $ ₫ ₯ € ₠ ₣ ƒ ₴ ₭ ₤ ℳ ₥ ₦ № ₧ ₰ £ ៛ ₨ ₪ ৳ ₮ ₩ ¥   ♠ ♣ ♥ ♦   𝄫 ♭ ♮ ♯ 𝄪   © ® ™
Latin: A a Á á À à  â Ä ä Ǎ ǎ Ă ă Ā ā à ã Å å Ą ą Æ æ Ǣ ǣ   B b   C c Ć ć Ċ ċ Ĉ ĉ Č č Ç ç   D d Ď ď Đ đ Ḍ ḍ Ð ð   E e É é È è Ė ė Ê ê Ë ë Ě ě Ĕ ĕ Ē ē Ẽ ẽ Ę ę Ẹ ẹ Ɛ ɛ Ǝ ǝ Ə ə   F f   G g Ġ ġ Ĝ ĝ Ğ ğ Ģ ģ   H h Ĥ ĥ Ħ ħ Ḥ ḥ   I i İ ı Í í Ì ì Î î Ï ï Ǐ ǐ Ĭ ĭ Ī ī Ĩ ĩ Į į Ị ị   J j Ĵ ĵ   K k Ķ ķ   L l Ĺ ĺ Ŀ ŀ Ľ ľ Ļ ļ Ł ł Ḷ ḷ Ḹ ḹ   M m Ṃ ṃ   N n Ń ń Ň ň Ñ ñ Ņ ņ Ṇ ṇ Ŋ ŋ   O o Ó ó Ò ò Ô ô Ö ö Ǒ ǒ Ŏ ŏ Ō ō Õ õ Ǫ ǫ Ọ ọ Ő ő Ø ø Œ œ   Ɔ ɔ   P p   Q q   R r Ŕ ŕ Ř ř Ŗ ŗ Ṛ ṛ Ṝ ṝ   S s Ś ś Ŝ ŝ Š š Ş ş Ș ș Ṣ ṣ ß   T t Ť ť Ţ ţ Ț ț Ṭ ṭ Þ þ   U u Ú ú Ù ù Û û Ü ü Ǔ ǔ Ŭ ŭ Ū ū Ũ ũ Ů ů Ų ų Ụ ụ Ű ű Ǘ ǘ Ǜ ǜ Ǚ ǚ Ǖ ǖ   V v   W w Ŵ ŵ   X x   Y y Ý ý Ŷ ŷ Ÿ ÿ Ỹ ỹ Ȳ ȳ   Z z Ź ź Ż ż Ž ž   ß Ð ð Þ þ Ŋ ŋ Ə ə
Greek: Ά ά Έ έ Ή ή Ί ί Ό ό Ύ ύ Ώ ώ   Α α Β β Γ γ Δ δ   Ε ε Ζ ζ Η η Θ θ   Ι ι Κ κ Λ λ Μ μ   Ν ν Ξ ξ Ο ο Π π   Ρ ρ Σ σ ς Τ τ Υ υ   Φ φ Χ χ Ψ ψ Ω ω   {{Polytonic|}}
Cyrillic: А а Б б В в Г г   Ґ ґ Ѓ ѓ Д д Ђ ђ   Е е Ё ё Є є Ж ж   З з Ѕ ѕ И и І і   Ї ї Й й Ј ј К к   Ќ ќ Л л Љ љ М м   Н н Њ њ О о П п   Р р С с Т т Ћ ћ   У у Ў ў Ф ф Х х   Ц ц Ч ч Џ џ Ш ш   Щ щ Ъ ъ Ы ы Ь ь   Э э Ю ю Я я   ́
IPA: t̪ d̪ ʈ ɖ ɟ ɡ ɢ ʡ ʔ   ɸ β θ ð ʃ ʒ ɕ ʑ ʂ ʐ ç ʝ ɣ χ ʁ ħ ʕ ʜ ʢ ɦ   ɱ ɳ ɲ ŋ ɴ   ʋ ɹ ɻ ɰ   ʙ ⱱ ʀ ɾ ɽ   ɫ ɬ ɮ ɺ ɭ ʎ ʟ   ɥ ʍ ɧ   ʼ   ɓ ɗ ʄ ɠ ʛ   ʘ ǀ ǃ ǂ ǁ   ɨ ʉ ɯ   ɪ ʏ ʊ   ø ɘ ɵ ɤ   ə ɚ   ɛ œ ɜ ɝ ɞ ʌ ɔ   æ   ɐ ɶ ɑ ɒ   ʰ ʱ ʷ ʲ ˠ ˤ ⁿ ˡ   ˈ ˌ ː ˑ ̪   {{IPA|}}

Wikidata entities used in this page

  • list: Sitelink, Title, Some statements, Miscellaneous (e.g. aliases, entity existence), Description: en

Pages transcluded onto the current version of this page (help):