Java_Project_6_answers

.docx

School

University of North Georgia, Dahlonega *

*We aren’t endorsed by this school

Course

1302

Subject

Computer Science

Date

Apr 29, 2024

Type

docx

Pages

7

Uploaded by melroyoliver

Report
Java Project 6: Recursion, Searching & Sorting Algorithms (60 points + 10 pts bonus) Submission due date: Sunday 11:59 pm, 4/14/2024 CSCI 1302 Submission includes: 1) The screenshots of the required program and the correct result for Q1 2) The answers for Q2 ~ Q3 Q1 . (10 pts) Write Java program with a recursive method called evenfact( N ) which takes in a number N and returns the factorial of the even numbers between the given number N and 2. For example: evenfact (4) returns 8, because 2*4=8 evenfact (9) returns 384, because 2*4*6*8=384
Q2. (10 pts) Given the sorted list: 2 8 15 38 76 100 138 270 386 To trace the execution for a binary search , searching for the number 270 . Step 1: find index 4, compare 76 and 270, because 76 < 270, pointer moves to left N Right Y. Step 2: find index 6, compare 138 and 270, because 138 < 270, pointer moves to left N Right Y. Step 3: find index 7, compare 270 and 270, because 270 = 270, pointer moves to left N Right N. Result: Number 270 is found at index 7. Q3. (Total 40 pts) Given the following list: 100 15 8 76 138 270 38 To implement the different sort algorithms to sort values from smallest to the biggest. Please fill out each step and find the update list content. If some change happens in the step, please fill the change information, otherwise leave the blank because there is no change. 1) Selection sort (10 pts) Step 1: swap 100 and 8, the list: 8, 15, 100, 76, 138, 270, 38 Step 2: swap 15 and 15, the list: 8, 15, 100, 76, 138, 270, 38 Step 3: swap 100 and 38, the list: 8, 15, 38, 76, 138, 270. 100 Step 4: swap 76 and 76, the list: 8, 15, 38, 76, 138, 270, 100 Step 5: swap 138 and 100, the list: 8, 15, 38, 76, 100, 270, 138
Step 6: swap 270 and 138, the list: 8, 15, 38, 76, 100, 138, 270 2) Insertion sort (10 pts) Step 1: insert 15, the list: 100, 15, 8, 76, 138, 270 Step 2: insert 8, the list: 8, 100, 15, 76, 138, 270, 38 Step 3: insert 76, the list: 8, 100, 15, 76, 138, 270, 38 Step 4: insert 138, the list: 8, 15, 76, 100, 138, 270, 38 Step 5: insert 270, the list: 8, 15, 76, 100, 138, 270, 38 Step 6: insert 38, the list: 8, 15, 38, 76, 100, 138, 270 3) Bubble sort (10 pts) Stage 1: the first iteration Step 1: swap 100 and 15, the list: [15, 100, 8, 76, 138, 270, 38] Step 2: swap 100 and 8, the list: [15, 8, 100, 76, 138, 270, 38] Step 3: swap 100 and 76, the list: [15, 8, 76, 100, 138, 270, 38] Step 4: swap 100 and 138, the list: [15, 8, 76, 100, 138, 270, 38] Step 5: swap 138 and 270, the list: [15, 8, 76, 100, 138, 270, 38] Step 6: swap 270 and 38, the list: [15, 8, 76, 100, 138, 38, 270] After the first iteration, the list is partially sorted as follows: [15, 8, 76, 100, 138, 38, 270]
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help