Computing Students - Computer Science Degree Notes
Home Contact Shop Notes Questions Programming Links Dictionary Coursework FORUM Tutors
  Recommended Kelkoo Searches: Computer Science | Computing | Computer Systems | Database | Computing Revision  

Notes > Models of Computation > Lists

Lists are data structures that consist of a collection of elements which are stored in a sequence. Different operations can be carried out on lists to either read the data held by them or to add data to them. Operations that retrieve elements from the list do not change the original list and its contents.

Similar to the notation for sets, a list can be represented as follows: [1,2,3,4,5]. This list contains five elements which happen to be numbers. Strings can just as easily be stored in a list. An empty list is denoted by [].

The "head" of a list refers to the first element in the list and the "tail" refers to the rest of the list. A list can contain repeated elements therefore the list [1,2,3,4,5,4,5] is a valid list.

To retrieve elements from a list the commands "head" and "tail" can be used in conjuntion with the list name. For example, the command "head(X)" where X is the list will retrive the single value at the head of the list. "tail(X)" will return another list of elements that excludes the first element that existed in the original list X.

Combinations of commands such as "head(tail(X))" can be used to retrieve single elements within the list. This means that any number can actually be returned using a combination of the commands "head" and "tail".

For the given list X = [2,5,7,2,3,6] the following commands will give the stated outputs:

  • head(X) = 2
  • tail(X) = [5,7,2,3,6]
  • head(tail(X)) = 5
  • tail(tail(X)) = [7,2,3,6]
  • head(tail(tail(X))) = 7
Lists can be combined or "concatenated". For example, the list [1,2,3] concatenated with [2,5,6,8,9] gives the list [1,2,3,2,5,6,8,9]

List construction can be undertaken using the commands "cons" and "nil()". "cons" represents the concatenate command. The "nil()" function simply inserts an empty value at the end of the list. The command "cons(5, cons(2, cons(6, nil())))" will produce the resultant list [5,2,6]

Of the list functions mentioned already there are two main types: Constructors and Selectors. "cons" and "nil" are known as constructors, because they are involved in creating new lists. "head" and "tail" are called selectors, as they take a list and return elements of the list.

Search for "Lists" on: Google | Kelkoo | Amazon | eBay (UK) | eBay (US)

Search for "Lists" on the rest of Computing Students: Lists






Home | Contact | Shop | Notes | Questions | Programming | Links | Dictionary | Coursework | Tutors Sponsored Links: Affiliate Program Articles | Computer Science Definitions | CS Degree Notes
Copyright © 2005-2009 ComputingStudents.com
This site is to be used in accordance with the ComputingStudents.com User Agreement
High Wycombe Web Design