Home/Review | Tech Talk Notes | AP Test Prep | FRQ Code |
Chenxin Individual Work (Tri 3)
Replit Link
Showcases my replit work from Tech Talks and projects assigned by OO
Table of Contents
Week 4 (Cross-over Partner)
Final Review Ticket
Challenge was to create a data structure in cross-over partner’s repository, linked here
POJO Data Structure: Stands for Plain Old Java Object, which is just a class with constructor and methods. Created a Gravity.java POJO that calculates and returns the force of gravity between Earth and a (user-inputted) planet in our solar system.
**Show runtime: **
Week 3 (Sort algorithms)
Week 3 Review Ticket
Bubble Sort (in BubbleSort.java): Compares adjacent elements and swaps them if they are in the wrong number. Since the code uses two for loops that iterates through the list, big o notation for the worst case scenario would be O(n * n) = O(n^2).
- Average Compare: 366800
- Average Swap: 183895
- Average Time (nanoseconds): 1517102
Selection Sort (in SelectSort.java): Splits the list into a sorted array and unsorted array. Each time we iterate through the unsorted array, we find the minimum value and add it to the sorted array. Since in the worst case scenario the code iterates through the array n times (once again two for loops), big o notation is O(n * n) = O(n^2).
- Average Compare: 366691
- Average Swap: 855
- Average Time: 674975
Insertion Sort (in InsertSort.java): Iterates through each element and compares it to the previous values until it is no longer smaller than the previous value. Since in the worst case scenario we iterate through the array n times, big o notation is also O(n * n) = O(n^2).
- Average Compare: 185624
- Average Swap: 184766
- Average Time: 581523
Merge Sort (in MergeSort.java): Recursively splits the array in two until each array contains one value, then compare and combine the smaller lists together until entire sorted list is recreated. Since the array is first divided then sorted, merge sort is a combination of binary and linear search, so big o notation for the worst case scenario is O(n * log n)
- Average Compare: 7284
- Average Swap: 7284
- Average Time: 127009
Analytics: By comparing the compare count, swap count, and time, merge sort is the best algorithm for large data sets because it has the lowest average for all of these statistics. Additionally, as shown by the graph, its big o notation of O(n * log n) is smaller than O(n^2) that the other algorithms have
Week 2 (Calculator function)
Week 2 Review Ticket
Challenge 1 (in Calculator.java): Code rpnToResult method to calculate expression from Reverse Polish Notation
Used for loop to iterate through rpn, and used if loops to perform operation on the top two entries in stack, then pushed answer back into stack. Only one entry would remain at the end of for loop, which was the final result.
Challenge 2 (also in Calculator.java): Code for a Power (^) operator. Power operator had more precedence than other operators
Also had to edit tokensToReversePolishNotation and rpnToResult method to include power operator
Week 1 (Stacks & Queues)
Week 1 Review Ticket
Challenge 1 (in Queue.java): Wrote the delete method for queue by setting new head and connecting tail as node
Difficulty printing out the queues so I changed addList and coded deleteList in QueueManager
Challenge 2 (in Merge.java): Created merge method to combine and sort two queues
Difficulty merging the entire queue because next() method of QueueIterator skipped over data
Challenge 3 (in Stack.java): Created stack class that follows the last in first out principle with methods push and pop
Difficulty testing the stack to reverse a queue (didn’t finish in time)
Week 0 (Data Structures)
Week 0 Review Ticket
Challenge 1 (in Main.java): Used Hashmap data structure in order to dynamically create and store options
Used try and catch method in order to print “Please enter a number listed in the menu.” instead of causing error if the input isn’t in the menu.
Challenge 2 (in IntByReference.java): Java can only call by value for parameters in a method, but variable “value” can be changed since the method is called within the object a. For object b, parameter “what” has to be updated using a method in order to change the reference.
toString() method returns the integer variable “value” as a String.
Challenge 3 (in Matrix.java): toString() method iterates over the 2d array using enhanced for loops in order to return the 2d array as a String