Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 11th International Symposium Sstd 2009 Aalborg Denmark July 8 10 2009 Proceedings Lncs 5644

Authors: Nikos Mamoulis ,Thomas Seidl ,Kristian Torp ,Ira Assent

2009th Edition

3642029817, 978-3642029813

More Books

Students also viewed these Databases questions

Question

4. Why does transfer matter?

Answered: 1 week ago