{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9b706f3d-a825-45bf-874b-5574311d96c1",
   "metadata": {},
   "source": [
    "### <center>San Jose State University<br>Department of Applied Data Science<br><br>**DATA 200<br>Computational Programming for Data Analytics**<br><br>Spring 2024<br>Instructor: Ron Mak</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "128a927d-0a06-4273-a0d0-9ec37d8f1f1b",
   "metadata": {},
   "source": [
    "# Graph of *n*log(*n*)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ecbe20e7-a228-4beb-ae75-4dfecd8858f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f0ac2526-88f0-46f3-b19c-dc660c3200a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "size = 1000\n",
    "\n",
    "n     = list(range(1, size + 1))\n",
    "nlogn = [i*np.log(i) for i in range(1, size + 1)]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5f8f0815-35fc-4274-9747-8941aeb69ced",
   "metadata": {},
   "source": [
    "## *n*log(*n*) is nearly linear"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47de826e-7d54-493e-bbf7-efd866cb1e31",
   "metadata": {},
   "outputs": [],
   "source": [
    "sns.set()\n",
    "plt.figure(figsize=(8, 10))\n",
    "\n",
    "ax = sns.lineplot(x=n, y=nlogn, label='y = n*log(n)')\n",
    "\n",
    "slope = (size*np.log(size) - np.log(0.5))/1000\n",
    "ax = sns.lineplot(x=[1, size + 1],\n",
    "                  y=[np.log(1), size*np.log(size/2)],\n",
    "                  linestyle='dashed',\n",
    "                  label=f'linear y = {slope:0.2f}*n')\n",
    "\n",
    "ax.set(xlabel='n', ylabel='y')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca14c36c-897a-42bf-a2a5-b0e4538b4cba",
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "480495b0-e18e-4540-a6dc-1791ea999dba",
   "metadata": {},
   "outputs": [],
   "source": [
    "# (c) 2023 by Ronald Mak"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
