# Algorithms 4th Edition (Sedgewick / Wayne)

**URL:** <https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25>\
**Category:** Learning Resources and Study Groups\
**Created:** [December 16, 2017, 10:14pm UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25 "2017-12-16T22:14:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [December 16, 2017, 10:14pm UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/1 "2017-12-16T22:14:33Z")

</div>

This section of the forum is for people who are working through [Algorithms 4th Edition](https://algs4.cs.princeton.edu/home/) and/or the related Coursera courses ([part 1](https://www.coursera.org/learn/algorithms-part1) and [part 2](https://www.coursera.org/learn/algorithms-part2)).

I’m reading the book at a very slow pace.

---

<div class="post-metadata">

**Author:** ![eayoungs](https://forum.codeselfstudy.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@eayoungs](https://forum.codeselfstudy.com/u/eayoungs)\
**Post date:** [December 20, 2017, 8:44pm UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/2 "2017-12-20T20:44:20Z")

</div>

Hey, Josh. I’m planning to work through this book in the new year. I might sign up for the Coursera course as well.

Eric

---

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [December 20, 2017, 8:50pm UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/3 "2017-12-20T20:50:56Z")

</div>

Great, we could share tips here and/or try to solve the puzzles in different languages.

If we need to hide algorithm implementations from the book, there is a “hide details” feature if you click the gear icon when writing a post. Here’s an example:

> **Click here to show the text**
>
> ```python
> def greeting():
> """Implement hello world."""
> return('saluton mondo')
> 
> if __name__ == ' __main__':
> print(greeting())
> 
> ```

---

<div class="post-metadata">

**Author:** ![eayoungs](https://forum.codeselfstudy.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@eayoungs](https://forum.codeselfstudy.com/u/eayoungs)\
**Post date:** [December 20, 2017, 8:56pm UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/4 "2017-12-20T20:56:00Z")

</div>

Great! Thanks for sharing that. I think it will be very helpful.

---

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [December 21, 2017, 12:15am UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/5 "2017-12-21T00:15:45Z")

</div>

@eayoungs - The percolation exercise is [here](https://www.coursera.org/learn/algorithms-part1/programming/Lhp5z/percolation).

I didn’t write anything below than they didn’t mention in the assignment, but just translated their description into methods that don’t work yet. I don’t know Java, so this was just trying to get code to compile.

> **PercolationStats.java**
>
> ```java
> import java.util.*;
> import edu.princeton.cs.algs4.StdOut;
> 
> public class PercolationStats {
> 
> public PercolationStats(int n, int trials) // perform trials independent experiments on an n-by-n grid
> {
> }
> 
> // sample mean of percolation threshold
> public static double mean(double a, double b)
> {
> // TODO: this is not the correct calculation.
> double result = a * b;
> return result;
> }
> 
> public double stddev() // sample standard deviation of percolation threshold
> {
> return 0.0;
> }
> 
> public double confidenceLo() // low endpoint of 95% confidence interval
> {
> return 0.0;
> }
> 
> public double confidenceHi() // high endpoint of 95% confidence interval
> {
> return 0.0;
> }
> 
> public static void main(String[] args) // test client (described below)
> {
> 
> double n = Double.parseDouble(args[0]);
> double t = Double.parseDouble(args[1]);
> double main_result = mean(n, t);
> 
> StdOut.println("The result is: " + main_result);
> 
> }
> }
> 
> ```

> **Percolation.java**
>
> ```java
> public class Percolation {
> 
> /**
> * Throw a java.lang.IllegalArgumentException if any argument to open(), isOpen(), or isFull() is
> * outside its prescribed range. The constructor should throw a java.lang.IllegalArgumentException if n ≤ 0.
> *
> *
> * Performance requirements. The constructor should take time proportional to n2; all methods should take constant
> * time plus a constant number of calls to the union–find methods union(), find(), connected(), and count().
> */
> 
> public Percolation(int n)
> {
> // create n-by-n grid, with all sites blocked
> }
> 
> public void open(int row, int col)
> {
> // open site (row, col) if it is not open already
> }
> 
> public boolean isOpen(int row, int col)
> {
> // is site (row, col) open?
> }
> 
> public boolean isFull(int row, int col)
> {
> // is site (row, col) full?
> }
> 
> public int numberOfOpenSites()
> {
> // number of open sites
> }
> 
> public boolean percolates()
> {
> // does the system percolate?
> }
> 
> public static void main(String[] args)
> {
> // test client (optional)
> }
> 
> }
> 
> ```

I may revisit the assignment later but will probably focus more on trying to get through the book than the course.

---

<div class="post-metadata">

**Author:** ![eayoungs](https://forum.codeselfstudy.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@eayoungs](https://forum.codeselfstudy.com/u/eayoungs)\
**Post date:** [December 21, 2017, 12:21am UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/6 "2017-12-21T00:21:40Z")

</div>

Oh, I thought maybe you translated it to Python. No worries if you don’t get back to it for a while, this will be a good reference for me. Thanks!

---

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [December 21, 2017, 12:22am UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/7 "2017-12-21T00:22:49Z")

</div>

Not that assignment, but it would be easy to translate into Python classes.

---

<div class="post-metadata">

**Author:** ![eayoungs](https://forum.codeselfstudy.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@eayoungs](https://forum.codeselfstudy.com/u/eayoungs)\
**Post date:** [January 4, 2018, 1:35am UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/8 "2018-01-04T01:35:51Z")

</div>

Just FYI; if anyone else is working on the first assignment, I just got a passing submission. I’m new to Java so mine is by no means an expert opinion but I’d be happy to discuss!

---

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [January 4, 2018, 3:32am UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/9 "2018-01-04T03:32:04Z")

</div>

I’d be interested in seeing how it works.

---

<div class="post-metadata">

**Author:** ![eayoungs](https://forum.codeselfstudy.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@eayoungs](https://forum.codeselfstudy.com/u/eayoungs)\
**Post date:** [January 4, 2018, 4:01am UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/10 "2018-01-04T04:01:19Z")

</div>

Sure; I just don’t want to run afoul of the Coursera code of conduct.

---

<div class="post-metadata">

**Author:** ![eayoungs](https://forum.codeselfstudy.com/letter_avatar_proxy/v4/letter/e/3ab097/32.png) [@eayoungs](https://forum.codeselfstudy.com/u/eayoungs)\
**Post date:** [January 4, 2018, 7:53pm UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/11 "2018-01-04T19:53:44Z")

</div>

I’ve found some of the work translated into Scala; I’m hoping to go through that code and would be interested in discussing the implementation and it’s differences from Java to Scala.

> **[garyaiki/Scala-Algorithms](https://github.com/garyaiki/Scala-Algorithms)**
>
> Scala translations of Robert Sedgewick's Java Algorthms

---

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [January 5, 2018, 1:55am UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/12 "2018-01-05T01:55:21Z")

</div>

Thanks. There are some other interesting courses listed there too.

> **[Functional Programming in Scala](https://www.coursera.org/specializations/scala)**
>
> Offered by École Polytechnique Fédérale de Lausanne. Program on a Higher Level. Write elegant functional code to analyze data that's big or ... Enroll for free.

> **[Functional Programming Principles in Scala](https://www.coursera.org/learn/scala-functional-programming)**
>
> Offered by École Polytechnique Fédérale de Lausanne. Functional programming is becoming increasingly widespread in industry. This trend is ... Enroll for free.

---

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [January 22, 2020, 12:32pm UTC](https://forum.codeselfstudy.com/t/algorithms-4th-edition-sedgewick-wayne/25/13 "2020-01-22T12:32:52Z")

</div>

I found some versions of the problems in other languages.

## JavaScript

> **[ohdonghoon1128/algorithms](https://github.com/ohdonghoon1128/algorithms)**
>
> Node.js (es6) algorithms from Robert Sedgewick and Kevin Wayne's algs4

> **[zachverb/Sedgewick-Algorithms-Javascript](https://github.com/zachverb/Sedgewick-Algorithms-Javascript)**
>
> My implementation of Sedgewick's algorithm problems in Javascript

## Python

> **[ChangeMyUsername/algorithms-sedgewick-python](https://github.com/ChangeMyUsername/algorithms-sedgewick-python)**
>
> Algorithms(4th edition) by Robert Sedgewick and Kevin Wayne exercises in python

## Java

> **[reneargento/algorithms-sedgewick-wayne](https://github.com/reneargento/algorithms-sedgewick-wayne)**
>
> Solutions to all the exercises of the Algorithms book by Robert Sedgewick and Kevin Wayne
