{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "e631810e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "12fa3ed1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# CMU Serif\n",
    "plt.rcParams['font.family'] = 'CMU Serif'\n",
    "plt.rcParams['mathtext.fontset'] = 'cm'\n",
    "plt.rcParams['font.size'] = 14\n",
    "plt.rcParams['axes.titlesize'] = 16\n",
    "plt.rcParams['axes.labelsize'] = 15\n",
    "plt.rcParams['xtick.labelsize'] = 13\n",
    "plt.rcParams['ytick.labelsize'] = 13\n",
    "plt.rcParams['legend.fontsize'] = 12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c691c40e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Structure</th>\n",
       "      <th>Mode</th>\n",
       "      <th>Operation</th>\n",
       "      <th>Time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Связный список</td>\n",
       "      <td>Случайный</td>\n",
       "      <td>Вставка</td>\n",
       "      <td>0.199516</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Связный список</td>\n",
       "      <td>Случайный</td>\n",
       "      <td>Поиск</td>\n",
       "      <td>0.024629</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Связный список</td>\n",
       "      <td>Случайный</td>\n",
       "      <td>Удаление</td>\n",
       "      <td>0.014065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Связный список</td>\n",
       "      <td>Случайный</td>\n",
       "      <td>Вставка</td>\n",
       "      <td>0.196946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Связный список</td>\n",
       "      <td>Случайный</td>\n",
       "      <td>Поиск</td>\n",
       "      <td>0.023807</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>373</th>\n",
       "      <td>Бинарное дерево поиска</td>\n",
       "      <td>Отсортированный</td>\n",
       "      <td>Поиск</td>\n",
       "      <td>0.062731</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>374</th>\n",
       "      <td>Бинарное дерево поиска</td>\n",
       "      <td>Отсортированный</td>\n",
       "      <td>Удаление</td>\n",
       "      <td>0.062908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>375</th>\n",
       "      <td>Бинарное дерево поиска</td>\n",
       "      <td>Отсортированный</td>\n",
       "      <td>Вставка (среднее)</td>\n",
       "      <td>0.952690</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>376</th>\n",
       "      <td>Бинарное дерево поиска</td>\n",
       "      <td>Отсортированный</td>\n",
       "      <td>Поиск (среднее)</td>\n",
       "      <td>0.060593</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>377</th>\n",
       "      <td>Бинарное дерево поиска</td>\n",
       "      <td>Отсортированный</td>\n",
       "      <td>Удаление (среднее)</td>\n",
       "      <td>0.064886</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>378 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Structure             Mode           Operation      Time\n",
       "0            Связный список        Случайный             Вставка  0.199516\n",
       "1            Связный список        Случайный               Поиск  0.024629\n",
       "2            Связный список        Случайный            Удаление  0.014065\n",
       "3            Связный список        Случайный             Вставка  0.196946\n",
       "4            Связный список        Случайный               Поиск  0.023807\n",
       "..                      ...              ...                 ...       ...\n",
       "373  Бинарное дерево поиска  Отсортированный               Поиск  0.062731\n",
       "374  Бинарное дерево поиска  Отсортированный            Удаление  0.062908\n",
       "375  Бинарное дерево поиска  Отсортированный   Вставка (среднее)  0.952690\n",
       "376  Бинарное дерево поиска  Отсортированный     Поиск (среднее)  0.060593\n",
       "377  Бинарное дерево поиска  Отсортированный  Удаление (среднее)  0.064886\n",
       "\n",
       "[378 rows x 4 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "csv_path = \"../../source/results/benchmarks.csv\"\n",
    "\n",
    "data = pd.read_csv(csv_path)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "a3737f45",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(np.float64(0.023733), np.float64(0.193345), np.float64(0.014249))"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Получение данных для Связного списка\n",
    "\n",
    "ll_random_insert  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Вставка'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ll_random_insert_average  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Вставка (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "ll_random_search  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Поиск'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ll_random_search_average  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Поиск (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "ll_random_delete  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Удаление'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ll_random_delete_average  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Удаление (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "ll_random_search_average, ll_random_insert_average, ll_random_delete_average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5434d260",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(np.float64(0.034479), np.float64(0.193979), np.float64(0.024509))"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Получение данных для Связного списка\n",
    "\n",
    "ll_sorted_insert  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Вставка'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ll_sorted_insert_average  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Вставка (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "ll_sorted_search  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Поиск'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ll_sorted_search_average  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Поиск (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "ll_sorted_delete  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Удаление'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ll_sorted_delete_average  = data.loc[\n",
    "        (data['Structure'] == 'Связный список') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Удаление (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "ll_sorted_search_average, ll_sorted_insert_average, ll_sorted_delete_average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "3deed9a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(np.float64(0.0), np.float64(0.003635), np.float64(5e-05))"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Получение данных для хеш таблицы\n",
    "ht_random_insert  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Вставка'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ht_random_insert_average  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Вставка (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "ht_random_search  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Поиск'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ht_random_search_average  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Поиск (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "ht_random_delete  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Удаление'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ht_random_delete_average  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Удаление (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "ht_random_delete_average, ht_random_insert_average, ht_random_search_average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "490e5c46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(np.float64(0.000163), np.float64(0.003181), np.float64(0.000109))"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Получение данных для хеш таблицы\n",
    "ht_sorted_insert  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Вставка'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ht_sorted_insert_average  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Вставка (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "ht_sorted_search  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Поиск'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ht_sorted_search_average  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Поиск (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "ht_sorted_delete  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Удаление'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "ht_sorted_delete_average  = data.loc[\n",
    "        (data['Structure'] == 'Хеш таблица') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Удаление (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "ht_sorted_delete_average, ht_sorted_insert_average, ht_sorted_search_average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "9d7274ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(np.float64(0.000481), np.float64(0.006081), np.float64(0.000336))"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Получение данных для дерева\n",
    "bst_random_insert  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Вставка'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "bst_random_insert_average  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Вставка (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "bst_random_search  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Поиск'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "bst_random_search_average  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Поиск (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "bst_random_delete  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Удаление'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "bst_random_delete_average  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Случайный') & (data['Operation'] == 'Удаление (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "bst_random_delete_average, bst_random_insert_average, bst_random_search_average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "92a545c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(np.float64(0.064886), np.float64(0.95269), np.float64(0.060593))"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#Получение данных для дерева\n",
    "bst_sorted_insert  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Вставка'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "bst_sorted_insert_average  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Вставка (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "bst_sorted_search  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Поиск'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "bst_sorted_search_average  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Поиск (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "bst_sorted_delete  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Удаление'),\n",
    "        'Time'\n",
    "    ].tolist()\n",
    "bst_sorted_delete_average  = data.loc[\n",
    "        (data['Structure'] == 'Бинарное дерево поиска') &  (data['Mode'] == 'Отсортированный') & (data['Operation'] == 'Удаление (среднее)'),\n",
    "        'Time'\n",
    "    ].iloc[0]\n",
    "\n",
    "bst_sorted_delete_average, bst_sorted_insert_average, bst_sorted_search_average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b2e93d6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# countUsers           = 10_000\n",
    "# countRepeat          = 10\n",
    "# countRandomSearch    = 200\n",
    "# countNotExitstSearch = 100\n",
    "# countDeletes         = 500\n",
    "\n",
    "countUsers           = 20_000\n",
    "countRepeat          = 20\n",
    "countRandomSearch    = 1000\n",
    "countNotExitstSearch = 500\n",
    "countDeletes         = 1000\n",
    "\n",
    "ll_col = 'blue'\n",
    "ht_col = 'orange'\n",
    "bst_col = 'green'\n",
    "\n",
    "iterations = range(countRepeat)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "208784a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 92548 characters]",
      "text/plain": [
       "<Figure size 1400x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Создание двух графиков рядом\n",
    "fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))\n",
    "\n",
    "# ============= Левый график: случайные данные =============\n",
    "ax1.set_title(\"Вставка случайных данных\")\n",
    "ax1.set_ylabel('Время, с')\n",
    "ax1.set_xlabel('Повторения')\n",
    "ax1.set_xticks(iterations)\n",
    "\n",
    "# Связный список\n",
    "ax1.scatter(iterations, ll_random_insert, label='связный список', color=ll_col)\n",
    "ax1.axhline(y=ll_random_insert_average, color=ll_col, linewidth=1, \n",
    "            linestyle='--', alpha=0.7)\n",
    "\n",
    "# Хеш таблица\n",
    "\n",
    "ax1.scatter(iterations, ht_random_insert, label='хеш таблица', color=ht_col)\n",
    "ax1.axhline(y=ht_random_insert_average, color=ht_col, linewidth=1, \n",
    "            linestyle='--', alpha=0.7)\n",
    "\n",
    "# Дерево\n",
    "\n",
    "ax1.scatter(iterations, bst_random_insert, label='дерево', color=bst_col)\n",
    "ax1.axhline(y=bst_random_insert_average, color=bst_col, linewidth=1, \n",
    "            linestyle='--', alpha=0.7)\n",
    "\n",
    "ax1.legend(loc='best')\n",
    "ax1.grid(True, alpha=0.3)\n",
    "\n",
    "# ============= Правый график: отсортированные данные =============\n",
    "ax2.set_title(\"Вставка отсортированных данных\")\n",
    "ax2.set_ylabel('Время, с')\n",
    "ax2.set_xlabel('Повторения')\n",
    "ax2.set_xticks(iterations)\n",
    "# ax2.set_xticklabels(range(1, 6))\n",
    "\n",
    "# Связный список\n",
    "ax2.scatter(iterations, ll_sorted_insert, label='связный список', color=ll_col)\n",
    "ax2.axhline(y=ll_sorted_insert_average, color=ll_col, linewidth=1, \n",
    "            linestyle='--', alpha=0.5)\n",
    "\n",
    "# Хеш таблица\n",
    "ax2.scatter(iterations, ht_sorted_insert, label='хеш таблица', color=ht_col)\n",
    "ax2.axhline(y=ht_sorted_insert_average, color=ht_col, linewidth=1, \n",
    "            linestyle='--', alpha=0.5)\n",
    "\n",
    "# Дерево\n",
    "ax2.scatter(iterations, bst_sorted_insert, label='дерево', color=bst_col)\n",
    "ax2.axhline(y=bst_sorted_insert_average, color=bst_col, linewidth=1, \n",
    "            linestyle='--', alpha=0.5)\n",
    "\n",
    "ax2.legend(loc='best')\n",
    "ax2.grid(True, alpha=0.3)\n",
    "\n",
    "# Общая настройка\n",
    "plt.suptitle(f'Сравнение производительности вставки в структуры данных (N = {countUsers})', \n",
    "             fontsize=14)\n",
    "plt.tight_layout()\n",
    "plt.savefig('../img/insert.pdf',\n",
    "            format='pdf',\n",
    "            dpi=300,\n",
    "            bbox_inches='tight',  \n",
    "            pad_inches=0.1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "7de42c9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 88396 characters]",
      "text/plain": [
       "<Figure size 1400x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Создание двух графиков рядом\n",
    "fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))\n",
    "\n",
    "# ============= Левый график: случайные данные =============\n",
    "ax1.set_title(\"Поиск в случайных данных\")\n",
    "ax1.set_ylabel('Время, с')\n",
    "ax1.set_xlabel('Повторения')\n",
    "ax1.set_xticks(iterations)\n",
    "# ax1.set_xticklabels(range(1, 6))\n",
    "\n",
    "ax1.scatter(iterations, ll_random_search, label='связный список', color=ll_col)\n",
    "ax1.axhline(y=ll_random_search_average, color=ll_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax1.scatter(iterations, ht_random_search, label='хеш таблица', color=ht_col)\n",
    "ax1.axhline(y=ht_random_search_average, color=ht_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax1.scatter(iterations, bst_random_search, label='дерево', color=bst_col)\n",
    "ax1.axhline(y=bst_random_search_average, color=bst_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax1.legend()\n",
    "ax1.grid(True, alpha=0.3)\n",
    "\n",
    "# ============= Правый график: отсортированные данные =============\n",
    "ax2.set_title(\"Поиск в отсортированных данных\")\n",
    "ax2.set_ylabel('Время, с')\n",
    "ax2.set_xlabel('Повторения')\n",
    "ax2.set_xticks(iterations)\n",
    "# ax2.set_xticklabels(range(1, 6))\n",
    "\n",
    "ax2.scatter(iterations, ll_sorted_search, label='связный список', color=ll_col)\n",
    "ax2.axhline(y=ll_sorted_search_average, color=ll_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax2.scatter(iterations, ht_sorted_search, label='хеш таблица', color=ht_col)\n",
    "ax2.axhline(y=ht_sorted_search_average, color=ht_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax2.scatter(iterations, bst_sorted_search, label='дерево', color=bst_col)\n",
    "ax2.axhline(y=bst_sorted_search_average, color=bst_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax2.legend()\n",
    "ax2.grid(True, alpha=0.3)\n",
    "\n",
    "# Общий заголовок\n",
    "plt.suptitle(f'Сравнение времени поиска в структурах данных (N = {countRandomSearch} + {countNotExitstSearch})', fontsize=14)\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.savefig('../img/search.pdf', \n",
    "            format='pdf',\n",
    "            dpi=300,\n",
    "            bbox_inches='tight',  # обрезает лишние поля\n",
    "            pad_inches=0.1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "0fd42f30",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 94880 characters]",
      "text/plain": [
       "<Figure size 1400x600 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Создание двух графиков рядом\n",
    "fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))\n",
    "\n",
    "# ============= Левый график: случайные данные =============\n",
    "ax1.set_title(\"Удаление в случайных данных\")\n",
    "ax1.set_ylabel('Время, с')\n",
    "ax1.set_xlabel('Повторения')\n",
    "ax1.set_xticks(iterations)\n",
    "# ax1.set_xticklabels(range(1, 6))\n",
    "\n",
    "ax1.scatter(iterations, ll_random_delete, label='связный список', color=ll_col)\n",
    "ax1.axhline(y=ll_random_delete_average, color=ll_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax1.scatter(iterations, ht_random_delete, label='хеш таблица', color=ht_col)\n",
    "ax1.axhline(y=ht_random_delete_average, color=ht_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax1.scatter(iterations, bst_random_delete, label='дерево', color=bst_col)\n",
    "ax1.axhline(y=bst_random_delete_average, color=bst_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax1.legend()\n",
    "ax1.grid(True, alpha=0.3)\n",
    "\n",
    "# ============= Правый график: отсортированные данные =============\n",
    "ax2.set_title(\"Удаление в отсортированных данных\")\n",
    "ax2.set_ylabel('Время, с')\n",
    "ax2.set_xlabel('Повторения')\n",
    "ax2.set_xticks(iterations)\n",
    "# ax2.set_xticklabels(range(1, 6))\n",
    "\n",
    "ax2.scatter(iterations, ll_sorted_delete, label='связный список', color=ll_col)\n",
    "ax2.axhline(y=ll_sorted_delete_average, color=ll_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax2.scatter(iterations, ht_sorted_delete, label='хеш таблица', color=ht_col)\n",
    "ax2.axhline(y=ht_sorted_delete_average, color=ht_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax2.scatter(iterations, bst_sorted_delete, label='дерево', color=bst_col)\n",
    "ax2.axhline(y=bst_sorted_delete_average, color=bst_col, linewidth=1, linestyle='--', alpha=0.7)\n",
    "\n",
    "ax2.legend()\n",
    "ax2.grid(True, alpha=0.3)\n",
    "\n",
    "# Общий заголовок\n",
    "plt.suptitle(f'Сравнение времени удаления в структурах данных (N = {countDeletes})', fontsize=14)\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.savefig('../img/delete.pdf', \n",
    "            format='pdf',\n",
    "            dpi=300,\n",
    "            bbox_inches='tight', \n",
    "            pad_inches=0.1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9eca6493",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.13.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
