4. Iteration versus recursion (an opportunity for performance measurement) Make a sorted integer array a [i]=i, i=0,...,n-1. Let bs (a,n,x) be a binary search program that returns the index i of array a[0..n-1] where a[i]=x. Obviously, the result is bs (a,n,x)=x, and the binary search function can be tested using the loop for(j=0; j

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Can someone please explain to me all of it? ASAP??!! This is C++ language. Instructions: The goal of this homework is to develop your skills in procedural programming. You should develop three efficient procedural programs and perform a simple performance measurement. Your programs should be as short and simple as possible, and as fast as possible. Each program must be documented. For each solution first explain the idea and then explain the reasons why you think it is a good procedural solution. You must show your source programs, and results of their execution. All programs should be written in C++.
4. Iteration versus recursion (an opportunity for performance measurement)
Make a sorted integer array a[i]=i, i=0,...,n-1. Let bs (a,n,x) be a binary search
program that returns the index i of array a[0..n-1] where a[i]=x. Obviously, the result is
bs (a,n,x)=x, and the binary search function can be tested using the loop
for(j=0; j<K; j++)
for (i=0; i<n; i++) if(bs (a,n,i) != i) cout << "\nERROR";
Select the largest n your software can support and then K so that this loop with an
iterative version of bs runs 3 seconds or more. Then measure and compare this run time
and the run time of the loop that uses a recursive version of bs. Compare these run times
using maximum compiler optimization (release version) and the slowest version
(minimum optimization or the debug version). If you have a desktop machine, use it. If
you must use a laptop, make measurements using AC power, and then same
measurements using only the battery. What conclusions can you derive from these
experiments? Who is faster? Why? What is the time for executing a single bs program? If
you have different compilers you can compare them.
Transcribed Image Text:4. Iteration versus recursion (an opportunity for performance measurement) Make a sorted integer array a[i]=i, i=0,...,n-1. Let bs (a,n,x) be a binary search program that returns the index i of array a[0..n-1] where a[i]=x. Obviously, the result is bs (a,n,x)=x, and the binary search function can be tested using the loop for(j=0; j<K; j++) for (i=0; i<n; i++) if(bs (a,n,i) != i) cout << "\nERROR"; Select the largest n your software can support and then K so that this loop with an iterative version of bs runs 3 seconds or more. Then measure and compare this run time and the run time of the loop that uses a recursive version of bs. Compare these run times using maximum compiler optimization (release version) and the slowest version (minimum optimization or the debug version). If you have a desktop machine, use it. If you must use a laptop, make measurements using AC power, and then same measurements using only the battery. What conclusions can you derive from these experiments? Who is faster? Why? What is the time for executing a single bs program? If you have different compilers you can compare them.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education