Question

In: Computer Science

Algorithms appear almost everywhere in life. For example, a store clerk uses an algorithm with tasks...

Algorithms appear almost everywhere in life. For example, a store clerk uses an algorithm with tasks such as scanning items, bagging groceries, and accepting your payment. Other algorithms, such as those that make up computer operating systems, are much more complex. In general, the goal of algorithm design is to complete a job in fewer steps. Create your own algorithm to complete a computing task. You can use C++, Java, or Python3 to create your algorithm.

Tips:

  • Remove unwanted comments.
  • Use proper logic.
  • Use fast calculating iterations.
  • Have a clear plan before creating the algorithm.
  • Make it small.
  • Make it efficient.

There are four steps to algorithm methodology. Discuss your algorithm design in relation to these four steps. Describe how you went through each step of the methodology to create your algorithm.

Solutions

Expert Solution

ALGORITHMS can be simply be explained in layman terms as a set of procedures to solve a problem .the approach can vary from a person to person and also dependent on the nature of the problem statement

it generally has 4 steps: design ,analyze,implement,experiment

since you have given me a choice of programming language,i would be using python 3

and the program i would be implementing as an example would be to find if a number is prime number or not.

step1)design

the main goal is to identify what is a prime number.prime is any number which has no other factors except itself and one.such is a requirement to be a prime number.eg. prime numbers=2,3,5,7,11,13,etc

non primes=4,6,8,9,10,etc

step2)analyze

  • so we know what is prime number ,but how to find if any given number is prime or not?we can divide the given number by each number preceding it to check if it a factor of the given number. if it is a factor i would give a remainder as zero during division.
  • subsequently we need to repeat the process to find the factors.
  • we should also remember that 1 is neither prime nor composite and hence can be treated as an exception

step 3)implement

  • so now we can imagine a loop which iteratively checks the numbers and returns a certain output if a certain condition is true.ill be posting the code first and then try to explain it.

def isprime(n):
    flag=0
    if n<=1:
        print("1 or 0 is invalid")
        quit(0)
    for i in range(2,n):
        if n%i==0:
            flag=1
    if flag==1:
        return True
    else:
        return False
print("enter an integer number")
try:
    n=int(input())
except:
    print("please enter a valid input")
    quit(0)
res=isprime(n)
if res==False:
     print(n," is prime")
else:
    print(n,"is not prime")

i also attched a screnshot for your reference

for line by line explanation,please refer to the following screenshot

step4)experiment

  • experiment with diffrent values to test the algorithm
  • try the exception handling techniques
  • try the values with random inputs
  • i have attached a sample output for your reference.i suggest trying it out yourself to understand it better

for more clarification or further simplification of the program,please reach out in the comment section,

--------------------------fin--------------------------------------------

hope my answer was helpful


Related Solutions

Explain: Analysis of algorithms with the example. Explain with example: How computational time of an algorithm...
Explain: Analysis of algorithms with the example. Explain with example: How computational time of an algorithm depends on input size? Write an algorithm (using whatever method you prefer) that takes an input of 10 integers, sorts the integers in ascending order and out puts the sorted list. In relation to computational time of your algorithm for part 4, what arrangement of the input numbers will cause the best case computational time? What arrangement will cause the worst case time?
1) Describe a real-world example that uses one of the Data Mining Tasks and why is...
1) Describe a real-world example that uses one of the Data Mining Tasks and why is this task best suited to this example? PLEASE EXPLAIN IN DETAIL.
Real life example of uses of performance appraisal during recruitment and selection
Real life example of uses of performance appraisal during recruitment and selection
1.create and solve Example of Mathematical induction uses in real life.   
1.create and solve Example of Mathematical induction uses in real life.   
Provide an example of an animal (or human) in your life that uses a multimodal cue....
Provide an example of an animal (or human) in your life that uses a multimodal cue. Develop one hypothesis that aligns with the Efficacy hypotheses, and one that aligns with the Content hypotheses. Be sure to explain how each hypothesis aligns with Content or Efficacy.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT