Write a new method called removeDuplicates( int[ ] A ) that removes all duplicate elements in an array A of N items. Return the number of items that remain in A. Your method must run in O(N log N) average time. Use quicksort as a pre- processing step.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Can i get help with this question, java language please

1 class QuicksortTester
2 {
3
4 /**
5 * Quicksort algorithm (driver)
6 */
7
8 public void quicksort( int [ ] a )
9 {
10 quicksort( a, 0, a.length - 1 );
11 }
12
13 /**
14 * Internal quicksort method that makes recursive calls.
15 * Uses median-of-three partitioning and a cut-off.
16 */
17
public void quicksort( int [ ] a, int low, int high )
19 {
20 if( low + CUTOFF > high )
21 insertionSort( a );
22 else
23 { // Sort low, middle, high
24 int middle = ( low + high ) / 2;
25 if( a[ middle ].compareTo( a[ low ] ) < 0 )
26 swapReferences( a, low, middle );
27 if( a[ high ].compareTo( a[ low ] ) < 0 )
28 swapReferences( a, low, high );
29 if( a[ high ].compareTo( a[ middle ] ) < 0 )
30 swapReferences( a, middle, high );
31
32 // Place pivot at position high - 1
33 swapReferences( a, middle, high - 1 );
34 int pivot = a[ high - 1 ];
35
36 // Begin partitioning
37 int i, j;
38 for( i = low, j = high - 1; ; )
39 {
40 while( a[ ++i ].compareTo( pivot ) < 0 )
41 ;
42 while( pivot.compareTo( a[ --j ] ) < 0 )
43 ;
44 if( i >= j )
45 break;
46 swapReferences( a, i, j );
47 }
48
49 // Restore pivot
50 swapReferences( a, i, high - 1 );
51
52 quicksort( a, low, i - 1 ); // Sort small elements
53 quicksort( a, i + 1, high ); // Sort large elements
54 }
55 }
56
57
58 // insert code here for question 5
59

5. Write a new method called removeDuplicates ( int [ ] A ) that removes all
duplicate elements in an array A of N items. Return the number of items that remain
in A. Your method must run in O(N log N) average time. Use quicksort as a pre-
processing step.
Transcribed Image Text:5. Write a new method called removeDuplicates ( int [ ] A ) that removes all duplicate elements in an array A of N items. Return the number of items that remain in A. Your method must run in O(N log N) average time. Use quicksort as a pre- processing step.
Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY