{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "c533959c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import LinkedList as ll\n",
    "import HashTable as ht\n",
    "import BinaryTree as bt\n",
    "import time \n",
    "import random as rand\n",
    "import csv\n",
    "import numpy as np\n",
    "import sys"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15cd6183",
   "metadata": {},
   "source": [
    "## Данные для обработки"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "88611f78",
   "metadata": {},
   "outputs": [],
   "source": [
    "N = 10000\n",
    "sys.setrecursionlimit(10000) \n",
    "records_sorted = [(f\"User_{i:05d}\", f\"+7999{i:07d}\") for i in range(N)] \n",
    "records_shuffled = records_sorted.copy()\n",
    "rand.shuffle(records_shuffled)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9fd1b8cd",
   "metadata": {},
   "source": [
    "## Исследование для LinkedList"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "083d49d0",
   "metadata": {},
   "source": [
    "### Добавление всех элементов произвольного кортежа\n",
    "- **data_ll_sh** -  Структура произвольных данных (только последний замер)\n",
    "- **time_ll_insert_sh** - Замер времени работы 10000 элементов (5 замеров) \n",
    "- **heads_ll_sh** - Массив голов для массив для произвольного массива"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "11634fa4",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_ll_insert_sh = [] \n",
    "heads_ll_sh = []\n",
    "for n in range(5):\n",
    "    head = None\n",
    "    data_ll_sh = []\n",
    "    start = time.perf_counter()\n",
    "    for i in range(N):\n",
    "        head = ll.ll_insert(head, records_shuffled[i][0], records_shuffled[i][1])\n",
    "        data_ll_sh.append(head)\n",
    "    end = time.perf_counter()\n",
    "    heads_ll_sh.append(head)\n",
    "    time_ll_insert_sh.append(end - start)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a5f161e",
   "metadata": {},
   "source": [
    "### Добавление всех элементов сортированного кортежа\n",
    "- **data_ll_so** - Структура отсортированных данных (только последний замер)\n",
    "- **time_ll_insert_so** - Замер времени работы 10000 элементов (5 замеров) \n",
    "- **heads_ll_so** - Массив голов для массив для сортированного массива"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "9eab4641",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_ll_insert_so = [] \n",
    "heads_ll_so = []\n",
    "for n in range(5):\n",
    "    head = None\n",
    "    data_ll_so = []\n",
    "    start = time.perf_counter()\n",
    "    for i in range(N):\n",
    "        head = ll.ll_insert(head, records_sorted[i][0], records_sorted[i][1])\n",
    "        data_ll_so.append(head)\n",
    "    end = time.perf_counter()\n",
    "    heads_ll_so.append(head)\n",
    "    time_ll_insert_so.append(end - start)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5862d31b",
   "metadata": {},
   "source": [
    "### Поиск элементов в произвольном массиве\n",
    "- **time_ll_find_sh** - Време поиска в произвольном массиве (для 5 замеров)\n",
    "- **find_ll_sh** - массив найденных данных в произвольном массиве (только последний замер)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "aac6cd23",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_ll_find_sh = []\n",
    "for n in range(5):\n",
    "    find_ll_sh = []\n",
    "    start = time.perf_counter()\n",
    "    for m in range(100): # замер для 100 случайных узлов \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_find = records_shuffled[i][0]\n",
    "        find_ll_sh.append(ll.ll_find(data_ll_sh[0], str_find))\n",
    "    for m in range(10): # недоступные данные\n",
    "        str_find = f\"Node_{m}\"\n",
    "        find_ll_sh.append(ll.ll_find(data_ll_sh[0], str_find))\n",
    "    end = time.perf_counter()\n",
    "    time_ll_find_sh.append(end - start)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "651aac23",
   "metadata": {},
   "source": [
    "### Поиск элементов в отсортированном массиве\n",
    "- **time_ll_find_so** - Време поиска в отсортированном массиве (для 5 замеров)\n",
    "- **find_ll_so** - Массив найденных данных в отсортированном массиве (только последний замер)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "5e5ae537",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_ll_find_so = []\n",
    "for n in range(5):\n",
    "    find_ll_so = []\n",
    "    start = time.perf_counter()\n",
    "    for m in range(100): # замер для 100 случайных узлов \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_find = records_sorted[i][0]\n",
    "        find_ll_so.append(ll.ll_find(data_ll_sh[0], str_find))\n",
    "    for m in range(10): # недоступные данные \n",
    "        str_find = f\"Node_{m}\"\n",
    "        find_ll_so.append(ll.ll_find(data_ll_sh[0], str_find))\n",
    "    end = time.perf_counter()\n",
    "    time_ll_find_so.append(end - start)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1f70be9",
   "metadata": {},
   "source": [
    "### Удаление элементов в произвольном массиве\n",
    "- **time_ll_delete_sh** - Време поиска в произвольном массиве (для 5 замеров)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "6cdf8a70",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0.04597238700080197,\n",
       " 0.0345118730001559,\n",
       " 0.04677163999804179,\n",
       " 0.0356504750016029,\n",
       " 0.033157756999571575]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time_ll_delete_sh = []\n",
    "for n in range(5):\n",
    "    current_head = heads_ll_sh[n]\n",
    "\n",
    "    start = time.perf_counter()\n",
    "    for m in range(50):  \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_delete = records_shuffled[i][0]\n",
    "        current_head = ll.ll_delete(current_head, str_delete)\n",
    "    end = time.perf_counter()\n",
    "\n",
    "    time_ll_delete_sh.append(end - start)\n",
    "time_ll_delete_sh"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d6156e9",
   "metadata": {},
   "source": [
    "### Удаление элементов в сортированном массиве\n",
    "- **time_ll_delete_so** - Време поиска в произвольном массиве (для 5 замеров)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "575e375c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0.03482511599941063,\n",
       " 0.02823204100059229,\n",
       " 0.029369250001764158,\n",
       " 0.01980331899903831,\n",
       " 0.030789607000770047]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time_ll_delete_so = []\n",
    "for n in range(5):\n",
    "    current_head = heads_ll_so[n]\n",
    "\n",
    "    start = time.perf_counter()\n",
    "    for m in range(50):  \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_delete = records_sorted[i][0]\n",
    "        current_head = ll.ll_delete(current_head, str_delete)\n",
    "    end = time.perf_counter()\n",
    "\n",
    "    time_ll_delete_so.append(end - start)\n",
    "time_ll_delete_so"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a95a40b",
   "metadata": {},
   "source": [
    "## Исследование BinaryTree"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54c92d21",
   "metadata": {},
   "source": [
    "### Добавление всех элементов произвольного кортежа\n",
    "- **data_bt_sh** -  Структура произвольных данных (только последний замер)\n",
    "- **time_bt_insert_sh** - Замер времени работы 10000 элементов (5 замеров) \n",
    "- **heads_bt_sh** - Массив голов для массив для произвольного массива"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "939aa900",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_bt_insert_sh = [] \n",
    "heads_bt_sh = []\n",
    "for n in range(5):\n",
    "    head = None\n",
    "    data_bt_sh = []\n",
    "    start = time.perf_counter()\n",
    "    for i in range(N):\n",
    "        head = bt.bst_insert(head, records_shuffled[i][0], records_shuffled[i][1])\n",
    "        data_bt_sh.append(head)\n",
    "    end = time.perf_counter()\n",
    "    heads_bt_sh.append(head)\n",
    "    time_bt_insert_sh.append(end - start)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e91b5893",
   "metadata": {},
   "source": [
    "### Добавление всех элементов сортированного кортежа\n",
    "- **data_bt_so** -  Структура сортированных данных (только последний замер)\n",
    "- **time_bt_insert_so** - Замер времени работы 10000 элементов (5 замеров) \n",
    "- **heads_bt_so** - Массив голов для массив для сортированного массива"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "d17b8108",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_bt_insert_so = [] \n",
    "heads_bt_so = []\n",
    "for n in range(5):\n",
    "    head = None\n",
    "    data_bt_so = []\n",
    "    start = time.perf_counter()\n",
    "    #head = bt.bst_insert(head, records_sorted[i][0],records_sorted[i][1])\n",
    "    head = bt.bst_insert_sort(records_sorted, 0, len(records_sorted) - 1)\n",
    "    data_bt_so.append(head)\n",
    "    end = time.perf_counter()\n",
    "    heads_bt_so.append(head)\n",
    "    time_bt_insert_so.append(end - start)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e8a3f9e",
   "metadata": {},
   "source": [
    "### Поиск элементов в произвольном массиве\n",
    "- **time_bt_find_sh** - Време поиска в произвольном массиве (для 5 замеров)\n",
    "- **find_bt_sh** - массив найденных данных в произвольном массиве (только последний замер)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "4352b11d",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_bt_find_sh = []\n",
    "for n in range(5):\n",
    "    find_bt_sh = []\n",
    "    start = time.perf_counter()\n",
    "    for m in range(100): # замер для 100 случайных узлов \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_find = records_shuffled[i][0]\n",
    "        find_bt_sh.append(bt.bst_find(data_bt_sh[0], str_find))\n",
    "    for m in range(10): # недоступные данные\n",
    "        str_find = f\"Node_{m}\"\n",
    "        find_bt_sh.append(bt.bst_find(data_bt_sh[0], str_find))\n",
    "    end = time.perf_counter()\n",
    "    time_bt_find_sh.append(end - start)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8db5208b",
   "metadata": {},
   "source": [
    "### Поиск элементов в отсортированном массиве\n",
    "- **time_bt_find_so** - Време поиска в сортированном массиве (для 5 замеров)\n",
    "- **find_bt_so** - массив найденных данных в сортированном массиве (только последний замер)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "7941e689",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_bt_find_so = []\n",
    "for n in range(5):\n",
    "    find_bt_so = []\n",
    "    start = time.perf_counter()\n",
    "    for m in range(100): # замер для 100 случайных узлов \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_find = records_sorted[i][0]\n",
    "        find_bt_so.append(bt.bst_find(data_bt_so[0], str_find))\n",
    "    for m in range(10): # недоступные данные\n",
    "        str_find = f\"Node_{m}\"\n",
    "        find_bt_so.append(bt.bst_find(data_bt_so[0], str_find))\n",
    "    end = time.perf_counter()\n",
    "    time_bt_find_so.append(end - start)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ffbe3dfe",
   "metadata": {},
   "source": [
    "### Удаление элементов в произвольном массиве\n",
    "- **time_bt_delete_sh** - Време поиска в произвольном массиве (для 5 замеров)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "4043a9dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_bt_delete_sh = []\n",
    "for n in range(5):\n",
    "    current_head = heads_bt_sh[n]\n",
    "\n",
    "    start = time.perf_counter()\n",
    "    for m in range(50):  \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_delete = records_shuffled[i][0]\n",
    "        current_head = bt.bst_delete(current_head, str_delete)\n",
    "    end = time.perf_counter()\n",
    "\n",
    "    time_bt_delete_sh.append(end - start)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7db94391",
   "metadata": {},
   "source": [
    "### Удаление элементов в сортированном массиве\n",
    "- **time_bt_delete_so** - Време поиска в произвольном массиве (для 5 замеров)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "7ab6136c",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_bt_delete_so = []\n",
    "for n in range(5):\n",
    "    current_head = heads_bt_so[n]\n",
    "\n",
    "    start = time.perf_counter()\n",
    "    for m in range(50):  \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_delete = records_sorted[i][0]\n",
    "        current_head = bt.bst_delete(current_head, str_delete)\n",
    "    end = time.perf_counter()\n",
    "\n",
    "    time_bt_delete_so.append(end - start)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0bf5b406",
   "metadata": {},
   "source": [
    "## Исследование HashTable"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75586bbc",
   "metadata": {},
   "source": [
    "### Добавление всех элементов произвольного кортежа\n",
    "- **data_ht_sh** -  Структура произвольных данных (только последний замер)\n",
    "- **time_ht_insert_sh** - Замер времени работы 10000 элементов (5 замеров) \n",
    "- **heads_ht_sh** - Массив голов для массив для произвольного массива"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "cb1788d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_ht_insert_sh = [] \n",
    "for n in range(5):\n",
    "    buckets = ht.create_ht(size = N * 4)\n",
    "    data_ht_sh = []\n",
    "    start = time.perf_counter()\n",
    "    for i in range(N):\n",
    "        buckets = ht.ht_insert(buckets, records_shuffled[i][0], records_shuffled[i][1])\n",
    "        data_ht_sh.append(buckets)\n",
    "    end = time.perf_counter()\n",
    "    time_ht_insert_sh.append(end - start)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6bb2aa16",
   "metadata": {},
   "source": [
    "### Добавление всех элементов сортированного кортежа\n",
    "- **data_ht_so** -  Структура сортированных данных (только последний замер)\n",
    "- **time_ht_insert_so** - Замер времени работы 10000 элементов (5 замеров) \n",
    "- **heads_ht_so** - Массив голов для массив для сортированного массива"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "4cb524e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_ht_insert_so = [] \n",
    "for n in range(5):\n",
    "    buckets = ht.create_ht(size = N * 4)\n",
    "    data_ht_so = []\n",
    "    start = time.perf_counter()\n",
    "    for i in range(N):\n",
    "        buckets = ht.ht_insert(buckets, records_sorted[i][0], records_sorted[i][1])\n",
    "        data_ht_so.append(buckets)\n",
    "    end = time.perf_counter()\n",
    "    time_ht_insert_so.append(end - start)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d79016f",
   "metadata": {},
   "source": [
    "### Поиск элементов в произвольном массиве\n",
    "- **time_ht_find_sh** - Време поиска в произвольном массиве (для 5 замеров)\n",
    "- **find_ht_sh** - массив найденных данных в произвольном массиве (только последний замер)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "45cec102",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_ht_find_sh = []\n",
    "for n in range(5):\n",
    "    find_ht_sh = []\n",
    "    start = time.perf_counter()\n",
    "    for m in range(100): # замер для 100 случайных узлов \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_find = records_shuffled[i][0]\n",
    "        find_ht_sh.append(ht.ht_find(data_ht_sh[0], str_find))\n",
    "    for m in range(10): # недоступные данные\n",
    "        str_find = f\"Node_{m}\"\n",
    "        find_ht_sh.append(ht.ht_find(data_ht_sh[0], str_find))\n",
    "    end = time.perf_counter()\n",
    "    time_ht_find_sh.append(end - start)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f11dbad",
   "metadata": {},
   "source": [
    "### Поиск элементов в отсортированном массиве\n",
    "- **time_ht_find_so** - Време поиска в сортированном массиве (для 5 замеров)\n",
    "- **find_ht_so** - массив найденных данных в сортированном массиве (только последний замер)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "19e7a19a",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_ht_find_so = []\n",
    "for n in range(5):\n",
    "    find_ht_so = []\n",
    "    start = time.perf_counter()\n",
    "    for m in range(100): # замер для 100 случайных узлов \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_find = records_shuffled[i][0]\n",
    "        find_ht_so.append(ht.ht_find(data_ht_so[0], str_find))\n",
    "    for m in range(10): # недоступные данные\n",
    "        str_find = f\"Node_{m}\"\n",
    "        find_ht_so.append(ht.ht_find(data_ht_so[0], str_find))\n",
    "    end = time.perf_counter()\n",
    "    time_ht_find_so.append(end - start)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e39fa07c",
   "metadata": {},
   "source": [
    "### Удаление элементов в произвольном массиве\n",
    "- **time_ht_delete_sh** - Време поиска в произвольном массиве (для 5 замеров)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "90a9613d",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_ht_delete_sh = []\n",
    "for n in range(5):\n",
    "    current_head = data_ht_sh[0]\n",
    "\n",
    "    start = time.perf_counter()\n",
    "    for m in range(50):  \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_delete = records_shuffled[i][0]\n",
    "        current_head = ht.ht_delete(current_head, str_delete)\n",
    "    end = time.perf_counter()\n",
    "    time_ht_delete_sh.append(end - start)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb9fcf01",
   "metadata": {},
   "source": [
    "### Удаление элементов в сортированном массиве\n",
    "- **time_ht_delete_so** - Време поиска в произвольном массиве (для 5 замеров)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "dfe01fe5",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_ht_delete_so = []\n",
    "for n in range(5):\n",
    "    current_head = data_ht_so[0]\n",
    "\n",
    "    start = time.perf_counter()\n",
    "    for m in range(50):  \n",
    "        i = rand.randint(0, N-1)\n",
    "        str_delete = records_shuffled[i][0]\n",
    "        current_head = ht.ht_delete(current_head, str_delete)\n",
    "    end = time.perf_counter()\n",
    "    time_ht_delete_so.append(end - start)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0ce9bbd",
   "metadata": {},
   "source": [
    "## Создание CSV файла\n",
    "Запишем все рание полученные данные в CSV файл"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "ce249772",
   "metadata": {},
   "outputs": [],
   "source": [
    "results = [\n",
    "    [\"Структура\", \"Режим\", \"Операция\", \"Время (сек)\"],\n",
    "    [\"LinkedList\", \"случайный\", \"вставка\", sum(time_ll_insert_sh)/len(time_ll_insert_sh)],\n",
    "    [\"LinkedList\", \"сортированный\", \"вставка\", sum(time_ll_insert_so)/len(time_ll_insert_so)],\n",
    "    [\"LinkedList\", \"случайный\", \"поиск\", sum(time_ll_find_sh)/len(time_ll_find_sh)],\n",
    "    [\"LinkedList\", \"сортированный\", \"поиск\", sum(time_ll_find_so)/len(time_ll_find_so)],\n",
    "    [\"LinkedList\", \"случайный\", \"удаление\", sum(time_ll_delete_sh)/len(time_ll_delete_sh)],\n",
    "    [\"LinkedList\", \"сортированный\", \"удаление\", sum(time_ll_delete_so)/len(time_ll_delete_so)],\n",
    "    [\"HashTable\", \"случайный\", \"вставка\", sum(time_ht_insert_sh)/len(time_ht_insert_sh)],\n",
    "    [\"HashTable\", \"сортированный\", \"вставка\", sum(time_ht_insert_so)/len(time_ht_insert_so)],\n",
    "    [\"HashTable\", \"случайный\", \"поиск\", sum(time_ht_find_sh)/len(time_ht_find_sh)],\n",
    "    [\"HashTable\", \"сортированный\", \"поиск\", sum(time_ht_find_so)/len(time_ht_find_so)],\n",
    "    [\"HashTable\", \"случайный\", \"удаление\", sum(time_ht_delete_sh)/len(time_ht_delete_sh)],\n",
    "    [\"HashTable\", \"сортированный\", \"удаление\", sum(time_ht_delete_so)/len(time_ht_delete_so)],\n",
    "    [\"BinaryTree\", \"случайный\", \"вставка\", sum(time_bt_insert_sh)/len(time_bt_insert_sh)],\n",
    "    [\"BinaryTree\", \"сортированный\", \"вставка\", sum(time_bt_insert_so)/len(time_bt_insert_so)],\n",
    "    [\"BinaryTree\", \"случайный\", \"поиск\", sum(time_bt_find_sh)/len(time_bt_find_sh)],\n",
    "    [\"BinaryTree\", \"сортированный\", \"поиск\", sum(time_bt_find_so)/len(time_bt_find_so)],\n",
    "    [\"BinaryTree\", \"случайный\", \"удаление\", sum(time_bt_delete_sh)/len(time_bt_delete_sh)],\n",
    "    [\"BinaryTree\", \"сортированный\", \"удаление\", sum(time_bt_delete_so)/len(time_bt_delete_so)],\n",
    "]\n",
    "\n",
    "with open(\"results.csv\", \"w\", newline=\"\") as f:\n",
    "    writer = csv.writer(f)\n",
    "    writer.writerows(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69023ea2",
   "metadata": {},
   "source": [
    "## Построение графиков и сравнение данных между собой\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "d06c4bb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 185368 characters]",
      "text/plain": [
       "<Figure size 2000x1500 with 9 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "t_ll = [sum(time_ll_insert_sh)/len(time_ll_insert_sh), sum(time_ll_insert_so)/len(time_ll_insert_so), sum(time_ll_find_sh)/len(time_ll_find_sh), sum(time_ll_find_so)/len(time_ll_find_so), sum(time_ll_delete_sh)/len(time_ll_delete_sh), sum(time_ll_delete_so)/len(time_ll_delete_so)]\n",
    "t_ht = [sum(time_ht_insert_sh)/len(time_ht_insert_sh), sum(time_ht_insert_so)/len(time_ht_insert_so), sum(time_ht_find_sh)/len(time_ht_find_sh), sum(time_ht_find_so)/len(time_ht_find_so), sum(time_ht_delete_sh)/len(time_ht_delete_sh), sum(time_ht_delete_so)/len(time_ht_delete_so)]\n",
    "t_bt = [sum(time_bt_insert_sh)/len(time_bt_insert_sh), sum(time_bt_insert_so)/len(time_bt_insert_so), sum(time_bt_find_sh)/len(time_bt_find_sh), sum(time_bt_find_so)/len(time_bt_find_so), sum(time_bt_delete_sh)/len(time_bt_delete_sh), sum(time_bt_delete_so)/len(time_bt_delete_so)]\n",
    "categoris = [\"рандомное добавление\", \"отсортированное добавление\", \"рандомный поиск\", \"отсортированный поиск\", \"рандомное удаление\", \"отсортированное удаление\"]\n",
    "\n",
    "plt.figure(\"графики\", figsize = (20,15))\n",
    "\n",
    "plt.subplot(3,3,1)\n",
    "plt.bar(categoris[0], t_ll[0], color = \"orange\")\n",
    "plt.bar(categoris[1], t_ll[1], color = \"green\")\n",
    "\n",
    "plt.title(f\"Время добавление для LinkedList\")\n",
    "\n",
    "plt.ylabel(\"время работы(секунды)\")\n",
    "\n",
    "plt.subplot(3,3,2)\n",
    "plt.bar(categoris[2], t_ll[2], color = \"orange\")\n",
    "plt.bar(categoris[3], t_ll[3], color = \"green\")\n",
    "\n",
    "plt.title(f\"Время поиска элементов в LinkedList\")\n",
    "\n",
    "plt.ylabel(\"время работы(секунды)\")\n",
    "\n",
    "\n",
    "plt.subplot(3,3,3)\n",
    "plt.bar(categoris[4], t_ll[4], color = \"orange\")\n",
    "plt.bar(categoris[5], t_ll[5], color = \"green\")\n",
    "\n",
    "plt.title(f\"Время удаления элементов в LinkedList\")\n",
    "\n",
    "plt.ylabel(\"время работы(секунды)\")\n",
    "\n",
    "plt.subplot(3,3,4)\n",
    "plt.bar(categoris[0], t_ht[0], color = \"orange\")\n",
    "plt.bar(categoris[1], t_ht[1], color = \"green\")\n",
    "\n",
    "plt.title(f\"Время добавление для HashTable\")\n",
    "\n",
    "plt.ylabel(\"время работы(секунды)\")\n",
    "\n",
    "plt.subplot(3,3,5)\n",
    "plt.bar(categoris[2], t_ht[2], color = \"orange\")\n",
    "plt.bar(categoris[3], t_ht[3], color = \"green\")\n",
    "\n",
    "plt.title(f\"Время поиска элементов в HashTable\")\n",
    "\n",
    "plt.ylabel(\"время работы(секунды)\")\n",
    "\n",
    "\n",
    "plt.subplot(3,3,6)\n",
    "plt.bar(categoris[4], t_bt[4], color = \"orange\")\n",
    "plt.bar(categoris[5], t_bt[5], color = \"green\")\n",
    "\n",
    "plt.title(f\"Время удаления элементов в HashTable\")\n",
    "\n",
    "plt.ylabel(\"время работы(секунды)\")\n",
    "\n",
    "plt.subplot(3,3,7)\n",
    "plt.bar(categoris[0], t_bt[0], color = \"orange\")\n",
    "plt.bar(categoris[1], t_bt[1], color = \"green\")\n",
    "\n",
    "plt.title(f\"Время добавление для BinaryTree\")\n",
    "\n",
    "plt.ylabel(\"время работы(секунды)\")\n",
    "\n",
    "plt.subplot(3,3,8)\n",
    "plt.bar(categoris[2], t_bt[2], color = \"orange\")\n",
    "plt.bar(categoris[3], t_bt[3], color = \"green\")\n",
    "\n",
    "plt.title(f\"Время поиска элементов в BinaryTree\")\n",
    "\n",
    "plt.ylabel(\"время работы(секунды)\")\n",
    "\n",
    "\n",
    "plt.subplot(3,3,9)\n",
    "plt.bar(categoris[4], t_bt[4], color = \"orange\")\n",
    "plt.bar(categoris[5], t_bt[5], color = \"green\")\n",
    "\n",
    "plt.title(f\"Время удаления элементов в BinaryTree\")\n",
    "\n",
    "plt.ylabel(\"время работы(секунды)\")\n",
    "\n",
    "plt.savefig('analysis.png')\n",
    "plt.tight_layout() \n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77155f07",
   "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.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
