Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My code is not working. :( I was trying to make a heap that would help me get the top logn flyers. Algorithm HAS to

My code is not working. :( I was trying to make a heap that would help me get the top logn flyers. Algorithm HAS to be in O(n) time.

Please help in fixing the errors & proving that run time is O(n).

-----------------------------------------------------------------------------------------------

package A3;

import java.util.Scanner; import java.util.PriorityQueue; import java.util.Collections;

public class TamarindoAirlines { private static PriorityQueue Heap = new PriorityQueue<>(); public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter the number of flyers: "); int n = scan.nextInt(); int [] array = new int[n]; for (int i = 0; i < n; i++) { System.out.print("Enter the number of miles flown by flyer #"+ (i+1) + ": "); float miles = scan.nextInt(); array[i] = (int) (1/miles); } scan.close(); calcTopFlyers(array, n); } public static int[] calcTopFlyers(int[] array, int n) { int [] B = new int[n]; for (int i = 0; i < Math.log10(n); i++) { B[i] = Heap.remove(); } return B; }

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

Step: 3

blur-text-image

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

3.1 Describe the three characteristics of clear verbal messages.

Answered: 1 week ago

Question

Identify cultural barriers to communication.

Answered: 1 week ago