# Hello, I have a java program that sorts a given text file and find t.docx

• No School
• AA 1
• 8

This preview shows page 1 - 4 out of 8 pages.

Subscribe to view the full document.

Hello, I have a java program that sorts a given text file and find the most frequent word using three algorithms selection sort, merge sort and insertion sort. Task 1: Predict the run-time, since it is impossible to run Selection Sort on an 1 Million word txt file (since it would take too long), we can only predict its approximate run-time. Give your estimate of run-time for Selection-Sort on data with 1 million (text file with 1 million words). Task 2: Give the time complexities of these three algorithms (selection, merge, insertion). In particular, give the proof of the complexity of the MergeSort algorithm. That is give the complexities in Big O notation for all 3 algorithms and the proof for the merge sort complexity. Code: import java.io.File; import java.util.Scanner; import java.util.Map.Entry; import java.util.AbstractMap; import java.util.Arrays; import java.util.Comparator; public class WordCountSort { public static void selectionSort(String[] data) { �� int n = data.length; �� ��� for (int i = 0; i < n - 1; i++) { �� ��� int minIndex = i; �� ��� ��� for (int j = i + 1; j < n; j++) { �� ��� ���
if �� ��� ��� ��� (data[minIndex].compareTo(data[j]) < 0) { minIndex = j; �� ��� ��� ��� ��� } �� ��� ��� ��� } �� ��� ��� if (i != minIndex) �� ��� ��� swap(data, minIndex, i); �� ��� ��� ��� } �� ��� } �� public static void insertionSort(String[] data) { �� int n = data.length; �� ��� for (int k = 1; k < n; k++) { �� ��� String cur = data[k]; �� ��� ��� int j = k;

Subscribe to view the full document.

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes