# List (Sequence)

AKA: Sequence, $$a_n$$ where n is the nth element, (1,2,3, ….)

Distinct from: Set

Measure of:

Description: A list is a collection of objects with a specific ordering and where the same object can appear more than once. Call each object an element, and its location its index or rank. An index is a natural number counting upward from the first element in the list. Whether counting begins at 0 or 1 depends on local conventions.

Formalization:

Algorithm:

Documentation:

list: Lists – Generic and Dotted Pairs

Examples:

example_list = list(1,2,3)
example_list
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3

Sorting a list in R Sorting or Ordering Vectors

You can specify auto, shell, quick, or radix algorithms. Auto typically chooses radix. Radix applies to lexigraphical data, e.g. string and numbers. Radix has $$O(nw)$$ time where $$n$$ is the number of keys and $$w$$ is the length of the keys.

Fast, stable and scalable true radix sorting

*Radix because it’s fast for R’s use case

*It is stable. Stable sorts preserve the original order of two elements if they are equal by the sorting criteria.

temp <- 5:1
sort(temp)
[1] 1 2 3 4 5

Documentation:

More on Lists

Examples:

example_list =  [1,2,3]
example_list
[1, 2, 3]

The ‘range’ function returns a generator for integers from between start to (stop-1). It’ll do reverse as well but you have to pass a third decrement term. The Python range() Function (Guide)

[q for q in range(5,10)]
[5, 6, 7, 8, 9]
[q for q in range(10,5,-1)]
[10, 9, 8, 7, 6]

Python lists have to ways to sort, in palce with “sort” or returning a new list with “sorted”. Sorting HOW TO

Python uses Timsort whose best case is $$O(n)$$ and worst and average case are both $$O(nlog(n))$$

temp=[q for q in range(10,5,-1)]
temp
[10, 9, 8, 7, 6]
temp.sort()
temp
[6, 7, 8, 9, 10]
temp=[q for q in range(10,5,-1)]
sorted(temp)
[6, 7, 8, 9, 10]
library(DBI)
# Create an ephemeral in-memory RSQLite database
con <- dbConnect(RSQLite::SQLite(), dbname = ":memory:")
dbListTables(con)
character(0)
dbWriteTable(con, "mtcars", mtcars)
dbListTables(con)
[1] "mtcars"
create table StatisticalNumbers(
value int
)
SELECT * FROM mtcars LIMIT 5;
5 records
mpg cyl disp hp drat wt qsec vs am gear carb
21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
18.7 8 360 175 3.15 3.440 17.02 0 0 3 2