In hashing we will first create hash function and then we will compute hash value for all the elements which involves O(n) complexity and then each element will compare against the hash values if there is only one match for all the elements are distinct and it involves O(n)
total complexity is O(n+n) == O(n)
for brute force algorithm it takes complexity of O(n^n);
for pre-sorting algorithm it takes complexity of O(nlogn);// because it involves sorting and then binary search
thoblerm 1: (25 pts) Explain how the time efficieney of this a to use hashing to...
a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n positive integers and determines whether there are two distinct elements of the list that have as their sum a third element of the list. That is, whether there exists i, j.k such that iヂj, i关k,j关k and ai + aj = ak. The algorithm should loop through all triples of elements of the list checking whether the sum of the first two is the third...
Subject: Algorithm.
solve only part 3 and 4 please.
2.2 Selection- 5 points each 1. Run the simultaneous min-and-max algorithm on the array A 4, 2, 12, 6, 13,9,15). (16, 7, 10, 1,5, 11,3,8, 14, 2. Explain why the above algorithm is better than the naive algorithm for finding minimum and maximum separately. How many comparisons does the naive algorithm do? How many comparisons does the simultaneous min and max do? 3. Use the randomized select algorithm based on partition...
solve 3
that tells how many swaps are done in the worst case given n elements Consider this modification of the partition algorithm. Randomly choose three potential pivots. Partition around the median of the three pivots 3. a) Write the pseudocode for this algorithm b) If this use the quicksort algorithm, what is the running time for the worst-case scenario? When will this happen? c) Why is this algorithm better than the regular quicksort algorithm? 4. Give the pseudocode of...
Question3 10 pts Let A [L.n] be a max-heap with n > 1 and consider the index ị such that l 〈 i 〈 n . Assume that all the elements of A are distinct. Write the pseudocode of an algorithm which replaces A [i] by A i 100 and then re-arranges the elements of A into a max-heap. The running time of your algorithm must be O (log, n Upload Choose a File
Question3 10 pts Let A [L.n]...
problem 2
can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to write its pseudo-code). To sort an array A, you will then call Det-QuickSort(A, 1, n). You also need to provide the worst case time complexity analysis of your algorithm. 2. (20 points) Given a set of n distinct numbers, we wish to find the k largest in sorted order using a comparison-based algorithm. Give an algorithm that implements each of the following methods, and...
the question from the course COMP 4040 that Analysis of
Algorithms
if you want to answer it by code please use C or C++
5. Algorithm Design (20 points) Input: array A contains n distinct numbers from 1 to n, in arbitrary order. Output: number of inversions (defined as the number of pair(i, j) of array indices with i < j and A[i] > Aj]) (a) (5 points) What array with elements from the set {1, 2, ..., n) has...
sets, dictionaties and hasing questions
1: Explain how hashing can provide
constant-time access to a data structure.
2: What causes collisions? Give an example of a
collision.
3: How does the linear method for resolving
collisions work? Use an example to explain.
4: What causes clustering?
5:
6:
What is the load factor for an array of length 30 with 10 items. O 1 0.3 10 30
Exercise 3 (2 pts). Consider the following decision problem: Given a list of integers, deter- mine whether all elements of the list are distinct. Is this problem in P? Yes, no, unknown? Justify your answer (if your answer is "yes", briefly describe a polynomial-time algorith)
1. State and explain the definition of big-O. 2. Explain why we use big-O to compare algorithms. 3. Explain why binary search runs in O(log n) time. 4. Under what conditions is it possible to sort a list in less than O(nlog n) time? 5. List and explain the worst-case and average-case running times for each Vector method below: (a) insert(iterator here, Object item) (b) insertAtHead (c) insertAtTail (aka push back) (d) get(iterator here) (e) get(index i) (f) remove(iterator here)...