Last active
November 9, 2019 23:35
-
-
Save daherk2/12b07cd2f8b6a8afc1f3d1d745c85ae4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "grafo = {\n", | |
| "\"1\" : ['2', '3', '4'],\n", | |
| "\"2\" : ['1','5'],\n", | |
| "\"3\" : ['1','6','7'],\n", | |
| "\"4\" : ['1', '8'],\n", | |
| "\"5\" : ['2','9'],\n", | |
| "\"6\" : ['3', '10'],\n", | |
| "\"7\" : ['3'],\n", | |
| "\"8\" : ['4'],\n", | |
| "\"9\" : ['5'],\n", | |
| "\"10\": ['6'], \n", | |
| "}" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<img src=\"Desktop/imagem.jpg\" style=\"height:280px\">\n" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.HTML object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "%%html\n", | |
| "<img src=/https://pt.wikipedia.org/wiki/Busca_em_largura#/media/Ficheiro:Breadth-First-Search-Algorithm.gif/" style=\"height:280px\">" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 32, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def Bproof(grafo, exp, visitado, queue, idx):\n", | |
| " if exp not in visitado:visitado.append(exp)\n", | |
| " queue[exp] = [i for i in grafo[exp] if i not in visitado]\n", | |
| " if len([ j for j in [ i for i in queue if len(queue[i]) != 0] if j in visitado]) == 0: \n", | |
| " print(visitado)\n", | |
| " else:\n", | |
| " if len(queue[exp]) == 0:\n", | |
| " idx = (idx)+1\n", | |
| " Bproof(grafo, visitado[len(visitado)-(idx)], visitado, queue, idx)\n", | |
| " else:\n", | |
| " Bproof(grafo, queue[exp][0], visitado, queue,1)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 33, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "['1', '2', '5', '9', '3', '6', '10', '7', '4', '8']\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "Bproof(grafo, \"1\", [], {}, 0)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "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.6.5" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment