mojo666's Profile User Rating: -----

Reputation: 368 Architect
Group:
Expert
Active Posts:
805 (0.39 per day)
Joined:
27-June 09
Profile Views:
12,381
Last Active:
User is offline Yesterday, 03:18 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Mozilla
Favorite Processor:
Who Cares
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0
Expert In:
Computer Science

Latest Visitors

Icon   mojo666 has not set their status

Posts I've Made

  1. In Topic: problem when inserting into binary tree

    Posted 23 Feb 2015

    Here's a couple things I noticed.

    Table insert(Table temp , Key_Type key ) {   
         struct node * nd = malloc(sizeof(tree_ptr));  
         if(temp->head ==NULL) {  
            nd->left = nd->right = NULL;  
            nd->element= key;  
            printf("new node inserted ! \n");  
         }  //You created a node and set the element to the key, but you didn't put the node in the table.
         else {   
            temp = malloc(sizeof (*temp));  
            temp->head = nd;  
            printf(" left or right branch added ! \n");  
         }  //This block of code can only execute if the table has an element.  It will overwrite the head with an empty node.
         return temp;  
    }
    
  2. In Topic: Domino. Need to implement recursion.

    Posted 18 Feb 2015

    Quote

    // I make D and sequence arrays/vectors to be in the starting position again(fill with removed elements).
    // I remove elements until current position in this recursion cycle.
    // Continue loop


    It seems like you are most struggling with how to track dominoes as you remove them from the list and then add them back after recursion. There is no reason to do this in the loop. You start the function by moving a dominoe from D to sequence, so all you need to do is the opposite at the end of the function.

    void makeSequence(Dominoes D, vector<int> sequence, bool rev, int index) {  
    // Remove dominoe from D at given index, and add it to sequence vector
      for(int i = 0; i < D.size(); i++)
      {
    	//rest of code
      }
    // Remove dominoe from end of sequence and insert into D at index
    }
    
    


    This format ensures that D and sequence return to the same state after a recursive call executes.

    Quote

    Is there any way I can shrink it?


    Not really. We may be able to make it a bit "cleaner", but all code that brute forces through the combinations will resemble what you have. If anything, you would want to start working on optimizations that make the algorithm run faster. Such changes will make the code longer.
  3. In Topic: Forbidden Permutations- Generating with Stack

    Posted 3 Feb 2015

    Do you at least understand all the terminology and what is being claimed by the problem? Do you understand how permutations are generated by stacks? "If and only if" statements are usually proven by breaking the problem into 2 parts.

    Part 1: If the permutation contains no forbidden triple, it can be generated.

    Part 2: If a permutation can be generated, it has no forbidden triple.

    I think a proof by contradiction is the way to go with part 2.
  4. In Topic: What Is the Bubblesort?

    Posted 3 Feb 2015

    Quote

    Remember that you are not looking at it through the eyes of a beginner.

    Incorrect. I remember learning bubble sort. The method used was to show us a barebone version similar to Jon's. Once we understood that version, we worked on adding optimizations such as swap check, or shortening the inner loop.

    Quote

    Imagine teaching it to a beginner using playing cards. Is it easier to stop when it's sorted than to keep track of the number of iterations. It would also seem odd to a beginner to keep making passes if the list is already sorted.

    The key to understanding bubble sort is whether or not the beginners understand the "bubbling" that happens on each pass. If they don't, then saying "This sorting algorithm runs until it is sorted" doesn't really add anything of value to the beginners' understanding. If they do, then I would say it is intuitive to repeat n times as the array is clearly sorted after that many loops for the reason you described. The check is more of a clever add on. I would also argue the swap check complicates things for the beginner as it adds more to track. For beginners, doing the same thing more than required is easier than doing multiple things to save time.
  5. In Topic: What Is the Bubblesort?

    Posted 2 Feb 2015

    View PostSkydiver, on 03 February 2015 - 05:33 AM, said:

    View Postcfoley, on 02 February 2015 - 02:28 PM, said:

    Did nobody notice that both the algorithms in the OP are wrong?

    I guess I'm still missing it. I've gone over both variants and I'm not seeing the problem. Can you please give a hint of what is wrong in both implementations?


    Hints:

    A - check variables.

    B - check loop parameters.

    Quote

    Algorithm A:

    1. Compare each pair in turn and swap them if they are the wrong way round.
    2. If you made no swaps, the list is in order and you are finished.
    3. At least the last item you compared is guaranteed to be in the correct position.
    4. Repeat from step 1, skipping the ones at the end of the list in the correct position.

    A loops through the whole list every iteration.

    Quote

    In algorithm B, for an inexperienced programmer/mathematician, it's a leap of faith to believe N times is enough. You can prove it easily enough but it's not intuitive.


    Based on your description, the largest item is in the final position and subsequent iterations will not reach that position. This makes N iterations is intuitively sufficient. If it is not clear then the programmer cannot guarantee any kind of efficiency for algorithm A either.

My Information

Member Title:
D.I.C Addict
Age:
30 years old
Birthday:
July 23, 1984
Gender:
Interests:
Chess, math, computers, AI
Years Programming:
6
Programming Languages:
C++, C#, VB.net, SQL, OCAML, LISP, MIPS

Contact Information

E-mail:
Private
Website URL:
Website URL  http://

Friends

Comments

mojo666 has no profile comments yet. Why not say hello?