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

  Evaluate how ericsson benefitted from amazon web services

cloud computing is defined by cearly and phifer in their case study titled case studies in cloud computing as a style

  Constructing truth table of converter circuit

Construct the truth table of the converter circuit using character a , b, c and d (d represents Least Significant Bit) in order to denote the literals input of BCD. Use w, x, y and z (z as Least Significant Bit) in order to represent the output li..

  Question- write down a java program which build a binary

question- write down a java program which build a binary tree given an arithmetic expression.- the arithmetic

  Describe the methods for establishing component priorities

Describe the methods for establishing component priorities, including Business functions and processes b. BIA scenarios and components c. Financial and service impact of components not being available d. Recovery time frameworks.

  Explain the fundamental components of a distributed system

explain the fundamental components of a distributed system.

  What are the pros and cons of each given option

Provide three different options that are available for selecting an identifier for a student entity. What are the pros and cons of each option?

  Implementing the transactions using sql

Write down the complete transaction utilizing the SQL. Write down the full transaction log

  Write a reflection report about the role of cryptography

Write a reflection report in 100 words about the role of cryptography in securing communication of confidential documents.

  Exhibit a set of representatives modulo 17 composed

list all integers x in the range -50 le x le 50 that satisfy x equiv 7 mod 17.b exhibit a set of representatives modulo

  Consider a design tool used in the construction

How is web content developed? What are some of the popular design tools in use today? Can you identify a design tool used in the construction of the website MSN.com.

  Spreadsheet model of the heat transfer situation

Spreadsheet model of the heat transfer situation

  Make a c++ class that implements a "safe" array

design a C++ class that implements a "safe" array, where the arrays bounds are checked before accessing its elements. The class constructor must accept an integer parameter and create a dynamic array of that size for storing integers, implemented ..

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