Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Help: RULES: You may not import any extra functionality besides the default. For example, System and Math are imported by default and thus may

JAVA Help:

RULES:

  1. You may not import any extra functionality besides the default. For example, System and Math are imported by default and thus may be used, whereas something like ArrayList must be explicitly imported so it is disallowed.
  2. You may not use any built-in functionality for copying an array, like System.arrayCopy(), Arrays.copyOf(), Object.clone(), Arrays.stream, etc. If you want to copy an array, you should do it manually (i.e. create a new array and transfer the data).

1st Problem-

Create the following method that, given an array of integers and a cardinal number, k, finds the kth smallest number in the array. You are not allowed to call any sorting functionality. Remember, a cardinal number starts with one; for the smallest value, k=1. Assume, there are enough items in the array to find the kth value.

public static int smallest(int[] arr, int k)

Examples:

smallest({1,1,1,3,3,4,5,5,5}, 5) --> 3

2nd Problem-

Create the following method that, given an array, it pushes all evens to the beginning and all odds to the end of the array; order between evens is preserved, and order between odds is preserved. So, modification happens in-place and the return type is void.

public static void partition(int[] arr)

Examples:

partition({10,9,8,7,6,5,4}) --> {10, 8, 6, 4, 9, 7, 5} partition({4,7,6,2,10,9,101,3}) --> {4, 6, 2, 10, 7, 9, 101, 3}

Please help with these 2 problems. Comments in code will be very appreciated. Thank You! :)

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

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

What is the purpose of a competitor analysis?

Answered: 1 week ago

Question

1. How is the newspaper help to our daily life?

Answered: 1 week ago

Question

1. Prepare a short profile of Mikhail Zoshchenko ?

Answered: 1 week ago

Question

What is psychology disorder?

Answered: 1 week ago