Thread: some suggestions to speed up code

  1. #16
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,339
    Or, perhaps I should say

    Quantify "bad"
    Mainframe assembler programmer by trade. C coder when I can.

  2. #17
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    bad here means that it's slow!

  3. #18
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    That's still vague.
    =========================================
    Everytime you segfault, you murder some part of the world

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,401
    It's not a dictionary.. so first I read a I read a list of words and put it into some data structure
    secondly I read a different file, which is also a list of words and then compare that words to see if any matches the word in the first file if it does then I copy that word to a data structure.. thirdly I would iterate through previous data structure and put the list of the words in a new data structure so that the list of the words would be sorted.. that's all I need to do basically

    so what is the most efficient and fast way to do this? what data structure should I use the first time, second time, and third time?
    You could read the two lists of words into two dynamic arrays, sort them, and then do a single pass through each of them simultaneously to find the words in the second list that appear in the first list. Since the resulting list is sorted, another dynamic array will do, assuming you do not intend to frequently insert elements to the middle of it.

    Alternatively, just sort the first list, and then use binary search on it. However, the resulting list would then not be sorted, so you would have to sort it.

    Of course, the point that people are making is that if your lists of words are sufficiently small, doing all this sorting would not help, and would merely be wasted effort.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    I am thinking of storing the first file in a hash table first...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-21-2006, 07:52 AM
  2. Flight Simulator Wind Speed!!
    By Dilmerv in forum C++ Programming
    Replies: 6
    Last Post: 03-20-2006, 12:40 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:33 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM