Just for creating some graphs, because it is easier to use an overkill and complicated system that I have some familiarity with for creating some simply graphs then to find, install, and use something better suited for the task.

library(ggplot2)
library(tidyverse)

We need a fake “true function for our f(x) and I want it to be in O(x^3)

fn <- function(x) {
    y <- 4.5 * (x^3) - 100 * (x^2) + (50000 * x) + 10000000
    return(y)
}
cols <- c("f(n)" = "#E69F00", "g(n)" = "#56B4E9")
base <- ggplot() +
    geom_function(aes(color = "f(n)"),
        fun = fn, linewidth = 2) +
    scale_color_manual(values = cols) +
    labs(x = "Size of imput", y = "Number of operations") +
    theme(plot.background = element_rect(fill = "transparent", color = NA),
        legend.position = c(0.9, 0.1),
        legend.title = element_blank()) +
    scale_y_continuous(labels = function(x) format(x, scientific = FALSE))
## Warning: A numeric `legend.position` argument in `theme()` was deprecated in ggplot2
## 3.5.0.
## ℹ Please use the `legend.position.inside` argument of `theme()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
p <- base + xlim(0, 360) + theme(legend.position = "none")
p
Operations grow by f(n)

Operations grow by f(n)

ggsave("time_only.pdf", bg = "transparent")
## Saving 7 x 5 in image
bound_line <- geom_function(aes(color = "Bound"),
    fun =  function(x) 5 * x^3,
    size = 2)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
p <- base + xlim(0, 100) + bound_line
p
Growth of f(n) and g(n) for small n.

Growth of f(n) and g(n) for small n.

ggsave("start_plot.pdf", bg = "transparent")
## Saving 7 x 5 in image

Intersection of complexity and \(5x^3\)

x0 <- 100 * sqrt(10)
p <- base + xlim(0, 380) + bound_line +
    geom_vline(xintercept = x0, linetype = "dotted")
p
Growth of f(n) and g(n) where g overtakes f.

Growth of f(n) and g(n) where g overtakes f.

ggsave("big_plot.pdf", bg = "transparent")
## Saving 7 x 5 in image

With

\[\begin{equation} f(x) = 4.5x^3 - 100x^2 + 50000x + 10000000 \end{equation}\]

and

\[\begin{equation} g(x) = 5x^3 \end{equation}\]

The intersection should be at the roots of

\[\begin{equation} g(x) - f(x) = -0.5x^3 - 100x^2 + 50000x + 10000000 \end{equation}\]