Untitled
unknown
plain_text
a year ago
462 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 - 1Editor is loading...
Leave a Comment