1

Merge sort seems somewhat difficult to implement, and honestly I feel like I'm out of my depth whenever I try to work on it. Also, I believe that merge sort would require that I have a better knowledge of pointers (I could be wrong) and I don't know if I know enough to tackle it. I do want to try it, but I also want to know if its doable at all for someone on my skill level, or if I should just try bubble sort, or insertion sort.

Thanks in advance,

0

It's hard to gauge your process/level of programming without seeing any code. However, I do agree that merge sort is harder than the others - it requires a greater understanding of programming.

Based on personal experience, selection sort, insertion sort, or bubble sort are the easiest sorting functions. Here is the pseudocode for each function (based on Week 3 CS50 Shorts), so you can decide for yourself which one is the easiest. Please note that what is "easy" depends on the individual.

Selection sort:

//repeat until no unsorted elements remain:
    //search the unsorted part of data to find the smallest value
    //swap the smallest found value with the first element of the unsorted part

Bubble sort:

//set swap counter to non-zero value
//repeat until the swap counter is 0:
    //reset swap counter to 0
    //look at each adjacent pair
        //if two adjacent elements are not in order, swap them and add one to the swap counter

Insertion sort:

//call the first element of the array "sorted"
//repeat until all elements are "sorted":
    //look at the next unsorted element. Insert into the "sorted" portion by shifting the requisite number of elements

Merge sort:

//sort the left half of the array (assuming n > 1)
//sort the right half of the array (assuming n > 1)
//merge the two halves together

If this answers your question, please hit the checkmark below!

2
  • Thanks for the quick answer, and sorry for not posting any code. I did have some code for merge sort, but it wasn't leading me anywhere so I constantly had to rewrite it. Its disappointing, but all of cs50's definitely been a humble experience. – Mazer Rackham Jan 31 '17 at 3:12
  • No problem! Remember that you can always code another function, continue on in CS50, and then return and attempt merge sort. – SuperNovaCoder Jan 31 '17 at 12:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .