Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK Programming Interviews Exposed: Secrets to Landing Your Next Job 2nd Ed ISBN: 978-0-470-12167-2
This is the forum to discuss the Wrox book Programming Interviews Exposed: Secrets to Landing Your Next Job, 2nd Edition by John Mongan, Noah Suojanen, Eric Gigučre; ISBN: 9780470121672
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK Programming Interviews Exposed: Secrets to Landing Your Next Job 2nd Ed ISBN: 978-0-470-12167-2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 18th, 2011, 05:53 PM
Registered User
 
Join Date: Apr 2011
Posts: 2
Thanks: 1
Thanked 1 Time in 1 Post
Default determineTermination bug

I believe the function determineTermination in Chapter 4 to determine if a list is acyclic or cyclic has a bug.

The function starts with:
fast = slow = head;
Then, without modifying fast or slow, checks:
else if ( fast==slow || ...)
return true;

Assuming the head exists and the list has at least two nodes (the first if condition), determineTermination will always return true.
Reply With Quote
The Following User Says Thank You to Malina For This Useful Post:
WayneHeym (May 27th, 2011)
  #2 (permalink)  
Old April 19th, 2011, 03:59 AM
mlb mlb is offline
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes. I noticed the same thing.
Reply With Quote
The Following User Says Thank You to mlb For This Useful Post:
WayneHeym (May 27th, 2011)
  #3 (permalink)  
Old June 8th, 2011, 05:03 PM
Registered User
 
Join Date: Jun 2011
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Default Errata

Yes. Fortunately they have addressed this in the errata: http://www.wiley.com/legacy/compbook...ew/errata.html
Reply With Quote
The Following User Says Thank You to User5910 For This Useful Post:
Malina (June 8th, 2011)
  #4 (permalink)  
Old June 8th, 2011, 05:20 PM
Registered User
 
Join Date: Apr 2011
Posts: 2
Thanks: 1
Thanked 1 Time in 1 Post
Default

Thanks for the link. I had been consulting this page for errata:

http://www.wrox.com/WileyCDA/WroxTit...Cd-ERRATA.html

and hadn't seen this listed there.
Reply With Quote
  #5 (permalink)  
Old June 11th, 2011, 04:40 PM
Authorized User
Points: 68, Level: 1
Points: 68, Level: 1 Points: 68, Level: 1 Points: 68, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 15
Thanks: 11
Thanked 0 Times in 0 Posts
Default Indicated page of Errata is apparently for first edition

As I'm looking at the second edition, not the first edition, I can't be sure, but it appears that the page http://www.wiley.com/legacy/compbook...ew/errata.html is a list of errata for the first edition, not the second. The page numbers don't match the second edition. Sadly, it appears that only one of these four errors was corrected in the second edition. Perhaps the additional author for that edition, Eric Gigučre, wasn't aware of this errata page.

Regards,

Wayne
Reply With Quote
  #6 (permalink)  
Old June 17th, 2013, 03:07 AM
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Malina View Post
I believe the function determineTermination in Chapter 4 to determine if a list is acyclic or cyclic has a bug.

The function starts with:
fast = slow = head;
Then, without modifying fast or slow, checks:
else if ( fast==slow || ...)
return true;

Assuming the head exists and the list has at least two nodes (the first if condition), determineTermination will always return true.
Actually, can't the check for fast==slow and fast->next == slow be moved to the end of the loop such that there is no need for additional ugly coding with another variable first ??
Reply With Quote
  #7 (permalink)  
Old June 17th, 2013, 01:32 PM
Authorized User
Points: 68, Level: 1
Points: 68, Level: 1 Points: 68, Level: 1 Points: 68, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 15
Thanks: 11
Thanked 0 Times in 0 Posts
Default In search of elegance

I appreciate your pointing out the inelegance of using an extra variable (in this case, the variable "first"). Fortunately, the newest edition (the third edition, copyright 2013) of this book observes that it is valuable "to start the fast pointer one node ahead of the slow pointer so they're not equal to begin with." (p. 59) Hence, the trouble with the earlier published versions is avoided without resorting to the inelegance of using an extra variable.

Regards,

Wayne
Reply With Quote
  #8 (permalink)  
Old June 19th, 2013, 12:56 PM
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by WayneHeym View Post
I appreciate your pointing out the inelegance of using an extra variable (in this case, the variable "first"). Fortunately, the newest edition (the third edition, copyright 2013) of this book observes that it is valuable "to start the fast pointer one node ahead of the slow pointer so they're not equal to begin with." (p. 59) Hence, the trouble with the earlier published versions is avoided without resorting to the inelegance of using an extra variable.

Regards,

Wayne
Thanks Wayne for the positive reply.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bug or no to bug learning C using VS.Net to compil tesh All Other Wrox Books 0 February 14th, 2007 01:06 PM
Span Bug? interrupt HTML Code Clinic 4 June 20th, 2006 10:40 AM
bug in jsp sagar Pro JSP 0 July 5th, 2004 10:16 AM
Bug happens guoqi BOOK: ASP.NET Website Programming Problem-Design-Solution 0 October 13th, 2003 02:35 PM



All times are GMT -4. The time now is 06:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.