## 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.1744704
- Concept:Binary search - 0.9876267
- Concept:Merge sort - 0.92282283
- Concept:Selection sort - 0.66468644
- Concept:Linear search - 0.57214946
- Concept:Search algorithm - 0.54992664
- Technology:QuickCheck - 0.5151021
- Concept:Insertion sort - 0.43059385
- Concept:Immutable list - 0.41614813
- Concept:Search problem - 0.39926967

## 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.
**