Homework 2 Solution

$35.00 $30.80

Description

READ Chapters 3 and 4 of “grokking algorithms” – try all exercises, but

do NOT turn in!

 

 

 

READ news story at https://metro.co.uk/2019/10/23/hitman-hires-hitman-hires-hitman-hires-hitman-hires-hitman-tells-police-10971438/

 

and hand-write as recursive algorithm (pseudocode) – assume ½ value reduction at each step. Don’t forget the base case where you report to police – how do you know who to report? Do NOT turn in!

 

 

 

 

 

 

 

 

Homework

 

 

Do not Google for a solution and copy it – if you need to watch a video or look at another solution, then do that…close it…and then program it yourself. It is important to try, to make mistakes, and then debug them.

 

 

#1 Program Merge Sort and test on array of 50 random integers.

 

  • You can limit the range of integers to numbers 0 to 99, if you wish.

 

  • Write the code so that you can easily change “50” to some other number (hint: use a #define macro).

 

  • Your program should do something reasonable on unlikely boundary cases (such as array of size 1, array of size 2, … ).

 

 

 

 

 

 

Sample output

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Homework

 

#2 Hand simulate a preorder, inorder, postorder traversal of this tree – write down the node values “processed” in each. Just turn in a pdf with the three results.

 

                            A                            
                                                         
                                                         
            B                               C            
                                                         
                                                         
    D               E               F               G    
                                                         
                                                         
H       I       J       K       L       M       N       O
                                                         

 

 

 

 

P Q   R S   T U V W X Y Z

 

 

 

 

Homework

 

 

Please upload to Canvas your C program and screen shot of you executing the program.

 

 

For this homework assignment, you may (if you choose) work in teams of 2.

 

 

Each student is expected to work WITH the other student while writing and testing (via ZOOM or whatever collaboration tool you like). Do not split the task between the two of you.

 

 

Each student should upload the program/screen shot + pdf of the tree traversal results

 

 

The comment at the top of the program should say if it was done by a team and who the two members of the team were (so that the TAs do not have to grade the same homework twice).