Untitled
unknown
plain_text
5 months ago
466 B
6
Indexable
quick_sort <- function(x) { if (length(x) <= 1) return(x) pivot <- x[1] left <- quick_sort(x[x < pivot]) right <- quick_sort(x[x > pivot]) return(c(left, pivot, right)) } # Binary Search implementation binary_search <- function(x, target) { low <- 1 high <- length(x) while (low <= high) { mid <- floor((low + high) / 2) if (x[mid] == target) { return(mid) } else if (x[mid] < target) { low <- mid + 1 } else { high <- mid - 1
Editor is loading...
Leave a Comment