Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use java please Lab2 Sorting Problem Description The problem is similar to Exercise2, but you need to sort words instead of numbers. Devise and implement

use java please

image text in transcribedimage text in transcribed

Lab2 Sorting Problem Description The problem is similar to Exercise2, but you need to sort words instead of numbers. Devise and implement an algorithm that sorts words in O(n) complexity, where n is the number of words in the input file (not counting the first word that has special meaning described below). The input file contains words separated by whitespaces. Each word consists of English letters a-z. There are 1,2 , or 3 letters in each word, the same letter can be used multiple times. The first word in the input file is so called maxword. It is some word that is equal to or greater than any other word in the file. Program Assume that you have n arbitrary words in range a..maxword. The words may be repeated. Sort them using the algorithm of O(n) complexity. Also sort them using any other algorithm of your choice. The program has to be case insensitive. For example, letters a and A has to be treated as equal. Sort all words from the input file in alphabetical case insensitive order (for example, a precedes aa, ab, b, ba, and bb). Ignore the letters case and output words in small case only. Write a program does both of the following, for each input file - reads words from input file in_abcX.txt, sorts them using O(n) algorithm, and outputs the sorted words in small letters to output file out_abcXa.txt (where X is 1, 2) - reads words again from the same input file, sorts them using any other algorithm of your choice, and outputs the sorted numbers to output file out Xb.txt The program has to read 2 input files and print the results to corresponding 4 output files. All files have to be processed in one program run. There are two test input files provided - in_abc10.txt and in_abc100.txt. There is also one sample output file corresponding to the first input file - out_abc10_sample.txt (file out_abc100_sample.txt is not provided). Run your program with the test input files. For each input file, two corresponding output files (produced by your program) have to be the same. Also compare the produced output file out_abc10a.txt with the sample file out_abc10_sample.txt. Submit the test input and the produced output files together with the program source code. Hint Replace characters with integers and use algorithm from Exercise2. For example, a is 01, b is 02, etc., and z is 26. For instance, word abc can be encoded as 10203 (may you skip leading zero? why yes or why not?). Word a is 10000 , word aa is 10100 , word z is 260000 , word yz is 252600. To figure out the array size k encode the maxword. For example, if maxword is aaa, then k is 10101. The numbers in these examples can have up to 6 digits. Can you devise other encoding that require only 5 digits? Input File Format The input file contains words separated by whitespaces - the first word is maxword (maximum possible word below) - the follow up words are the words that you need to sort (count these words to figure out n ) For example, Zzz // so maxword is zzz, the deduced k is 262626 ab ijk zdd// so n is 4 In this example, the actual maximum word is zdd that can be calculated after all words are read. But we have to allocate array at the beginning, so we specify maxword ==zzz (and the deduced k is 262626). Example If your input file contains ddd Aa aab Abc cb bcd The output has to be aa aab abc bcd cd

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

The paleolithic age human life, short write up ?

Answered: 1 week ago