## Concept:

# Sorting problem

## Headline

The problem of sorting a given list

## Description

The problem can be described, for example, as follows:

- Input:
- A list
*l*of values

- A list
- Output:
- A list
*r*satisfying these properties:*r*is a permutation is of*l*.*r*is sorted.

- A list

This is an algorithmic problem; there are various sorting algorithms, e.g., Quicksort.

## Illustration

### Sorting problem in Haskell

The ingredients of the above problem description, i.e., the test for two lists to be permutations of each other and the test for a list to be sorted, can be described more formally as follows; we use Language:Haskell notation:

```
-- Test for two lists to be permutations of each other
permutation :: Eq a => [a] -> [a] -> Bool
permutation [] [] = True
permutation (x:xs) ys = remove ys []
where
-- Repeat removal of equal elements
remove [] _ = False
remove (y:ys) zs =
if (x==y)
then permutation xs (zs++ys)
else remove ys (y:zs)
-- Test for a list to be sort
sorted :: Ord a => [a] -> Bool
sorted [] = True
sorted [x] = True
sorted (x1:x2:xs) = x1 <= x2 && sorted (x2:xs)
```

We apply the list properties to a few sample lists:

```
-- Illustrate list properties
main = do
let l1 = [2,4,3,1,4]
let l2 = [1,2,3,4,4]
let l3 = [1,8,2,7,4]
print $ sorted l1 -- False
print $ sorted l2 -- True
print $ sorted l3 -- False
print $ permutation l1 l2 -- True
print $ permutation l1 l3 -- False
```

## Metadata

### There are no revisions for this page.

## User contributions

## User edits

## Syntax for editing wiki

For you are available next options:will make text bold.

will make text italic.

will make text underlined.

will make text striked.

will allow you to paste code headline into the page.

will allow you to link into the page.

will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

will allow you to paste image into the page.

is list with bullets.

is list with numbers.

will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

will allow your to insert code snippets from
**
@worker.
**

#### 10 most similar pages:

- Concept:Sorting_problem - 3.1394384
- Concept:Binary search - 0.98188126
- Concept:Merge sort - 0.93050843
- Concept:Selection sort - 0.6631335
- Concept:Linear search - 0.56635934
- Concept:Search algorithm - 0.5439444
- Technology:QuickCheck - 0.5140834
- Concept:Insertion sort - 0.43215495
- Concept:Immutable list - 0.40885887
- Concept:Search problem - 0.39820704

## Syntax for editing wiki

For you are available next options:will make text bold.

will make text italic.

will make text underlined.

will make text striked.

will allow you to paste code headline into the page.

will allow you to link into the page.

will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

will allow you to paste image into the page.

is list with bullets.

is list with numbers.

will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

will allow your to insert code snippets from
**
@worker.
**