<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name: <NAME>  \n",
    "Date: November 1st, 2016  \n",
    "Assignment: Homework 3  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1) Consider the weighted graph:\n",
    "\n",
    "a) Demonstrate Prim's algorithm starting from vertex A. Write the edges in the order they were added to the minimum spanning tree.\n",
    "\n",
    "1. $AE$\n",
    "2. $EB$\n",
    "3. $BC$\n",
    "4. $CD$\n",
    "5. $CG$\n",
    "6. $GF$\n",
    "7. $DH$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "b) Demonstrate Dijkstra's algorithm on the graph, using vertex $A$ as the source. Write the vertices in the order which they are marked and compute all distances at each step.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2) A Hamiltonian path in a graph $G=(V,E)$ is a simple path that includes every vertex in $V$. Design an algorithm to determine if a directed acyclic graph (DAG) has a Hamiltonian path. Your algorithm should run in $O(V+E)$. Provide a written description of your algorithm including why it works, pseudocode and an explanation of the running time."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "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.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
<commit_msg>Added question text for the full homework 3 assignment<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name: <NAME>  \n",
    "Date: November 1st, 2016  \n",
    "Assignment: Homework 3  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1) Consider the weighted graph:\n",
    "\n",
    "a) Demonstrate Prim's algorithm starting from vertex A. Write the edges in the order they were added to the minimum spanning tree.\n",
    "\n",
    "1. $AE$\n",
    "2. $EB$\n",
    "3. $BC$\n",
    "4. $CD$\n",
    "5. $CG$\n",
    "6. $GF$\n",
    "7. $DH$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "b) Demonstrate Dijkstra's algorithm on the graph, using vertex $A$ as the source. Write the vertices in the order which they are marked and compute all distances at each step.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2) A Hamiltonian path in a graph $G=(V,E)$ is a simple path that includes every vertex in $V$. Design an algorithm to determine if a directed acyclic graph (DAG) has a Hamiltonian path. Your algorithm should run in $O(V+E)$. Provide a written description of your algorithm including why it works, pseudocode and an explanation of the running time."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3) Below is a list of courses and prerequisites for a factious CS degree."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "a) Draw a directed acyclic graph (DAG) that represents the precedence among the courses."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "b) Give a topological sort of the graph."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "c) Find an order in which all the classes can be taken. You are allowed to take multiple courses at one time as long as there is no prerequisite conflict."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "d) Determine the length of the longest path in the DAG. How did you find it? What does this represent?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4)  Suppose you have an undirected graph G=(V,E) and you want to determine if you can assign two colors (blue and red) to the vertices such that adjacent vertices are different colors.   This is the graph Two-Color problem.  If the assignment of two colors is possible, then a 2-coloring is a function C: V -> {blue, red} such that C(u)  C(v) for every edge (u,v)  E.  Note: a graph can have more than one 2-coloring.  \n",
    "\n",
    "Give an O(V  + E) algorithm to determine the 2-coloring of a graph if one exists or terminate with the message that the graph is not Two-Colorable.  Assume that the input graph G=(V,E) is represented using adjacency lists."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "a) Give a verbal description of the algorithm and provide detailed pseudocode."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "b) Analyze the running time."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5) A region contains a number of towns connected by roads.  Each road is labeled by the average\n",
    "number of minutes required for a fire engine to travel to it.  Each intersection is labeled with a circle. Suppose that you work for a city that has decided to place a fire station at location G. (While this problem is small, you want to devise a method to solve much larger problems)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "a) What algorithm would you recommend be used to find the fastest route from the fire station to each of the intersections?  Demonstrate how it would work on the example above if the fire station is placed at G.  Show the resulting routes."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "b) Suppose one ”optimal” location (maybe instead of G) must be selected for the fire station such that it minimizes the distance to the farthest intersection.  Devise an algorithm to solve this problem given an arbitrary road map.  Analyze the time complexity of your algorithm when there are f possible locations for the fire station (which must be at one of the intersections) and r possible roads."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "c) In the above graph what is the “optimal” location to place the fire station?  Why?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**EXTRA CREDIT:** Now suppose you can build two fire stations.  Where would you place them to minimize the farthest distance from an intersection to one of the fire stations?  Devise an algorithm to solve this problem given an arbitrary road map.  Analyze the time complexity of your algorithm when there are f possible locations for the fire station (which must be at one of the intersections) and r possible roads."
   ]
  }
 ],
 "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.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}

{'fraction_non_alphanumeric': 0.1396542409508374, 'fraction_numerical': 0.007428417071853053, 'mean_word_length': 2.9897629310344827, 'pattern_counts': {'":': 102, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1986784', 'n_tokens_mistral': 2452, 'n_tokens_neox': 2356, 'n_words': 933}