Question

Algorithm

Humble Numbers

Problem 4-1 (Humble Numbers) 10 points A number k > 1 is called humble if the only prime factors of k are 3 and 5. Consider t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(a) Let us argue about (1), the only value program output is the value of cur, which gets its value from the step cur = HEAP.EXTRACTMIN, this means minimum number present in the heap is extracted. We can also notice that after extracting the minimum number from the heap, multiples of the number are inserted into the heap, which means no number smaller than the cur is inserted into the heap, which means numbers that will be extracted in the future will be greater than the cur. Hence, the algorithm outputs numbers in increasing order.

(2) the algorithm outputs the number only if cur != prevOutput. as we know from (1) that algorithm output number in increasing order, which means two equal numbers can occur only one after another. if so happens, cur!=prevOutput will prevent it from giving output. Hence, the algorithm will never output the same number twice.

(3) algorithm only output numbers extracted from the heap. in which, only multiples of 3 and 5 are inserted. So, heap contains only humble numbers. Hence, the output will also be humble numbers

(4) Algorithm inserts initially 3 and 5. After that, it inserts the next possible number whose prime factors are 3 and 5. every combination of multiplication of 3 and 5 are covered in the heap. Moreover, it outputs numbers in increasing order without repeating as proved above. Moreover, the loop is conditioned to run until n humble numbers are outputted. So, it will output all the first n humble numbers.

(b) Initially, HEAP.INSERT in called 2 times and after that, it is called for every increment in the value of count until it reaches n. So, total calls of HEAP.INSERT = 2 + n*2 = 2(n+1)

(c) We can observe from the algorithm, for every 2 HEAP.INSERT operation performed, at least 1 HEAP.EXTRACTMIN is called, except for the first 2 inserts. So, a minimum of N HEAP.INSERT will be called.

(d) A HEAP.EXTRACTMIN takes constant time while a HEAP.INSERT takes O(logn) time. from (b) and (c), total time taken by algo will be = n*1 + 2(n+1)*O(logn) = O(nlogn)

Add a comment
Know the answer?
Add Answer to:
Algorithm Humble Numbers Problem 4-1 (Humble Numbers) 10 points A number k > 1 is called...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Sieve of Eratosthenes is a simple, ancient algorithm for finding all prime numbers up to...

    The Sieve of Eratosthenes is a simple, ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking as composite lie., not prime) the multiples of each prime, starting with the multiples of 2 The sieve of Eratosthenes can be expressed in pseudocode, as follows: Input: an integer n Let A be an array of 8oo1ean values, indexed by integers 2 to n, initially all set to true. for t - 2, 3,...

  • Write a C program which computes the count of the prime and perfect numbers within a...

    Write a C program which computes the count of the prime and perfect numbers within a given limit Land U, representing the lower and upper limit respectively. Prime numbers are numbers that have only 2 factors: 1 and themselves (1 is not prime). An integer number is said to be perfect number if its factors, including 1 (but not the number itself), sum to the number. Sample Inputi: 1 100 Sample Outputs: Prime: 25 Perfect: 2 Sample Input2: 101 10000...

  • Write a function called isPrime.m. This function is used to check whether a given number is...

    Write a function called isPrime.m. This function is used to check whether a given number is a prime number or not. The output shows 1 for prime number and 0 for non-prime number. Example: isPrime(5)       return 1 isPrime(10)   return 0 Then write a function called checkPrime.m, to check an arrays to show how many prime numbers in this array. Example: checkPrime([1,4,5,6,4,7,9,25]) >> count = checkPrime([1,4,5,6,4,7,9,25]) count =             3.00

  • Problem 1: Implement an algorithm to generate prime numbers. You will need to implement the following...

    Problem 1: Implement an algorithm to generate prime numbers. You will need to implement the following ingredients (some of them you developed for earlier assignments): 1. A method to generate random binary numbers with n-digits (hint: for the most significant digit, you have no choice, it will be 1; similarly, for the least significant digit there is no choice, it will have to be 1; for all other position, generate 0 or 1 at random) 2. A method to compute...

  • problem 2 can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to...

    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...

  • 10. Consider the Traveling Salesperson problem (a) Write the brute-force algorithm for this proble that considers...

    10. Consider the Traveling Salesperson problem (a) Write the brute-force algorithm for this proble that considers (b) Implement the algorithm and use it to solve instances of size 6, 7, (c) Compare the performance of this algorithm to that of Algorithm all possible tours 8, 9, 10, 15, and 20 6.3 using the instances developed in (b) Algorithm 6.3 The Best-First Search with Branch-and-Bound Pruning Algorithm for the Traveling Salesperson problem Problem: Determine an optimal tour in a weighted, directed...

  • Modify the algorithm to solve the problem of finding the k-th largest number in array A

    Modify the algorithm to solve the problem of finding the k-th largest number in array A, 1≤k≤n, without sorting the entire array. Partsof the algorithm are given below. Fill in the blanks.                 Select-k-th-largest(A: Array [1..n] of numbers)                 1               for _____________________                 2                                 ________________                 3                                 for _____________________                 4                                                   if _______________ then ___________                 5                                 if position ≠ i then                 6                                                   temp=A[i]                 7                                                   A[i]=A[position]                 8                                                   A[position]=temp

  • 4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up t...

    4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up to n, anda number num which we wish to insert into A, in the proper sorted position. The function Search finds the minimum index i such that num should be inserted into Ali]. It searches the array sequentially until it finds the location i. Another function MakeRoom moves A[i], .., AIn] to Ali+1]...AIn+1] same sort...

  • for matlab programming beginner level Q1) Write an algorithm for finding the prime numbers between 1...

    for matlab programming beginner level Q1) Write an algorithm for finding the prime numbers between 1 and 100 and displaying them. As you know; prime numbers are the ones that can only be divided by 1 and themselves, Example: 5 is a prime number. Write your algorithm in pseudocode and as flowchart. I

  • pleas answer asap 3. (20 points) Algorithm Analysis and Recurrence There is a mystery function called Mystery(n) and the pseudocode of the algorithm own as below. Assume that n 3* for some positiv...

    pleas answer asap 3. (20 points) Algorithm Analysis and Recurrence There is a mystery function called Mystery(n) and the pseudocode of the algorithm own as below. Assume that n 3* for some positive integer k21. Mystery (n) if n<4 3 for i1 to 9 5 for i-1 to n 2 return 1 Mystery (n/3) Print "hello" 6 (1) (5 points) Please analyze the worst-case asymptotic execution time of this algorithm. Express the execution time as a function of the input...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT