Write the function insertionsorta that takes an array of


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

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write the function insertionsorta that takes an array of
Reference No:- TGS01564399

Expected delivery within 24 Hours