Create a second empty queue q2

Assignment Help Data Structure & Algorithms
Reference no: EM132087306

Here is the assignment:

You are going to create a Queue. (alternately you can create a list and simply implement enqueue and dequeue functions in the List - that will technically make it a queue).

You will fill the first list with numbers consecutively numbered from 2 to n where n is entered by the user (we will call this Q1).

When creating your Queue object use the correct function names for enqueue and dequeue functions. Again - sorry, cannot use an Javascript array in your implementation - you need to implement enqueue and dequeue.

Create a second empty Queue Q2.

Once you have the first Queue filled we are going to use a technique called Sieve of Eratosthenes which uses first queue to fill the second queue.

Here is the algorithm;

1. Dequeue 1st element in Q1 (which will be 2). You will need to remember the value of this element - we will call it X.

2. Enqueue this element into Q2 (Q2 is the list of primes)

3. Iterate and Dequeue each successive element of Q1

If the value is divisible by X, go to the next element

if the value is not divisible by X enqueue back onto Q1, go to the next element.

4. Print the values of Q1 and Q2 after each time through.

5. When done go back to the beginning of the Q1 and repeat steps 1-3 (the first value will be 3 the second time around

Reference no: EM132087306

Questions Cloud

What is the average density of the mixture : How van I find the average density of the mixture; then 40 cm3 of gasoline are mixed with 50 cm3 of water. What is the average density of the mixture?
Setting pco2 to an absurdly high value : Setting pCO2 to an absurdly high value of 10,000 ppm, you will see a spike in the CO2 absorption band.
What are the benefits of using encryption : What implications would follow from not using cryptological technologies? Why might vendors propose proprietary encryption methods?
Calculate the equilibrium pressures of all species : If pure phosgene at an initial pressure of 1.0 atmosphere decomposes, calculate the equilibrium pressures of all species.
Create a second empty queue q2 : Once you have the first Queue filled we are going to use a technique called Sieve of Eratosthenes which uses first queue to fill the second queue.
Calculate the energy : Afterwards he feels guilty and decides to work off the excess calories by walking up 6 flights of stairs 3 times. Calculate the energy.
What is the overall structure of a dna molecule : What is the overall structure of a DNA molecule What is chemistry
Why do you the organization choose to use virtual desktop : Why do you the organization choose to use virtual desktop it's users?
The process of migrating to a newer enterprise resource : Your organization is in the process of migrating to a newer enterprise resource planning application.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Karatsuba''s divide-and-conquer algorithm

In class we discussed Karatsuba's divide-and-conquer algorithm for integer multiplication, which multiplies n-bit numbers by recursively multiplying n bit numbers. We take two numbers X and Y and split them each into their most significant half a..

  Explain algorithm from is optimal by proving lower bound

Illustrate that your algorithm from (a) is optimal by proving lower bound of n - k on number of comparisons required to solve the problem.

  Designing a string-checking algorithm

Provide an example of an input string that is in the proper format and an example that is not in the proper format. Describe how your algorithm determines that the first string is in the proper format and that the second string is not in proper fo..

  Show the result of deleting numbers from the splay tree

Show the result of deleting 3 from the splay tree shown in Exercise for both the bottom-up and top-down versions.

  Implementing the banker algorithm

Prompt user to enter the size of matrix n and m. Your program should accept any n x m matrix and m vectors where n and m are positive integer less than ten.

  Implement the quick select algorithm

Implement the Quick-Select Algorithm. To choose a pivot point, Pivot = median Then move pivot to the last element. Ideal number to sort. 8,1,4,9,6,3,5,2,7,0

  Why does not serialization save value of static variables

1) Why doesn't serialization save the value of static variables? 2) What are the advantages and disadvantags of serialization? 3) What things are required for a class that implements Serializable?

  Give algorithm to find schedule to obtain maximum profit

Give an algorithm to find the schedule that obtains the maximum amount of profit, assuming that all processing times are integers between 1 and n.

  Investigate algorithms used to exchange routing information

In an internet, routers periodically exchange information from their routing tables, making it possible for a new router to appear and begin routing packets.

  Describe ambiguity in proposed algorithm

Describe the distinction between an ambiguity in a proposed algorithm and an ambiguity in the representation of an algorithm. Describe how the use of primitives helps remove ambiguities in an algorithm's representation.

  What is the time complexity of running quicksort

Consider your textbook's implementation of quicksort from chapter 8. The corrected findPartition method is included below for your convenience.

  Calculating an arithmetic mean, median and mode

Calculate an arithmetic mean, median, and mode for up to fifty test scores. The information are contained in a text file. To determine the median, first sort the array.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd