Dealing With Teacher

This is a discussion on Dealing With Teacher within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by swgh The other reason could be he is "teaching what he was taught" when he learned the ...

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by swgh View Post
    The other reason could be he is "teaching what he was taught" when he learned the language. So, he can only suggest concepts that he belives to be true, dispite them being flawed.
    Yes, it is technically impossible to teach things you don't know, right? This does, of course, not make the teacher any more right.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    The problem here is that you will be 'programming' your brain to use incorrect programming practices. It is very hard to remove that bad programming at will and so I would not mess with the class. Your best bet may be to wait until a different teacher teaches it or buy a good book on C++ programming and go from there.

    I highly recommend The C++ Programming Language by Bjarne Stroustrup. I have about 7 different books on C++ and Bjarne's by far takes C++ to the next level far beyond what the other books show. Bjarne's book explains everything about the language and you can be sure that what is mentioned in the book is accurate and standardized. Some say the book is difficult to read and understand but I've had no issues with it.
    Last edited by VirtualAce; 09-23-2007 at 02:09 PM.

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    There are a few minor issues with Stroustrup's book that I've noticed, but they're probably covered in a short errata list somewhere. One is that he talks about the export keyword without mentioning that very few compilers actually implement it, so in practice you end up putting whole template definitions in header files, not just the declarations. To be fair, this was written in 1997, and he apparently thought it would be implemented soon. He also says that the worst-case performance of sort() is O(N*N), which was true at the time, but shortly after the implementation was changed from quicksort to introsort which is O(N*log(N)) worst-case.

    http://www.sgi.com/tech/stl/sort.html

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,403
    He also says that the worst-case performance of sort() is O(N*N), which was true at the time, but shortly after the implementation was changed from quicksort to introsort which is O(N*log(N)) worst-case.
    From what I see the C++ standard only mandates a N log N comparisons in the average case, so perhaps the choice of introsort over the other O(n log n) sorts is implementation specific, and thus an O(n*n) worst case would be acceptable.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Quote Originally Posted by laserlight View Post
    From what I see the C++ standard only mandates a N log N comparisons in the average case, so perhaps the choice of introsort over the other O(n log n) sorts is implementation specific, and thus an O(n*n) worst case would be acceptable.
    I hope this will be changed in C++09. According to the link, introsort is at least as fast as quicksort on average, so it shouldn't cost anything to make the stronger guarantee - and one can always take any fast average-case algorithm and turn it into a hybrid with something like mergesort to also get O(n log n) worst-case. I have code with several stages including a sort operation, none of the others being worse than O(n log n) worst-case, and if I can't count on the sorting to be the same, it throws a wrench into the works. There must be others in the same boat. Stroustrup does say that stable_sort() is supposed to be O(n log n) worst-case (with sufficient memory) - do you know if the current standard guarantees that?

  6. #21
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,403
    According to the link, introsort is at least as fast as quicksort on average, so it shouldn't cost anything to make the stronger guarantee - and one can always take any fast average-case algorithm and turn it into a hybrid with something like mergesort to also get O(n log n) worst-case.
    If I remember correctly, introsort is precisely such a hybrid, being a variant of quick sort that switches to heap sort if a possible worst case is detected.

    I have code with several stages including a sort operation, none of the others being worse than O(n log n) worst-case, and if I can't count on the sorting to be the same, it throws a wrench into the works.
    I suppose there is the option of make_heap() followed by sort_heap(), if you really want to guarantee average and worst case of O(n log n) regardless of whether there is sufficient additional memory.

    Stroustrup does say that stable_sort() is supposed to be O(n log n) worst-case (with sufficient memory) - do you know if the current standard guarantees that?
    Yes, but then merge sort is the obvious choice for stable_sort()
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advice for learning C without a teacher
    By tvsinesperanto in forum C Programming
    Replies: 10
    Last Post: 03-16-2006, 03:05 PM
  2. cpp help, not even the teacher can figure this out!
    By Kynan_BeetleBug in forum C++ Programming
    Replies: 4
    Last Post: 01-16-2003, 02:06 AM
  3. Half life Problem which I am right and the teacher is wrong
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 11-06-2002, 03:28 PM
  4. card shuffling dealing question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2002, 07:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21