Answers.Body: <p>I used to teach some search and sorting algorithms but now my favorite teaching example is <a href="https://en.wikipedia.org/wiki/Euclidean_algorithm" rel="nofollow noreferrer">Euclidean algorithm</a> (GCD), for couple of reasons,</p>
  <ol>
  <li><p>It was probably the oldest algorithm. I can also talk about some history, one of my favorite subjects, but more importantly makes kids engaged.</p>
  </li>
  <li><p>Let them prove it themselves. It is quite easy and again makes them engaged.</p>
  </li>
  <li><p>Help them review/refresh recursion.</p>
  </li>
  <li><p>The most important reason I used it now is that the most popular video stream website in China, called <a href="https://www.bilibili.com/" rel="nofollow noreferrer">bilibili</a> (you can see it as the top TikTok competitor in China for young generation) crashed for almost 10 hours in 2021.07.13 for exactly a hidden bug in its implementation for GCD, written lua, <a href="https://mp.weixin.qq.com/s/nGtC5lBX_Iaj57HIdXq3Qg" rel="nofollow noreferrer">check here for detailed</a>, but it is in Chinese. So I will briefly explain here: they developed this innocent lua script for GCD for their <a href="https://openresty.org/en/" rel="nofollow noreferrer">OpenResty</a> web server. In 2021.07.13 under an extremely rare condition, the b parameter it got was '0' instead of 0, so the lua script  became an infinite loop and drain the whole computer cluster to death.</p>
  </li>
  </ol>
  <p>This real life example makes the whole discussion &quot;interactive&quot;!</p>
  <p><a href="https://i.sstatic.net/RiiMR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RiiMR.png" alt="GCD" /></a></p>
  <p>--- update ---</p>
  <p>Recently I teach the binary search and re-read this old article again &quot;<a href="https://ai.googleblog.com/2006/06/extra-extra-read-all-about-it-nearly.html" rel="nofollow noreferrer">Extra, Extra - Read All About It: Nearly All Binary Searches and Mergesorts are Broken</a>&quot;</p>
  <blockquote>
  <p>I remember vividly Jon Bentley's first Algorithms lecture at CMU,
  where he asked all of us incoming Ph.D. students to write a binary
  search, and then dissected one of our implementations in front of the
  class. Of course it was broken, as were most of our implementations.
  This made a real impression on me ...</p>
  </blockquote>
  <p>So maybe like what he described there, ask your students to implement a binary search in class. I don't do that because my students are highschoolers but for college students I feel it is appropriate.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-22T06:52:18.267Z
Answers.LastActivityDate: 2023-02-02T09:25:20.623Z
Answers.LastEditDate: 2023-02-02T09:25:20.623Z
Answers.UserDisplayName: Qiulang 邱朗
Answers.Body: <p>You could provide working code, load it into an IDE, and start a debugger. Stop at lines of code that are interesting. Or make a dump of data structures that are interesting. Perhaps during each iteration (or before and after an operation. To show how linked lists can grow, for example.<br />
  Demonstrating the basic usage of a debugger is valuable to anyone.</p>
  <p>You could also Benchmark some different variants/implementations of certain algorithms and ask in advance, which variant might run faster. You could do this in form of a poll (in your videoconferencing software) or just asking &quot;Raise your arm if you think algo 1 is faster&quot;.</p>
  <p>Let them benchmark on their machines and report results, to demonstrate that some results depend on hardware, on many factors.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-20T18:54:03.360Z
Answers.Text: My professor tried the first method. Nobody understood anything. 2nd year students don't understand what a debugger is and why they'd ever need it.
Answers.UserDisplayName: arunkumaraqm
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-01T17:54:48.617Z
Answers.LastActivityDate: 2022-05-01T17:54:48.617Z
Answers.UserDisplayName: knb
Answers.Body: <p>CS50 was open-source last time I checked... it's a very well designed curriculum. I remember there were people worlwide using their material to teach computer science. Just make sure their policies and licenses haven't change.</p>
  <p>CS50 is the introductory course of Computer Science by Harvard University. You can find the material at <a href="https://www.edx.org/course/introduction-computer-science-harvardx-cs50x" rel="nofollow noreferrer">https://www.edx.org/course/introduction-computer-science-harvardx-cs50x</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-30T11:04:06.077Z
Answers.Text: How is such a thing "interactive"?
Answers.UserDisplayName: Buffy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-30T02:07:53.230Z
Answers.LastActivityDate: 2022-04-30T02:07:53.230Z
Answers.UserDisplayName: Daniel N.
Answers.Body: <p>I'm a bit worried about the scale here, but I often did some interesting things when there were fewer than about 30 students. Maybe you can make it work. I'll give a couple of examples using sorting. To do them you need a bunch of cards (maybe bigger than index cards at this scale) and a marking pen.</p>
  <p>Call it playtime. (Done with university students in a CS major)</p>
  <p>Write a bunch of integers on individual cards (probably about eight cards). Hand them out to a bunch of students, one card each. Have them stand in line facing the class with the numbers in random sequence, cards visible.</p>
  <p>Insertion  sort:</p>
  <p>Have one student not in the line point to the second person in the line from the left side of the line.</p>
  <p>Pull the person pointed to out of line, compare their number with that of the first person and if the number is less, push (gently) the first person down to the now empty (right) slot to make a slot for the one you pulled out and push them into the open slot.</p>
  <p>Tell the &quot;pointing student&quot; to point one person farther on. Go there, pull that person out of line and then move down toward the left, pushing people right as long as their number is larger than the one you've pulled out. Put them into the now empty slot. Repeat.</p>
  <p>The quadratic sorts are all pretty easy to manage. The faster ones can be done (with mistakes and lots of laughing) using some students as data and other students as pointers. Merge sort might be the hardest, but note that with some practice it can be done in parallel. But first practice merging as a separate &quot;play&quot;.</p>
  <p>For quick sort you might be able to have about 16 data points and fewer might not give enough data to help the students grok the method.</p>
  <p>Searching is also possible and a bit simpler. One or several &quot;pointer&quot; students to keep track of things.</p>
  <p>I also did some general recursion lessons having one student with a &quot;base case&quot; script and adding additional students to a list with a different script that, say, either returned a value or passed the process down toward the base case. I'd guess that tree algorithms might be too messy to manage, though.</p>
  <p>You can do something similar (with care) to teach linear recursion by adapting <a href="https://www.nurseryrhymes.org/there-was-an-old-lady-who-swallowed-a-fly.html" rel="nofollow noreferrer">There was an old lady who swallowed a fly</a> into what I called choir practice. The base case is &quot;'I don't know why she swallowed a fly, perhaps she'll die'&quot;. You need to be choir director feeding the initial lines of each verse and handing a card to a new student with their lines.</p>
  <p>You say, at one point, &quot;There was an old woman who swallowed a cat. Imagine that, to swallow a cat&quot;. Hand a new student the card &quot;She swallowed the cat to catch the bird&quot; who reads the card aloud, and points to (recurses) to the next person whose card gets read again (&quot;She swallowed the bird to catch the spider&quot;) and passes control (points to) the next student.</p>
  <p>Note that you (choir director) terminates when you reach the &quot;horse&quot; verse.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-01T18:25:17.073Z
Answers.LastActivityDate: 2022-05-01T20:53:39.373Z
Answers.LastEditDate: 2022-05-01T20:53:39.373Z
Answers.UserDisplayName: Buffy
Body: <p>I am faculty of computer science. Currently, I am teaching a design and analysis of algorithms course to second-year undergraduate students. This is my second semester of teaching before this I have done a Teaching assistantship during my Ph.D.</p>
  <p>I am feeling like 50 percent of my class is not understanding what I try to teach in the class there 10-15 percent of students have understood the content I have taught. This observation comes from the result of the quiz I conducted last week.</p>
  <p>I have tried my best to teach algorithms, I use slides and a board (50-50 percent time). Always starts with two-three examples and then discusses the cases of algorithms and ask questions in between trying to take the response from students and at the end presents the algorithm. I do problem-solving one time a week.</p>
  <p>I want to engage students to participate in the class but only fractions of them seems interested like 20-30 percent. When I do problem-solving then participation is more it is around 50 percent.</p>
  <p>Kindly suggest some techniques to make the course more interactive and create interest in most of the students.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-18T11:00:01.620Z
Comments.Text: Have you kept in mind the fact that simply some of them (even maybe up to 50% of them) may not be interested in algorithms at all? They may be aspiring frontend developers, DevOpses, network administrators... CS is about the broad knowledge revolving around computers and students need to be able to grasp at least the bare minimum of everything you teach there, but from my experience peaks of 50% of the students actively participating in any algorithms and data structures courses is a very decent result. You can't engage everyone. Without more details, it's gonna be hard to offer decent advises
Comments.UserDisplayName: Fureeish
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-18T11:26:22.417Z
Comments.Text: @Fureeish, that sounds very wrong. A CS degree isn't a jobs program. It is an education program.
Comments.UserDisplayName: Buffy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-18T11:27:19.517Z
Comments.Text: What do you mean by "interactive"? Or do you intend "active learning"? Not quite the same thing. How many students do you have?
Comments.UserDisplayName: Buffy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-18T11:45:53.577Z
Comments.Text: @Buffy why would that sound very wrong? And while I agree that in principle, CS degree is not about landing a job but about obtaining knowledge, ultimately this knowledge is meant to be used. Majority of CS students want to land a job after they finish university. If your students mostly consist of people that seek knowledge just for the sake of seeking knowledge, I do surely envy you. And I believe that CS degree should be on par with current jobs' requirements and expectations.
Comments.UserDisplayName: Fureeish
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-18T14:43:06.003Z
Comments.Text: @  Buffy, Class of size 60. Interactive means students participate in the activities which I do in the class. Like if I aks something then they respond and given me answers /opionions.
Comments.UserDisplayName: Shi
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-18T14:44:34.853Z
Comments.Text: @ Fureeish Yes students here are mostly interested in Webdesign, full stack development etc.
Comments.UserDisplayName: Shi
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-19T22:59:18.323Z
Comments.Text: @Shi Does this course use a textbook like Skiena's *The Algorithm Design Manual*? I am asking because some algorithms courses are oriented towards the theoretical, while others are oriented towards the practical, encouraging experimentation by the students. I am a hands-on learner myself. When I was a CS student (a long time ago; retired software engineer now), the first kind of class would bore me to no end, while the latter kind would get me all fired up, inspiring me to experiment and research the literature beyond what was needed for class.
Comments.UserDisplayName: njuffa
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-20T10:11:17.360Z
Comments.Text: @Fureeish There are algorithms in front end. sort, search, square-root, etc are not the only algorithms.And front-end devs will use the back-end algorithms. Get them interested in how to choose an implementation. Teach then algorithms that are relevant to them.
Comments.UserDisplayName: ctrl-alt-delor
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-20T10:50:37.337Z
Comments.Text: @ctrl-alt-delor I really dislike arguments like these, because one can strech them further indefinitely. Should an aspiring web-developer learn assembly because - after all - the code they write will be transformed into it? I don't think so. It's *good* to have a basic understanding of it, but it won't be pleasant for everyone. Algorithms are a little bit different. They are way closer to maths. Should everyone learn maths? Yes, beacuse it teaches *a way of thinking*. Should everyone at a CS program learn algorithms? Yes, for the same reason. Will everyone enjoy maths / algorithms? No, never.
Comments.UserDisplayName: Fureeish
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-04-20T13:43:21.053Z
Comments.Text: @ njuffa, I assign problems from the skiena's book but I cover theory part from coreman or jeff erickson's lecture notes.
Comments.UserDisplayName: Shi
Tags: <algorithms>
Title: How to teach algorithms in an interactive way
ThreadText: # How to teach algorithms in an interactive way
  
  (Asked by: username_0 on 2022-04-18)
  
  I am faculty of computer science. Currently, I am teaching a design and analysis of algorithms course to second-year undergraduate students. This is my second semester of teaching before this I have done a Teaching assistantship during my Ph.D.
  
  I am feeling like 50 percent of my class is not understanding what I try to teach in the class there 10-15 percent of students have understood the content I have taught. This observation comes from the result of the quiz I conducted last week.
  
  I have tried my best to teach algorithms, I use slides and a board (50-50 percent time). Always starts with two-three examples and then discusses the cases of algorithms and ask questions in between trying to take the response from students and at the end presents the algorithm. I do problem-solving one time a week.
  
  I want to engage students to participate in the class but only fractions of them seems interested like 20-30 percent. When I do problem-solving then participation is more it is around 50 percent.
  
  Kindly suggest some techniques to make the course more interactive and create interest in most of the students.
  
  **Tags:** algorithms
  
  > **Comments:**
  > **username_1**: Have you kept in mind the fact that simply some of them (even maybe up to 50% of them) may not be interested in algorithms at all? They may be aspiring frontend developers, DevOpses, network administrators... CS is about the broad knowledge revolving around computers and students need to be able to grasp at least the bare minimum of everything you teach there, but from my experience peaks of 50% of the students actively participating in any algorithms and data structures courses is a very decent result. You can't engage everyone. Without more details, it's gonna be hard to offer decent advises  
  > **username_2**: @username_1, that sounds very wrong. A CS degree isn't a jobs program. It is an education program.  
  > **username_2**: What do you mean by "interactive"? Or do you intend "active learning"? Not quite the same thing. How many students do you have?  
  > **username_1**: @username_2 why would that sound very wrong? And while I agree that in principle, CS degree is not about landing a job but about obtaining knowledge, ultimately this knowledge is meant to be used. Majority of CS students want to land a job after they finish university. If your students mostly consist of people that seek knowledge just for the sake of seeking knowledge, I do surely envy you. And I believe that CS degree should be on par with current jobs' requirements and expectations.  
  > **username_0**: @  username_2, Class of size 60. Interactive means students participate in the activities which I do in the class. Like if I aks something then they respond and given me answers /opionions.  
  > **username_0**: @ username_1 Yes students here are mostly interested in Webdesign, full stack development etc.  
  > **username_3**: @username_0 Does this course use a textbook like Skiena's *The Algorithm Design Manual*? I am asking because some algorithms courses are oriented towards the theoretical, while others are oriented towards the practical, encouraging experimentation by the students. I am a hands-on learner myself. When I was a CS student (a long time ago; retired software engineer now), the first kind of class would bore me to no end, while the latter kind would get me all fired up, inspiring me to experiment and research the literature beyond what was needed for class.  
  > **username_4**: @username_1 There are algorithms in front end. sort, search, square-root, etc are not the only algorithms.And front-end devs will use the back-end algorithms. Get them interested in how to choose an implementation. Teach then algorithms that are relevant to them.  
  > **username_1**: @username_4 I really dislike arguments like these, because one can strech them further indefinitely. Should an aspiring web-developer learn assembly because - after all - the code they write will be transformed into it? I don't think so. It's *good* to have a basic understanding of it, but it won't be pleasant for everyone. Algorithms are a little bit different. They are way closer to maths. Should everyone learn maths? Yes, beacuse it teaches *a way of thinking*. Should everyone at a CS program learn algorithms? Yes, for the same reason. Will everyone enjoy maths / algorithms? No, never.  
  > **username_0**: @ username_3, I assign problems from the skiena's book but I cover theory part from coreman or jeff erickson's lecture notes.  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_2 on 2022-05-01. Score: 4 | Accepted answer
  
  I'm a bit worried about the scale here, but I often did some interesting things when there were fewer than about 30 students. Maybe you can make it work. I'll give a couple of examples using sorting. To do them you need a bunch of cards (maybe bigger than index cards at this scale) and a marking pen.
  
  Call it playtime. (Done with university students in a CS major)
  
  Write a bunch of integers on individual cards (probably about eight cards). Hand them out to a bunch of students, one card each. Have them stand in line facing the class with the numbers in random sequence, cards visible.
  
  Insertion sort:
  
  Have one student not in the line point to the second person in the line from the left side of the line.
  
  Pull the person pointed to out of line, compare their number with that of the first person and if the number is less, push (gently) the first person down to the now empty (right) slot to make a slot for the one you pulled out and push them into the open slot.
  
  Tell the "pointing student" to point one person farther on. Go there, pull that person out of line and then move down toward the left, pushing people right as long as their number is larger than the one you've pulled out. Put them into the now empty slot. Repeat.
  
  The quadratic sorts are all pretty easy to manage. The faster ones can be done (with mistakes and lots of laughing) using some students as data and other students as pointers. Merge sort might be the hardest, but note that with some practice it can be done in parallel. But first practice merging as a separate "play".
  
  For quick sort you might be able to have about 16 data points and fewer might not give enough data to help the students grok the method.
  
  Searching is also possible and a bit simpler. One or several "pointer" students to keep track of things.
  
  I also did some general recursion lessons having one student with a "base case" script and adding additional students to a list with a different script that, say, either returned a value or passed the process down toward the base case. I'd guess that tree algorithms might be too messy to manage, though.
  
  You can do something similar (with care) to teach linear recursion by adapting [There was an old lady who swallowed a fly](https://www.nurseryrhymes.org/there-was-an-old-lady-who-swallowed-a-fly.html) into what I called choir practice. The base case is "'I don't know why she swallowed a fly, perhaps she'll die'". You need to be choir director feeding the initial lines of each verse and handing a card to a new student with their lines.
  
  You say, at one point, "There was an old woman who swallowed a cat. Imagine that, to swallow a cat". Hand a new student the card "She swallowed the cat to catch the bird" who reads the card aloud, and points to (recurses) to the next person whose card gets read again ("She swallowed the bird to catch the spider") and passes control (points to) the next student.
  
  Note that you (choir director) terminates when you reach the "horse" verse.
  
  
  ---
  
  ### Answer by username_5 on 2022-08-22. Score: 2
  
  I used to teach some search and sorting algorithms but now my favorite teaching example is [Euclidean algorithm](https://en.wikipedia.org/wiki/Euclidean_algorithm) (GCD), for couple of reasons,
  
  1. It was probably the oldest algorithm. I can also talk about some history, one of my favorite subjects, but more importantly makes kids engaged.
  2. Let them prove it themselves. It is quite easy and again makes them engaged.
  3. Help them review/refresh recursion.
  4. The most important reason I used it now is that the most popular video stream website in China, called [bilibili](https://www.bilibili.com/) (you can see it as the top TikTok competitor in China for young generation) crashed for almost 10 hours in 2021.07.13 for exactly a hidden bug in its implementation for GCD, written lua, [check here for detailed](https://mp.weixin.qq.com/s/nGtC5lBX_Iaj57HIdXq3Qg), but it is in Chinese. So I will briefly explain here: they developed this innocent lua script for GCD for their [OpenResty](https://openresty.org/en/) web server. In 2021.07.13 under an extremely rare condition, the b parameter it got was '0' instead of 0, so the lua script became an infinite loop and drain the whole computer cluster to death.
  
  This real life example makes the whole discussion "interactive"!
  
  [![GCD](https://i.sstatic.net/RiiMR.png)](https://i.sstatic.net/RiiMR.png)
  
  --- update ---
  
  Recently I teach the binary search and re-read this old article again "[Extra, Extra - Read All About It: Nearly All Binary Searches and Mergesorts are Broken](https://ai.googleblog.com/2006/06/extra-extra-read-all-about-it-nearly.html)"
  
  > I remember vividly Jon Bentley's first Algorithms lecture at CMU,
  > where he asked all of us incoming Ph.D. students to write a binary
  > search, and then dissected one of our implementations in front of the
  > class. Of course it was broken, as were most of our implementations.
  > This made a real impression on me ...
  
  So maybe like what he described there, ask your students to implement a binary search in class. I don't do that because my students are highschoolers but for college students I feel it is appropriate.
  
  
  ---
  
  ### Answer by username_6 on 2022-05-01. Score: 2
  
  You could provide working code, load it into an IDE, and start a debugger. Stop at lines of code that are interesting. Or make a dump of data structures that are interesting. Perhaps during each iteration (or before and after an operation. To show how linked lists can grow, for example.  
  Demonstrating the basic usage of a debugger is valuable to anyone.
  
  You could also Benchmark some different variants/implementations of certain algorithms and ask in advance, which variant might run faster. You could do this in form of a poll (in your videoconferencing software) or just asking "Raise your arm if you think algo 1 is faster".
  
  Let them benchmark on their machines and report results, to demonstrate that some results depend on hardware, on many factors.
  
  > **Comments:**
  > **username_7**: My professor tried the first method. Nobody understood anything. 2nd year students don't understand what a debugger is and why they'd ever need it.  
  
  ---
  
  ### Answer by username_8 on 2022-04-30. Score: 1
  
  CS50 was open-source last time I checked... it's a very well designed curriculum. I remember there were people worlwide using their material to teach computer science. Just make sure their policies and licenses haven't change.
  
  CS50 is the introductory course of Computer Science by Harvard University. You can find the material at <https://www.edx.org/course/introduction-computer-science-harvardx-cs50x>
  
  > **Comments:**
  > **username_2**: How is such a thing "interactive"?  
  
  ---
  
  