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.
Maximal matching for a given graph can be found by the simple greedy algorithn below:
Maximal Matching(G, V, E)
1. M = φ
2.While(no more edges can be added)
2.1 Select an edge,e,which does not have any vertex in common with edges in M
2.2 M = M ∪ e
3. return M
Algorithm 2: Algorithm Maximum Matching
Input : A graph G = (V, E).
Output: A matching M of G.
M = {e} for some e ∈ E(G);
while there is an M-augmenting path in G do
Find an M-augmenting path P of G;
M = (M \ E(P)) ∪ (E(P) \ M);
Output(M);
In all algorithms, always prove why they work. ALWAYS, analyze the complexity of your algorithms....
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...
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.
8. In plain English, explain how Mergesort, and QuickSort algorithms work and give your reasons why QuickSort is considered to be the fastest algorithm in practice even so the Mergesort runs always as Θ(MogN) and Quicksort as θ(NlogN) only on average while for some inputs can run as long as o(N-)? 9. On simple examples, explain how quadratic probing works and why it can fail if a hash table is over half full. 8. In plain English, explain how Mergesort,...
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...
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.
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:...
The zigzag sorting problem takes an array data of size n and outputs a per- mutation where data[1] <data[2] > data[3] = data[4] > data[5] S..., all the way to the end of the array. (In general data[i] = data[i+1] if i is odd and data[i] > data[i+1] if i is even.) Answer the following questions about developing algorithms for the zigzag sorting problem. 1. Give pseudocode for a brute force algorithm for zigzag sorting. Your pseudocode just needs to...
Question 4 (10 marks) When analysing the complexity of algorithms, there are three main approaches: worst case, best case and average case. As an example, consider measuring the complexity of list-merging by counting the number of comparisons used As a test example, assume the following A1: There are two ordered lists, each of length 4, say A2: Neither list contains repeats, so a! < a2 < аз < a4 and bl <b2 < b3 < b4 A3: The lists are...
Task Algorithms: Pattern Matching (in java) Write a program that gets two strings from user, size and pattern, and checks if pattern exists inside size, if it exists then program returns index of first character of pattern inside size, otherwise it returns -1. The method should not use built-in methods such as indexOf , find, etc. Only charAt and length are allowed to use. Analyze the time complexity of your algorithm. Your solution is not allowed to be> = O...