write a python function using a heap with two input parameters, an array of integers ~a~ of ~n~ elements and an integer ~k~ returning an array containing the largest ~k~ elements of ~a~. Do it in O(n log k).
Added by Terri B.
Step 1
First, we need to create a heap of size k. Show more…
Show all steps
Your feedback will help us improve your experience
Ravindra Yadav and 71 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
in Python - Write a program that reads a list of integers into a list as long as the integers are greater than zero, then outputs the smallest and largest integers in the list.
Vandit T.
Write a program in Python that reads a list of integers into a list as long as the integers are greater than zero, then outputs the smallest and largest integers in the list. Ex: If the input is: 10 5 3 21 2 -6 the output is: 2 21 You can assume that the list of integers will have at least 2 values.
Nicole S.
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Willis J.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD