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 3rd Edition
This is the forum to discuss the Wrox book Programming Interviews Exposed: Secrets to Landing Your Next Job, 3rd Edition by John Mongan, Noah Kindler, Eric Giguere; ISBN: 978-1-118-26136-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK Programming Interviews Exposed: Secrets to Landing Your Next Job 3rd Edition 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 March 12th, 2015, 02:29 PM
mjr mjr is offline
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Optimized Quicksort (3rd ed., p 142)

Should the comparison be changed from <= to <, since there's no need to swap an element with itself, unless
the swap isn't important (i.e., it doesn't do any harm) at that point and the need is just to adjust both i and j variables?

// If the values are in the wrong order, swap them.
if( i <= j ){

Compared to
// ...
if( i < j ) {

Thanks,

Last edited by mjr; March 12th, 2015 at 02:57 PM.
Reply With Quote
  #2 (permalink)  
Old July 11th, 2017, 03:20 PM
Wrox Author
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Exactly: when i == j the swap does nothing, but adjusting the values of i and j is essential. You could modify the code to eliminate this wasted swap, but I'm not sure the increased complexity would be worth it.

John
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
Initial Comments - XSLT 2.0 3rd Ed. baryza Wrox Book Feedback 1 July 9th, 2007 07:18 PM
doubts on introduction of professional c# 3rd ed benraidertx BOOK: Professional C#, 2nd and 3rd Editions 1 June 1st, 2005 04:47 PM
Where did the Appendicies go? - 3rd ed AndrewGiles BOOK: Professional C#, 2nd and 3rd Editions 1 January 4th, 2005 07:04 PM
Expanding Forum to Cover Professional C# 3rd Ed jminatel BOOK: Professional C#, 2nd and 3rd Editions 0 July 21st, 2004 03:37 PM



All times are GMT -4. The time now is 02:26 AM.


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