{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1446abf1-3a2e-4eaf-a89a-5bbe335a5a19",
   "metadata": {},
   "outputs": [],
   "source": [
    "Add Vertices and Edges - add_vertex(v) - add_edge(u, v, weight=None)\n",
    "Query - has_edge(u, v) - has_vertex(v)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9283b81a-b299-48bd-81d5-f970a765e447",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dsa.graph import Graph\n",
    "\n",
    "g = Graph.create_adjacency_matrix(directed=True, weighted=True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5a500071-f743-487c-9d53-6ffe05d853bc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   |  A   B   C \n",
      "----------------\n",
      " A |            \n",
      " B |            \n",
      " C |            \n"
     ]
    }
   ],
   "source": [
    "g.add_vertex(\"A\")\n",
    "g.add_vertex(\"B\")\n",
    "g.add_vertex(\"C\")\n",
    "\n",
    "g.print_graph()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "36ccfd89-ce33-4e43-beb7-f6b99d4fd174",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   |  A   B   C \n",
      "----------------\n",
      " A |      1   2 \n",
      " B |          3 \n",
      " C |            \n"
     ]
    }
   ],
   "source": [
    "g.add_edge(\"A\", \"B\", 1)\n",
    "g.add_edge(\"A\", \"C\", 2)\n",
    "g.add_edge(\"B\", \"C\", 3)\n",
    "\n",
    "g.print_graph()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04baad6a-db53-4720-b580-7eaac5746846",
   "metadata": {},
   "source": [
    "Query Methods"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "41aa710b-e3a0-49f8-aa1d-0ccbafd68638",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['A', 'B', 'C']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g.vertices()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "ba319158-ee1c-4d43-8ecf-d5f54c863bbe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('A', 'B', 1), ('A', 'C', 2), ('B', 'C', 3)]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g.edges()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a46a7889-28d4-46be-9a2b-c37181b800b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "g.has_vertex(\"A\") # True\n",
    "g.has_vertex(\"B\") # True\n",
    "g.has_vertex(\"D\") # False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3982ae09-6ab3-4eb0-a956-2312470e5f6f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g.has_edge(\"A\", \"B\") # True\n",
    "g.has_edge(\"A\", \"C\") # True\n",
    "g.has_edge(\"C\", \"B\") # False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "62383019-5242-48fa-bed5-24a9fa3b9c2a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['B', 'C']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g.adjacents(\"A\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d23046be-66fe-4e49-9ead-a4adcfb5b355",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('B', 1), ('C', 2)]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g.adjacent_items(\"A\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "6fdec726-7b76-483a-a624-567aa9234263",
   "metadata": {},
   "outputs": [],
   "source": [
    "g = Graph.create_adjacency_list(directed=True, weighted=True)"
   ]
  }
 ],
 "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.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
