bsort.df | R Documentation |
Students learning to programme are often taught the bubble sort algorithm for several reasons. Firstly, sorting is a commonly used operation in programming, so having a way of sorting vectors into order is useful. Secondly, it lets the instructor talk about the order of the algorithm, and how it is very inefficient. In computer science, big O notation is used to classify algorithms according to how their run time or space requirements grow as the input size grows. The bubble sort algorithm is known to be O(n^2). That is, the time taken to run the algorithm increases quadratically (with the square) with the size of the vector.
bsort.df
A data.frame with 200 rows and 2 columns:
Size of the random vector.
Time in seconds taken to sort the vector using bubbleSort
.
This data set consists of 200 observations generated using the following code: “' set.seed(123) N = 200 bsort.df = data.frame(n = rep(0, N), time = rep(0, N))
n = sample(100:1000, size = N, replace = TRUE)
pb = txtProgressBar(0, N, style = 3)
for(i in 1:N) x = rnorm(n[i]) bsort.df$n[i] = n[i] bsort.df$time[i] = system.time(bubbleSort(x))[1] setTxtProgressBar(pb, i) close(pb) “' It consists of the times taken to sort 200 vectors of random length between 100 and 1,000. The vectors themselves are random samples of size n[i] from the standard normal distribution.
bubbleSort
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.