Binary Search Trees: Remove; QuickSort

Individual Post-Class Exercises

NOTE Because this is the very last lesson, this Lesson may be due on an unusual day and/or an unusual time.
Please check the main page for the due date for this Lesson.
 
  1. Lesson Setup

    1. Start-of-lecture Slides   (Required)

    2. Final Exam: Q+A & Review

    3. 'Starter' project for the lesson 09 PCEs (VS 2015/2017)
      This is the combined starter project for both BST-Remove and QuickSort.  Please let the instructor know ASAP if you find anything wrong
      Note: Please do copy code from your prior lessons and paste it into this lesson, whenever you can reuse useful code.
      NOTE: This project/Solution DOES include NUnit tests - you'll need to get the tests to pass for this lesson
    4. Please use this link to access the repo with the 'Starter' project for lesson 09 PCEs (VS 2017/2019)
      This is the combined starter project for both BST-Remove and QuickSort.  Please let the instructor know ASAP if you find anything wrong

      Note: Please do copy code from your prior lessons and paste it into this lesson, whenever you can reuse useful code.
      NOTE: This project/Solution DOES include NUnit tests - you'll need to get the tests to pass for this lesson
    5. Watch the online videos for this lesson and demonstrate your knowledge (Hand-In)
      You can download a .ZIP of all the videos for this lesson from Microsoft's OneDrive website by opening the folder (click this link to open the folder), then clicking on the "Download" menu item.
       
      1. Starter File for outlining this lesson's videos

      2. Viewing Quiz

  2. BST: Remove

    1. VIDEO: (These are two links to the exact same video - you can watch either one, depending on which one(s) is available)
      (You only have to watch this once)
      OneDrive: BST - Remove (Concepts)
      DropBox: BST - Remove (Concepts)
    2. VIDEO: (These, and all the other videos on this page are also two links to the same file, in case one of them is down.)
      OneDrive: BST: Remove By Hand Exercise
      DropBox:BST: Remove By Hand Exercise  
    3. Exercise: BST: Remove By Hand (Hand In)
    4. VIDEO:
      OneDrive: BST: Remove (Overview)
      DropBox: BST: Remove (Overview)  
    5. Exercise: BST: Remove preview
    6. Exercise: BST: FindAndRemoveNextSmaller (in C#) (Hand-In)
    7. Exercise: BST: Remove (coded in C#) (Hand-In)
  3. Understanding QuickSort

    1. VIDEO:
      OneDrive: QuickSort Algorithm
      DropBox: QuickSort Algorithm
       
      1. QuickSort SlideShow (this are the same slides used in the above video)
    2. Exercise: Demonstrating Only The Partition Method Step By Step, By Hand (Not Required, But It Will Be On The Final Exam)
      (NOTE: This is a Word file, so you can easily print it)
    3. Exercise: Demonstrating The Entire QuickSort By Hand (Not Required, But It Will Be On The Final Exam)
      Example solution for this 'by hand' exercise
    4. For a fun, visual demonstration of different sorting algorithms:
      https://www.toptal.com/developers/sorting-algorithms
  4. Implementing (Writing Code For) QuickSort

    1. Exercise: Preview: QuickSort
    2. Exercise: QuickSort: Partition (Hand-In)
    3. Exercise: QuickSort: Implementing QuickSort (Hand-In)
    4. VIDEO:
      OneDrive: QuickSort Time / Space
      DropBox: QuickSort Time / Space
    5. VIDEO:
      OneDrive: QuickSort Worst Case
      DropBox:QuickSort Worst Case
  5. Fill Out The CIEs For This Course

    1. Go to  https://cascadia.campuslabs.com/courseeval/
    2. Enter your Cascadia email, username and password
    3. Select the class from the drop down menu
    4. Click on the start evaluation button
    5. Fill out and submit the survey
    6. While the site operates in all browsers, it works more efficiently from Firefox or Chrome
  6. Last Steps

    1. Hand in your work:
      Starting with this lesson you must hand in your work via GitHub.

      1. Don't forget to commit your Viewing Quiz/Video Outline to your repo on GitHub.com
        Since you're handing in all your work through git/GitHub this week you'll need to add your Viewing Quiz/Video Outline to your GitHub repo.
        You can do this through Visual Studio (and then push it) or through GitHub.com directly - as long as it gets handed in either way is fine

      2. Create and commit a file which tells me your name
        Please create a text file in Visual Studio (or NotePad/Text Editor/etc) and please name the file LASTNAME, FIRSTNAME.txt, where LASTNAME is replaced with your last name and FIRSTNAME is replaced with your first name (based on how you registered at Cascadia).
        This will enable me to know who you are even if it's not clear from your GitHub username.

      3. You do NOT need to hand in an INSTRUCTORFEEDBACK.docx file when handing in work via GitHub.
        It doesn't hurt if you do so feel free to do so if you'd like to.
        I'm going to ignore any that are there.

    2. Make sure that you're working on the next homework assignment.
      Details are listed on the
      homework assignment page.
      The due date is listed on the main page.
    3. Practice what you've learned
      Remember that in order to really learn this stuff you're going to need to practice it.  Go back and redo the exercises from this lesson until you've really got it down.  Go back to the prior lesson(s) and review and redo that.  Make sure that you've really got this stuff in your head (and remember that it gets easier each time you redo the work)!
 
In-Class Materials:

These materials are used by students in the hybrid class during leture time.  Online students can safely ignore everything in this 'In Class Materials' box.

In-Class Materials:

Instructor's Materials:

Videos recorded during class (of the In-Class Exercises):

display:none to hide notes

TODO: Use this code to auto-correct student traces:

 

namespace PCE_StarterProject
{
    public class Program
    {
        static public void QSort(int[] A)
        { QSort_private(A, 0, A.Length - 1); }

        static private void QSort_private(int[] A, int left, int right)
        {
            int pivotIndex = Partition(A, left, right);

            if (pivotIndex - 1 > left)
                QSort_private(A, left, pivotIndex - 1);
            if (pivotIndex + 1 < right)
                QSort_private(A, pivotIndex + 1, right);
        }
        static private int Partition(int[] A, int left, int right)
        {
            int pivot = A[left];
            int indexLeft = left;
            int indexRight = right;

            while (indexLeft < indexRight)
            {
                while (A[indexRight] > pivot)
                    indexRight--;

                while (indexLeft < indexRight && A[indexLeft] <= pivot)
                    indexLeft++;

                if (indexLeft < indexRight)
                    Swap(A, indexLeft, indexRight);
            }

            Swap(A, left, indexRight); //swap pivot & right index
            return indexRight; // new location of pivot
        }

        static public void Swap(int[] A, int L, int R)
        {
            int temp = A[L];
            A[L] = A[R];
            A[R] = temp;
            //print here

            for (int i = 0; i < A.Length; i++)
                if( i == L || i == R)
                    Console.Write(" =>" + A[i] + "<= " );
                else if( i != 0)
                    Console.Write("  ," + A[i] + "   ");
                else 
                    Console.Write("   " + A[i] + "   ");
            Console.WriteLine();
        }

        public static void Main(string[] args)
        {    // TOOD: First print the starting array
            int[] nums = { -3, 10, 21, 20, 19, 9, -4, 7 };
            QSort(nums);

            // Use this for any code that you want to
            // put into main, and run as a stand-alone console applicatiion
            //TestTheThings ttt = new TestTheThings();
            //ttt.RunExercise();
        }
    }