always explain their correctness and analyze their complexity. The complexity should be as small as possible
Consider the following question. Given a SORTED array and a number z, find if there are two number i != j, so that A[i] + A[j] = z. Give the best algorithm you can for this problem. Explain very precisely your answer.
This method works in O(n) time if
range of numbers is known.
Let sum be the given sum and A[] be the array in which we need to
find pair.
1) Initialize Binary Hash Map M[] = {0, 0, …} 2) Do following for each element A[i] in A[] (a) If M[x - A[i]] is set then print the pair (A[i], x – A[i]) (b) Set M[A[i]]
always explain their correctness and analyze their complexity. The complexity should be as small as possible...
Remarks: In all the algorithms, always explain their correctness and analyze their complexity. The complexity should be as small as possible. A correct algorithm with large complexity, may not get full credit. Say that we are given a rooted tree so that any element in the tree has a profit. An independent set in the tree is a collection of vertices no two of which are a parent and a child. The goal is to find an independent set of...
Design And analysis algorithm course . Remarks: In all the algorithms, always explain their correctness and analyze their com- plexity. The complexity should be as small as possible. A correct algorithm with large complexity, may not get full credit Question 2: Give an algorithm that finds the maximum size subarray (the entries may not be contiguous) that forms an increasing sequence.
Design And analysis algorithm course Remarks: In all the algorithms, always explain their correctness and analyze their com- plexity. The complexity should be as small as possible. A correct algorithm with large complexity, may not get full credit Question 3: Given a gas station with two pumps, and a collection of cars 1, 2, n with filling time si for item i (on both pumps). Find a schedule that assigns cars to the two pumps, so that if the first...
In all algorithms, always prove why they work. ALWAYS, analyze the complexity of your algorithms. In all algorithms, always try to get the fastest possible. A matching M = {ei} is maximal if there is no other matching M' so that M ⊆ M' and M /= M' . Give an algorithm that finds a maximal matching M in polynomial time. The algorithm should be in pseudocode/plain English. Provide the complexity of the algorithm as well.
Remarks: All the graphs here are without self loops and parallel edges, and anti-parallel edges. When we speak of a flow network, we mean there are capacities c(e) ? 0 on the edges, the graph G is directed with a source s and a destination t. In all the algorithms, always explain their correctness and analyze their complexity. The complexity should be as small as possible. A correct algorithm with large complexity, may not get full credit. • Question 3:...
Assume L is an array, length (L) returns the number of records in the array, and qsort \((L, \quad i, j)\) sorts the records of \(L\) from \(i\) to \(j\) (leaving the records sorted in L) using the Quicksort algorithm. What is the average-case complexity for the following code fragment?$$ \begin{array}{c} \text { for }(\mathrm{i}=0 ; \text { i<length }(\mathrm{L}) ; \mathrm{i}++) \\ \text { qsort }(\mathrm{L}, 0, \mathrm{i}) ; \end{array} $$You should provide a formula for computing the total...
In all the answers always explain their correctness (or prove it if necessary) Question 2: Give a deterministic automata for the following languages. The Alphabet Σ = {0, 1} 1. 01". Namely, the strings that start with some number m (it may be that m = 0) of 0 and then some another number n (n may be zero) of 1. 2. The set of all strings with 3 consecutive 0 3. The Language so that every 3 consecutive characters...
Please explain Remarks: In all algorithm, always prove why they work. ALWAYS, analyze the com- plexity of your algorithms. In all algorithms, always try to get the fastest possible. A correct algorithm with slow running time may not get full credit. In all data structures, try to minimize as much as possible the running time of any operation. . Question 4: 1. Say that we are given a mazimum flow in the network. Then the capacity of one of the...
Exercise 7.3.5: Worst-case time complexity - mystery algorithm. The algorithm below makes some changes to an input sequence of numbers. MysteryAlgorithm Input: a1, a2....,an n, the length of the sequence. p, a number Output: ?? i != 1 j:=n While (i < j) While (i <j and a < p) i:= i + 1 End-while While (i <j and a 2 p) j:=j-1 End-while If (i < j), swap a, and a End-while Return( aj, a2,...,an) (a) Describe in English...
(13 pts) Given an array AlI,2,. .. ,n] integers, design and analyze an efficient Divide-and-Conquer algorithm to find some i and j, where j > 1, such that A[j]-Ali] is maximized. For example, given A 6, 1,3,8,4,5, 12,6], the maximum value of AL] - Ali] for j > i is 12-1 11 where j -7 and i 2. Give the underlying recurrence relation for your algorithm and analyze its running time. You should carefully state all details of your algorithm:...