Write the function insertion_sort

Assignment Help Computer Engineering
Reference no: EM131182162

Problem 1:

Write the function insertion_sort(a) that takes an array of numbers and returns an array of the same values in nondecreasing order, without modifying a.

Your function should use the insert function written in the previous problem.
>> b = Array.new(12) {Random.rand(100)}
=> [30, 81, 43, 95, 24, 38, 64, 56, 74, 70, 33, 60]
>> insertion_sort(b)
=> [24, 30, 33, 38, 43, 56, 60, 64, 70, 74, 81, 95] >> b
=> [30, 81, 43, 95, 24, 38, 64, 56, 74, 70, 33, 60]
>> insertion_sort(b) == b.sort
=> true

Problem 2:
The factorial of an integer n is defined fact(n)=n!=n?(n-1)?(n-2)???1.

Define five different versions of the function fact, named fact1, ... fact5. Try to achieve significant variety among your functions.
>> fact1(5)
=> 120
>> fact2(40)
=> 815915283247897734345611269596115894272000000000

Reference no: EM131182162

Questions Cloud

Identify and describe a business crisis : Identify and describe a business crisis situation and the main leaders involved. It could be one that you have experienced or have read about. Be sure to include a discussion of ethical implications
Dosages resembles a normal distribution reasonably closely : In a sample of 100 syringes, the hospital's quality control officer finds the average dosage to be 0.5mL. The standard deviation of the dosage is 0.02 mL and the distribution of the dosages resembles a normal distribution reasonably closely.
How will you sell the product in that country : What is the product that you plan to sell? -  What foreign country do you plan to target?  -  How will you sell the product in that country?
Formulate an alternative hypothesis : Formulate an alternative hypothesis for each of the following null hypotheses. (a) H0: Support for a presidential candidate is unchanged after the start of the use of TV commercials.
Write the function insertion_sort : Write the function insertion_sort(a) that takes an array of numbers and returns an array of the same values in nondecreasing order, without modifying a.
Expected number of people that leave the drive-thru : What is the expected number of people that leave the drive-thru with their orders filled in any given 4 minute interval?
How can you use goal-setting to increase motivation : Develop strategies to advance your career using your strengths. How can you use goal-setting to increase motivation and improve job performance? How might your engagement as an employee and job satisfaction influence job performance
How many ties of each type may it possibly have : Ties Unlimited stocks $1 ties, $2 ties, and $4 ties. If it has a total inventory of 7,000 ties valued at $12,000. How many ties of each type may it possibly have? If the number of $2 ties is 2,000 how many of each type are there?
Required to manufacture units : It took a contractor 1285 hours to manufacture their first unit of an item. If the contractor expects to achieve a 92% unit learning curve, how many hours would be required to manufacture units 52-100?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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