pjd

pjd

A Common-Sense Guide to Data Structures and Algorithms, Second Edition: suggestion for sum_swap example (page 413)

Maybe you were just trying to keep the sum_swap code clean and streamlined for ease of reading, but this method didn’t seem as air-tight as other example methods in the book. You may want to at least comment that not all cases are handled by the method.

Two ways I think this method might fail are 1) the method does not handle the case where swapping to even out the sums is not possible, and 2) since shift_amount is calculated with integer division and thus will always be an integer, I suspect that sum_swap could give an incorrect answer if sum_1 - sum_2 is an odd number.

Then again, maybe those types of caveats are understood and maybe I missed other such scenarios elsewhere in the book.

I’m getting close to the end…finally! Great book, very well-written and helpful for me!

Most Liked

jaywengrow

jaywengrow

Author of A Common-Sense Guide to Data Structures and Algorithms

Thank you! Currently, the method does handle cases where swapping the sums isn’t possible, as it returns nil at the end. However, you are correct about the odd number issue. I will handle this in a future version. Good catch!

Popular Prag Prog topics Top

New
jon
Some minor things in the paper edition that says “3 2020” on the title page verso, not mentioned in the book’s errata online: p. 186 But...
New
iPaul
page 37 ANTLRInputStream input = new ANTLRInputStream(is); as of ANTLR 4 .8 should be: CharStream stream = CharStreams.fromStream(i...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=> (create-...
New
edruder
I thought that there might be interest in using the book with Rails 6.1 and Ruby 2.7.2. I’ll note what I needed to do differently here. ...
New
AleksandrKudashkin
On the page xv there is an instruction to run bin/setup from the main folder. I downloaded the source code today (12/03/21) and can’t see...
New
hazardco
On page 78 the following code appears: <%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
New
New
dachristenson
I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity...
New

Other popular topics Top

AstonJ
Or looking forward to? :nerd_face:
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
PragmaticBookshelf
A Hero’s Journey with Chris Pine @chrispine Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1122 25120 742
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New

Latest in PragProg

View all threads ❯