Skip to content
4 changes: 2 additions & 2 deletions pretext/AlgorithmAnalysis/BigONotation.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
another.</p>
<figure align="" xml:id="fig-graphfigurecpp">
<caption xmlns:c="https://www.sphinx-doc.org/" xmlns:changeset="https://www.sphinx-doc.org/" xmlns:citation="https://www.sphinx-doc.org/" xmlns:cpp="https://www.sphinx-doc.org/" xmlns:index="https://www.sphinx-doc.org/" xmlns:js="https://www.sphinx-doc.org/" xmlns:math="https://www.sphinx-doc.org/" xmlns:py="https://www.sphinx-doc.org/" xmlns:rst="https://www.sphinx-doc.org/" xmlns:std="https://www.sphinx-doc.org/">Figure 1: Common Big-O Functions</caption>
<image source="AlgorithmAnalysis/Figures/newplot.png" width="50%"/>
<image source="AlgorithmAnalysis/Figures/newplot.png" width="50%" alt="Graph of common Big-O functions (constant, logarithmic, linear, n log n, quadratic, cubic, exponential) showing their comparative growth rates as n increases."/>
</figure>
<exercise label="parsonsBigO" indent="show" language="python">
<statement>
Expand Down Expand Up @@ -252,7 +252,7 @@ main()</pre>
ignored as <em>n</em> grows larger.</p>
<figure align="" xml:id="fig-graphfigure2cpp">
<caption xmlns:c="https://www.sphinx-doc.org/" xmlns:changeset="https://www.sphinx-doc.org/" xmlns:citation="https://www.sphinx-doc.org/" xmlns:cpp="https://www.sphinx-doc.org/" xmlns:index="https://www.sphinx-doc.org/" xmlns:js="https://www.sphinx-doc.org/" xmlns:math="https://www.sphinx-doc.org/" xmlns:py="https://www.sphinx-doc.org/" xmlns:rst="https://www.sphinx-doc.org/" xmlns:std="https://www.sphinx-doc.org/">Figure 2: Comparing <m>T(n)</m> with Big-O Functions</caption>
<image source="AlgorithmAnalysis/Figures/newplot2.png" width="50%"/>
<image source="AlgorithmAnalysis/Figures/newplot2.png" width="50%" alt="Graph comparing a specific T(n) function (3n^2+2n+4) with Big-O functions like O(n^2) and O(n^3), illustrating how T(n) follows the O(n^2) curve as n increases."/>
</figure>
<p><xref ref="fig-graphfigure2cpp"/> shows a few of the common Big-O functions as they
compare with the <m>T(n)</m> function discussed above. Note that
Expand Down
2 changes: 1 addition & 1 deletion pretext/AlgorithmAnalysis/WhatIsAlgorithmAnalysis.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ main()
following <m>8 \times 9</m>.rectangle.</p>
<figure align="" xml:id="fig-sumof-n-integers">
<caption xmlns:c="https://www.sphinx-doc.org/" xmlns:changeset="https://www.sphinx-doc.org/" xmlns:citation="https://www.sphinx-doc.org/" xmlns:cpp="https://www.sphinx-doc.org/" xmlns:index="https://www.sphinx-doc.org/" xmlns:js="https://www.sphinx-doc.org/" xmlns:math="https://www.sphinx-doc.org/" xmlns:py="https://www.sphinx-doc.org/" xmlns:rst="https://www.sphinx-doc.org/" xmlns:std="https://www.sphinx-doc.org/">Figure 1: Sum of <title_reference>n = 8</title_reference> integers</caption>
<image source="AlgorithmAnalysis/Figures/sumof-n-integers.png" width="50%"/>
<image source="AlgorithmAnalysis/Figures/sumof-n-integers.png" width="50%" alt="Diagram illustrating the sum of the first 8 integers as a blue area within an 8x9 rectangle. The blue area represents 1+2+3+4+5+6+7+8 squares."/>
</figure>
<p>To find the blue area, we can count the number of blue squares
<m>1+2+3+4+5+6+7+8</m>, which we just learned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</p>
<p>Reductionism is the view that the behavior of a system can be explained by understanding its components. For example, the periodic table of the elements is a triumph of reductionism, because it explains the chemical behavior of elements with a model of electrons in atoms. Holism is the view that some phenomena that appear at the system level do not exist at the level of components, and cannot be explained in component-level terms.</p>
<p>We get back to explanatory models in <xref ref="scale-free-networks_introduction"/>, instrumentalism in <xref ref="game-of-life_introduction"/>, and holism in <xref ref="self-organized-criticality_introduction"/></p>
<exercise>
<exercise xml:id="exercise-classical-models" label = "exercise-classical">
<statement>
<p>Q-1: Classical models are better to <BlankNode/> <var/> </p>
</statement>
Expand All @@ -39,7 +39,7 @@
</var>
</setup>
</exercise>
<exercise>
<exercise xml:id="exercise-complex-models" label = "exercise-classical-2">
<statement>
<p>Q-2: Complex Models are better to <BlankNode/> <var/> </p>
</statement>
Expand Down
6 changes: 5 additions & 1 deletion pretext/Graphs/Generating.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
<title>Generating Graphs</title>
<figure align="center" xml:id="g-fig-3">
<caption xmlns:c="https://www.sphinx-doc.org/" xmlns:changeset="https://www.sphinx-doc.org/" xmlns:citation="https://www.sphinx-doc.org/" xmlns:cpp="https://www.sphinx-doc.org/" xmlns:index="https://www.sphinx-doc.org/" xmlns:js="https://www.sphinx-doc.org/" xmlns:math="https://www.sphinx-doc.org/" xmlns:py="https://www.sphinx-doc.org/" xmlns:rst="https://www.sphinx-doc.org/" xmlns:std="https://www.sphinx-doc.org/"> A complete graph with 10 nodes.</caption>
<image source="Graphs/Figures/thinkcomplexity2003.png" width="50%" alt="&quot; A complete graph with 10 nodes.&quot;"/>
<image source="Graphs/Figures/thinkcomplexity2003.png" width="50%" >
<shortdescription>Complete graph with 10 nodes.</shortdescription>
<description>
<p>The image depicts a complete graph consisting of ten nodes. These nodes, labeled 0 through 9, are arranged in a circular pattern for visual clarity. Every node is connected to every other node by a straight edge, forming a dense network where all possible connections are present. This illustrates the fundamental property of a complete graph: full interconnectivity between all its vertices.</p>
</description> </image>
</figure>
<p>We'll start by generating a <term>complete graph</term>, which is a graph where every node is connected to every other.</p>
<p>Here's a generator function that takes a list of nodes and enumerates all distinct pairs. If you are not familiar with generator functions.</p>
Expand Down
7 changes: 6 additions & 1 deletion pretext/Graphs/GeneratingER.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
<title>Generating ER Graphs</title>
<figure align="center" xml:id="g-fig-7">
<caption xmlns:c="https://www.sphinx-doc.org/" xmlns:changeset="https://www.sphinx-doc.org/" xmlns:citation="https://www.sphinx-doc.org/" xmlns:cpp="https://www.sphinx-doc.org/" xmlns:index="https://www.sphinx-doc.org/" xmlns:js="https://www.sphinx-doc.org/" xmlns:math="https://www.sphinx-doc.org/" xmlns:py="https://www.sphinx-doc.org/" xmlns:rst="https://www.sphinx-doc.org/" xmlns:std="https://www.sphinx-doc.org/"> An ER graph with n=10 and p=0.3.</caption>
<image source="Graphs/Figures/thinkcomplexity2004.png" width="50%" alt="&quot; An ER graph with n=10 and p=0.3.&quot;"/>
<image source="Graphs/Figures/thinkcomplexity2004.png" width="50%" >
<shortdescription>Visual representation of an Erdős-Rényi random graph with 10 nodes and specific edge connections based on p=0.3.</shortdescription>
<description>
<p>The image displays an Erdős-Rényi (ER) random graph. It features 10 circular nodes, which are labeled with integers from 0 to 9. These nodes are arranged in a somewhat irregular, non-grid layout across the viewing area.</p>
<p>Edges, represented as lines, connect various pairs of these nodes. The graph is not complete, meaning not all possible pairs of nodes are connected. This visual sparsity is characteristic of an ER graph where edges form with a probability <m>p</m> (in this case, <m>p=0.3</m> for <m>n=10</m> nodes). For instance, the visual details show that node 3 is connected only to node 2, while other nodes, such as node 7, exhibit multiple connections to different nodes within the graph.</p>
</description> </image>
</figure>
<p>The ER graph <m>G(n, p)</m> contains <m>n</m> nodes, and each pair of nodes is connected by an edge with probability <m>p</m>. Generating an ER graph is similar to generating a complete graph.</p>
<p>The following generator function enumerates all possible edges and chooses which ones should be added to the graph:</p>
Expand Down
8 changes: 7 additions & 1 deletion pretext/Graphs/NetworkX.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
<title>NetworkX</title>
<figure align="center" xml:id="g-fig-2">
<caption xmlns:c="https://www.sphinx-doc.org/" xmlns:changeset="https://www.sphinx-doc.org/" xmlns:citation="https://www.sphinx-doc.org/" xmlns:cpp="https://www.sphinx-doc.org/" xmlns:index="https://www.sphinx-doc.org/" xmlns:js="https://www.sphinx-doc.org/" xmlns:math="https://www.sphinx-doc.org/" xmlns:py="https://www.sphinx-doc.org/" xmlns:rst="https://www.sphinx-doc.org/" xmlns:std="https://www.sphinx-doc.org/"> An undirected graph that represents driving time between cities.</caption>
<image source="Graphs/Figures/thinkcomplexity2002.png" width="50%" alt="&quot; An undirected graph that represents driving time between cities.&quot;"/>
<image source="Graphs/Figures/thinkcomplexity2002.png" width="50%">
<shortdescription>Undirected graph: driving times for Albany, Boston, NYC, Philly.</shortdescription>
<description>
<p>The image displays an undirected graph representing a road network with driving times. It features four square-shaped nodes, labeled with city names: Albany, Boston, NYC (New York City), and Philly (Philadelphia), positioned to roughly approximate their geographical locations.</p>
<p>Edges, as lines, connect these cities, indicating direct driving routes. Each edge is labeled with the driving time in hours. Specifically, the connections are: Albany to Boston (3 hours), Albany to NYC (4 hours), Boston to NYC (4 hours), and NYC to Philly (2 hours).</p>
</description>
</image>
</figure>
<p>To represent graphs, we'll use a package called NetworkX, which is the most commonly used network library in Python.</p>
<p>We can create a directed graph by importing NetworkX (usually imported as <c>nx</c>) and instantiating <c>nx.DiGraph</c>:</p>
Expand Down
14 changes: 12 additions & 2 deletions pretext/Graphs/ProbabilityOfConnectivity.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
<title>Probability of Connectivity</title>
<figure align="center" xml:id="id1">
<caption xmlns:c="https://www.sphinx-doc.org/" xmlns:changeset="https://www.sphinx-doc.org/" xmlns:citation="https://www.sphinx-doc.org/" xmlns:cpp="https://www.sphinx-doc.org/" xmlns:index="https://www.sphinx-doc.org/" xmlns:js="https://www.sphinx-doc.org/" xmlns:math="https://www.sphinx-doc.org/" xmlns:py="https://www.sphinx-doc.org/" xmlns:rst="https://www.sphinx-doc.org/" xmlns:std="https://www.sphinx-doc.org/"> Probability of connectivity with n=10 and a range of p. The vertical line shows the predicted critical value.</caption>
<image source="Graphs/Figures/thinkcomplexity2005.png" width="50%" alt="&quot; Probability of connectivity with n=10 and a range of p. The vertical line shows the predicted critical value&quot;"/>
<image source="Graphs/Figures/thinkcomplexity2005.png" width="50%" >
<shortdescription>Line graph: probability of connectivity (n=10) vs. probability of edge (p).</shortdescription>
<description>
<p>The graph plots the probability of graph connectivity against the probability of an edge (<m>p</m>) for a graph with <m>n=10</m> nodes. The x-axis, labeled 'Prob of edge (p)', is on a logarithmic scale ranging from <m>10^{-2.5}</m> to <m>10^0=1</m>. The y-axis, labeled 'Prob connected', ranges linearly from 0.0 to 1.0. A blue S-shaped curve illustrates the relationship, showing the probability of connectivity rising from near 0 to near 1. The steepest part of this ascent occurs around <m>p \approx 0.23</m>. A vertical gray line at this x-value indicates the predicted critical value for <m>p</m>.</p>
</description> </image>
</figure>
<figure align="center" xml:id="g-fig-6">
<caption xmlns:c="https://www.sphinx-doc.org/" xmlns:changeset="https://www.sphinx-doc.org/" xmlns:citation="https://www.sphinx-doc.org/" xmlns:cpp="https://www.sphinx-doc.org/" xmlns:index="https://www.sphinx-doc.org/" xmlns:js="https://www.sphinx-doc.org/" xmlns:math="https://www.sphinx-doc.org/" xmlns:py="https://www.sphinx-doc.org/" xmlns:rst="https://www.sphinx-doc.org/" xmlns:std="https://www.sphinx-doc.org/"> Probability of connectivity for several values of n and a range of p.</caption>
<image source="Graphs/Figures/thinkcomplexity2006.png" width="50%" alt="&quot; Probability of connectivity for several values of n and a range of p.&quot;"/>
<image source="Graphs/Figures/thinkcomplexity2006.png" width="50%">
<shortdescription>Connectivity probability vs. edge probability (p) for n=30, 100, 300.</shortdescription>
<description>
<p>This line graph shows how graph connectivity probability changes with varying numbers of nodes (<m>n</m>) and edge probability (<m>p</m>). The x-axis, 'Prob of edge (p)', is logarithmic (<m>10^{-2.5}</m> to <m>10^0</m>). The y-axis, 'Prob connected', ranges from 0.0 to 1.0.</p>
<p>Three S-shaped curves are shown: a dark blue curve for <m>n=30</m>, a medium blue curve for <m>n=100</m>, and a light blue curve for <m>n=300</m>. Each curve has a faint vertical line at its critical point for <m>p</m>.</p>
<p>As <m>n</m> increases, the S-curve (transition to connectivity) shifts left towards lower <m>p</m> values and becomes steeper, indicating a more abrupt transition.</p>
</description> </image>
</figure>
<p>For given values of <m>n</m> and <m>p</m>, we would like to know the probability that <m>G(n, p)</m> is connected. We can estimate it by generating a large number of random graphs and counting how many are connected. Here's how:</p>
<pre>def prob_connected(n, p, iters=100):
Expand Down
8 changes: 7 additions & 1 deletion pretext/Graphs/SelfCheck.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
<title>Self Check</title>
<figure align="center" xml:id="id1">
<caption xmlns:c="https://www.sphinx-doc.org/" xmlns:changeset="https://www.sphinx-doc.org/" xmlns:citation="https://www.sphinx-doc.org/" xmlns:cpp="https://www.sphinx-doc.org/" xmlns:index="https://www.sphinx-doc.org/" xmlns:js="https://www.sphinx-doc.org/" xmlns:math="https://www.sphinx-doc.org/" xmlns:py="https://www.sphinx-doc.org/" xmlns:rst="https://www.sphinx-doc.org/" xmlns:std="https://www.sphinx-doc.org/">A Graphical represention of a Friend Network</caption>
<image source="Graphs/Figures/SELF_CHECK_FIG.png" width="50%" alt="&quot;Graph of Friend Network&quot;"/>
<image source="Graphs/Figures/SELF_CHECK_FIG.png" width="50%" >
<shortdescription>Graph of Friend Network</shortdescription>
<description>
<p>An undirected graph depicts a social network with five nodes: Josh, Kate, Jerry, Mary, and Billy-Bob. Edges show connections between these individuals.</p>
<p>Josh is connected to Billy-Bob. Kate is connected to Jerry, Mary, and Billy-Bob. Jerry is connected to Kate and Billy-Bob; Mary is also connected to Kate and Billy-Bob. Billy-Bob connects to Josh, Kate, Jerry, and Mary, acting as a central connector.</p>
<p>The connections are mutual, indicating friendships or bidirectional relationships.</p>
</description> </image>
</figure>
<exercise label="SC_Q1">
<statement>
Expand Down
9 changes: 8 additions & 1 deletion pretext/Graphs/WhatIsAGraph.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
<title>What is a Graph?</title>
<figure align="center" xml:id="g-fig-1">
<caption xmlns:c="https://www.sphinx-doc.org/" xmlns:changeset="https://www.sphinx-doc.org/" xmlns:citation="https://www.sphinx-doc.org/" xmlns:cpp="https://www.sphinx-doc.org/" xmlns:index="https://www.sphinx-doc.org/" xmlns:js="https://www.sphinx-doc.org/" xmlns:math="https://www.sphinx-doc.org/" xmlns:py="https://www.sphinx-doc.org/" xmlns:rst="https://www.sphinx-doc.org/" xmlns:std="https://www.sphinx-doc.org/"> A directed graph that represents a social network.</caption>
<image source="Graphs/Figures/thinkcomplexity2001.png" width="50%" alt="&quot; A directed graph that represents a social network.&quot;"/>
<image source="Graphs/Figures/thinkcomplexity2001.png" width="50%">
<shortdescription>Directed three-node graph showing social network connections.</shortdescription>
<description>
<p>The image displays a simple directed graph with three nodes, visually representing network elements. Edges, as arrows, show the direction of relationships. The nodes can be identified as Alice, Bob, and Chuck based on the text's example.</p>
<p>A mutual, bidirectional connection exists between two nodes (Alice and Bob), shown by arrows pointing from each to the other. Both of these nodes also have outgoing arrows directed towards the third node (Chuck).</p>
<p>The third node (Chuck) only has incoming arrows from Alice and Bob and no outgoing arrows. This structure illustrates the example where Alice and Bob follow each other, both follow Chuck, and Chuck follows no one back.</p>
</description>
</image>
</figure>
<p>To most people a <q>graph</q> is a visual representation of data, like a bar chart or a plot of stock prices over time. That's not what this chapter is about.</p>
<p>In this chapter, a <term>graph</term> is a representation of a system that contains discrete, interconnected elements. The elements are represented by <term>nodes</term> &#x2014; also called <term>vertices</term> &#x2013; and the interconnections are represented by <term>edges</term>.</p>
Expand Down