bsort.df: Time taken to sort random vectors of various lengths using...

bsort.dfR Documentation

Time taken to sort random vectors of various lengths using bubble sort.

Description

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.

Usage

bsort.df

Format

A data.frame with 200 rows and 2 columns:

n

Size of the random vector.

time

Time in seconds taken to sort the vector using bubbleSort.

Details

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.

See Also

bubbleSort


jmcurran/jaggR documentation built on Nov. 2, 2023, 11:04 a.m.