Question

Describe an algorithm that, given a set S of n integers and another integer x, determines...

Describe an algorithm that, given a set S of n integers and another integer x, determines whether or not there exist two elements in S whose sum is exactly x. Your algorithm must be nlogn. Evaluate how long each step in the algorithm takes to demonstrate that it meets this requirement.

Homework Answers

Answer #1

sort in worst case take O(nlogn)

iterative an take O(n) and searching element in array take O(logn) time
O(n)*O(logn)=O(nlogn)
T(overall)=2*(time for sorting) +time for finding and searching

T(overall)=2*O(nlogn)+O(nlogn)

T(overall)=3*O(nlogn)

T(overall)=O(nlogn)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Algorithm problem 2 [2.3-7] Describe a Θ(nlgn) algorithm that, given a set S of n integers...
Algorithm problem 2 [2.3-7] Describe a Θ(nlgn) algorithm that, given a set S of n integers and another integer ,determines whether or not there exist two elements in S whose sum is exactly x.
Describe an algorithm that takes as input a list of n integers and finds the location...
Describe an algorithm that takes as input a list of n integers and finds the location of the first even integer or returns -1 if there is no even integer in the list. Here is the operation's header: procedure locationOfFirstEven(a1, a2, a3, ..., an : integers)
a. Find an algorithm for solving the following problem: Given a positive integer n, find the...
a. Find an algorithm for solving the following problem: Given a positive integer n, find the list of positive integers whose product is the largest among all the lists of positive integers whose sum is n. For example, if n is 4, the desired list is 2, 2 because 2 × 2 is larger than 1 × 1 × 1 × 1, 2 × 1 × 1, and 3 × 1. If n is 5, the desired list is 2,...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
1. Use the roster method to describe the elements of the following set. x∈ℤ||x−3|<12 and x...
1. Use the roster method to describe the elements of the following set. x∈ℤ||x−3|<12 and x is a multiple of 3 2. Use the roster method to describe the elements of the following set. {n∈ℕ∣∣∣1n+6⩾6272 and n is a multiple of 5} 3. Determine the cardinality of the following sets. {x∈ℤ|−4⩽x⩽3}: {x∈ℕ|−4⩽x⩽3}: 4. Evaluate the following expressions. [Hint: start by factoring the polynomial.] ∣∣{x∈ℚ∣∣18x3+69x2+56x=0}∣∣= ∣∣{x∈(0,∞)∣∣18x3+69x2+56x=0}∣∣= ∣∣{x∈ℤ∣∣18x3+69x2+56x=0}∣∣= 5.  Evaluate the following expressions. [Hint: start by factoring the polynomial.] ∣∣{x∈ℝ∣∣x4+11x2+28=0}∣∣= ∣∣{x∈ℚ∣∣x4+11x2+28=0}∣∣= ∣∣{x∈ℕ∣∣x4+11x2+28=0}∣∣= 6....
Problem Definition: Problem: Given an array of integers find all pairs of integers, a and b,...
Problem Definition: Problem: Given an array of integers find all pairs of integers, a and b, where a – b is equal to a given number. For example, consider the following array and suppose we want to find all pairs of integers a and b where a – b = 3 A = [10, 4, 6, 16, 1, 6, 12, 13] Then your method should return the following pairs: 4, 1 15, 12 13, 10 A poor solution: There are...
One way to represent a very large integer (one that won't fit into a variable of...
One way to represent a very large integer (one that won't fit into a variable of type short, int, or even long) is to use an array. The array is of type int, so each element in the array can hold an integer -- we will store just one digit of our number per array element. So if a user entered 2375, it might be stored as -------------------------- | 2 | 3 | 7 | 5 | ... | --------------------------...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class Zillion implements a decimal counter that allows numbers with an effectively infinite number of digits. Of course the number of digits isn’t really infinite, since it is bounded by the amount of memory in your computer, but it can be very large. 1. Examples. Here are some examples of how your class Zillion must work. I’ll first create an instance of Zillion. The string...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
1) Describe an example of each of the following that may be found of your kitchen:...
1) Describe an example of each of the following that may be found of your kitchen: Explain how your choice falls into this category, and if there is a chemical name or symbol for it, provide that as well. Provide a photo of your example with your ID card in it. a) a compound b) a heterogeneous mixture c) an element (symbol) Moving to the Caves… Lechuguilla Caves specifically. Check out this picture of crystals of gypsum left behind in...