<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?action=history&amp;feed=atom&amp;title=Runtime_evaluation</id>
	<title>Runtime evaluation - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?action=history&amp;feed=atom&amp;title=Runtime_evaluation"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Runtime_evaluation&amp;action=history"/>
	<updated>2026-04-13T02:04:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Runtime_evaluation&amp;diff=103&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Runtime_evaluation&amp;diff=103&amp;oldid=prev"/>
		<updated>2026-01-27T08:51:57Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 10:51, 27 January 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l84&quot;&gt;Line 84:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 84:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises to be handed in ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exercises to be handed in ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&quot;Calculate&quot; can mean many things here; Analyze, argue, explain, show, or even demonstrate. For some algorithms (not these) it even means &quot;do a lot of math&quot;. The calculation must be &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;convincing and &lt;/del&gt;explained. Just showing the result is insufficient.&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&quot;Calculate&quot; can mean many things here; Analyze, argue, explain, show, or even demonstrate. For some algorithms (not these) it even means &quot;do a lot of math&quot;. The calculation must be &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;convincingly &lt;/ins&gt;explained &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;based on reasoning&lt;/ins&gt;. Just showing the result is insufficient.&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Calculate Big O of exercise 2 in [[Python Recap and Objects]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Calculate Big O of exercise 2 in [[Python Recap and Objects]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Calculate Big O of exercise 1 in [[Regular Expressions]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Calculate Big O of exercise 1 in [[Regular Expressions]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Runtime_evaluation&amp;diff=102&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;__NOTOC__ {| width=500  style=&quot;font-size: 10px; float:right; margin-left: 10px; margin-top: -56px;&quot; |Previous: Intermediate unit test |Next: Changing existing code base |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/Python10-Runtime.pptx Runtime evaluation of algorithms] Old ppt, not so important&lt;br&gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=41edc89b-61a5-475d-84d0-af2701271b5d Run...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Runtime_evaluation&amp;diff=102&amp;oldid=prev"/>
		<updated>2026-01-27T08:50:06Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ {| width=500  style=&amp;quot;font-size: 10px; float:right; margin-left: 10px; margin-top: -56px;&amp;quot; |Previous: &lt;a href=&quot;/22118/index.php/Intermediate_unit_test&quot; title=&quot;Intermediate unit test&quot;&gt;Intermediate unit test&lt;/a&gt; |Next: &lt;a href=&quot;/22118/index.php?title=Changing_existing_code_base&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Changing existing code base (page does not exist)&quot;&gt;Changing existing code base&lt;/a&gt; |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/Python10-Runtime.pptx Runtime evaluation of algorithms] Old ppt, not so important&amp;lt;br&amp;gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=41edc89b-61a5-475d-84d0-af2701271b5d Run...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
{| width=500  style=&amp;quot;font-size: 10px; float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Intermediate unit test]]&lt;br /&gt;
|Next: [[Changing existing code base]]&lt;br /&gt;
|}&lt;br /&gt;
== Required course material for the lesson ==&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22113/Python10-Runtime.pptx Runtime evaluation of algorithms] Old ppt, not so important&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=41edc89b-61a5-475d-84d0-af2701271b5d Runtime Analysis] See this first&lt;br /&gt;
&lt;br /&gt;
== Subjects covered ==&lt;br /&gt;
Runtime evaluation of algorithms&amp;lt;br&amp;gt;&lt;br /&gt;
Big O notation&lt;br /&gt;
&lt;br /&gt;
== Big O notation ==&lt;br /&gt;
When you &amp;quot;calculate&amp;quot; the running time of a program or an algorithm you write your result in the &amp;#039;&amp;#039;&amp;#039;Big O&amp;#039;&amp;#039;&amp;#039; notation. The running time is the complexity of the algorithm. The hardest part about Big O is understanding the concept - performing the actual calculation is rather easy in most cases. Especially since there is no real calculation to do, but mostly just analysis of the code.&lt;br /&gt;
&lt;br /&gt;
== Some loosely explained theory ==&lt;br /&gt;
Any program is performing some operations when it is running. This could be addition of a number to a variable. It could be asking which number is the biggest or if two strings are identical. You have been programming; every statement is an operation.&lt;br /&gt;
&lt;br /&gt;
Calculating Big O is estimating the number of operations. This is &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; the number of statements. Some statements are executed several times in loops. Big O is more similar to the accumulated number of times each statement has been executed during the run of the program. While it is possible to calculate this number exactly, given an input and given that randomness is not part of the program, then this is not necessary and very uninteresting and possibly difficult.&lt;br /&gt;
&lt;br /&gt;
What is needed is an estimate that explains how the program&amp;#039;s running time scales with the size of the input; Big O.&lt;br /&gt;
Very often - almost always - a program contains loops that loop over data. Let&amp;#039;s take the program that calculates the average of a list/file of numbers as an example.&lt;br /&gt;
&lt;br /&gt;
 # pseudo code&lt;br /&gt;
 open file&lt;br /&gt;
 for each line in file&lt;br /&gt;
     sum = sum + number(line)&lt;br /&gt;
     increment(line_counter)&lt;br /&gt;
 close file&lt;br /&gt;
 print sum/line_counter&lt;br /&gt;
&lt;br /&gt;
The opening and closing of the file is done once, likewise the printing of the sum. The summing is done once per number/line. This means the more numbers there are in the file, the more additions are made. It scales with the number of numbers. The line_counter is also incremented once per line, so that obviously also scale in the same way as the summing.&amp;lt;br&amp;gt;&lt;br /&gt;
To put this in Big O notation: O(1 + n + n + 1 + 1) = O(2n + 3).&amp;lt;br&amp;gt;&lt;br /&gt;
This expression is still too complex. The &amp;quot;small stuff&amp;quot; is eliminated, this means remove the constants. They don&amp;#039;t tell much about how running time scales anyway.&amp;lt;br&amp;gt;&lt;br /&gt;
The final Big O notation: O(n), where n is the number of numbers.&amp;lt;br&amp;gt;&lt;br /&gt;
If you have a more complex Big O like: O(n*n + n), then the single n is thrown away as that is not important compared to n*n, so O(n*n) is the final result.&lt;br /&gt;
&lt;br /&gt;
== A collecting of internet resources on Big O ==&lt;br /&gt;
[http://stackoverflow.com/questions/487258/what-is-a-plain-english-explanation-of-big-o-notation Big O in plain English]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://rob-bell.net/2009/06/a-beginners-guide-to-big-o-notation/ A Beginner&amp;#039;s Guide to Big O Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://www.interviewcake.com/big-o-notation-time-and-space-complexity Big O Notation]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://bigocheatsheet.com/ Big-O Algorithm Complexity Cheat Sheet]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://justin.abrah.ms/computer-science/big-o-notation-explained.html Big O notation explained]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://justin.abrah.ms/computer-science/how-to-calculate-big-o.html How to calculate Big O]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://www.youtube.com/watch?v=V6mKVRU1evU Big O notations - a youtube video]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Big_O_notation Wikipedia&amp;#039;s entry on Big O] is particular useless. It is most likely correct, but impossible to understand. Don&amp;#039;t go there for information unless you like pain.&lt;br /&gt;
&lt;br /&gt;
If all you want to do is to measure how long your program takes to run in real time (seconds and minutes), then you should just use the &amp;#039;&amp;#039;&amp;#039;time&amp;#039;&amp;#039;&amp;#039; command in unix. Simply put it in front of your program.&lt;br /&gt;
&lt;br /&gt;
 # Normally you call your program like&lt;br /&gt;
 ./mypythonprogram.py fastafile&lt;br /&gt;
 # To see how long it takes to execute, use&lt;br /&gt;
 time ./mypythonprogram.py fastafile&lt;br /&gt;
&lt;br /&gt;
== How to calculate Big O in the project ==&lt;br /&gt;
When a program or algorithm is small, then it is often trivial to perform this &amp;quot;calculation&amp;quot;. In bigger pieces of software, you often need to be more systematic about it. Since we know that the loops are what matters in Big O, then keeping track of the loops in the software as comments is a great way of starting a system. In this example, I have a list of numbers where all must be multiplied in pairs and then summed.&amp;lt;br&amp;gt;&lt;br /&gt;
The code:&lt;br /&gt;
 numbers = [2,3,5,7,11,13]&lt;br /&gt;
 sum = 0&lt;br /&gt;
 for i in range(len(numbers)-1):&lt;br /&gt;
     for j in (j+1, range(numbers)):&lt;br /&gt;
         sum += numbers[i] * numbers[j]&lt;br /&gt;
 print(&amp;quot;Result:&amp;quot;, sum)&lt;br /&gt;
I start adding a comment about Big O in the inner loop. I discard the minor issues, like in essence the loop is at most n-1 long, and minimum 1 long. The worst case is what we use in these situations.&lt;br /&gt;
 numbers = [2,3,5,7,11,13]&lt;br /&gt;
 sum = 0&lt;br /&gt;
 for i in range(len(numbers)-1):&lt;br /&gt;
     # O(n), where n is the number of numbers, worst case&lt;br /&gt;
     for j in (j+1, range(numbers)):&lt;br /&gt;
         sum += numbers[i] * numbers[j]&lt;br /&gt;
 print(&amp;quot;Result:&amp;quot;, sum)&lt;br /&gt;
Then I add a Big O comment to the outer loop. Since I already have the Big O for the inner loop, it is easy.&lt;br /&gt;
 numbers = [2,3,5,7,11,13]&lt;br /&gt;
 sum = 0&lt;br /&gt;
 # O(n*n), where n is the number of numbers&lt;br /&gt;
 for i in range(len(numbers)-1):&lt;br /&gt;
     # O(n), where n is the number of numbers, worst case&lt;br /&gt;
     for j in (j+1, range(numbers)):&lt;br /&gt;
         sum += numbers[i] * numbers[j]&lt;br /&gt;
 print(&amp;quot;Result:&amp;quot;, sum)&lt;br /&gt;
Now I have the result, O(n*n), easily argued and explainable. Shown directly in the code. I should add some logical reasoning, but I have a strong analysis in the code, which can support me.&lt;br /&gt;
&lt;br /&gt;
== Exercises to be handed in ==&lt;br /&gt;
&amp;quot;Calculate&amp;quot; can mean many things here; Analyze, argue, explain, show, or even demonstrate. For some algorithms (not these) it even means &amp;quot;do a lot of math&amp;quot;. The calculation must be convincing and explained. Just showing the result is insufficient.&amp;lt;br&amp;gt;&lt;br /&gt;
# Calculate Big O of exercise 2 in [[Python Recap and Objects]]&lt;br /&gt;
# Calculate Big O of exercise 1 in [[Regular Expressions]]&lt;br /&gt;
# Calculate Big O of exercise 2 in [[Regular Expressions]]&lt;br /&gt;
# Calculate Big O of exercise 5 in [[Regular Expressions]]&lt;br /&gt;
# Calculate Big O of exercise 9 in [[Regular Expressions]]&lt;br /&gt;
# Calculate Big O of exercise 9 in [[Making Functions]]&lt;br /&gt;
# Calculate Big O of exercise 1 in [[Advanced Data Structures and New Data Types]]&lt;br /&gt;
# Calculate Big O of exercise 4 in [[Advanced Data Structures and New Data Types]]&lt;br /&gt;
# Calculate Big O of exercise 6 in [[Comprehension, Generators, Functions and Methods]]&lt;br /&gt;
&lt;br /&gt;
== Exercises for extra practice ==&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>