Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
bartleby
Concept explainers
Question
IN C++, with pre an d post pseudocode please
Write the simplest program that will demonstrate iteration vs recursion using the following guidelines -
- Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which
- Takes an array of integers and its size as input params and returns a bool such that
- 'true' ==> all elements of the array are prime, so the array is prime,
- 'false' ==> at least one element in array is not prime, so array is not prime.
- Print out a message "Entering <function_name>" as the first executed statement of each function.
- Perform the code to test whether every element of the array is a Prime number.
- Print out a message "Leaving <function_name>" as the last executed statement before returning from the function.
- Remember - there will be nested loops for the iterative function and there can be no loops at all in the recursive function.
- For the recursive function - define one other helper function (IsPrimeRecur) which will recursively check if a number is prime or not - it will
- take the integer dividend (number to be checked for prime) and the integer divisor to perform the division,
- return true or false,
- not contain any loops to check if a number is prime,
- be the most efficient check possible, and
- write out the entering and exiting function statement as in #1-2 and #1-4 above.
- Remember - replace <function_name> with the actual name of each function.
- Including your 'main', there will be a total of 4 functions in your program and only the primary helper functions can be invoked from 'main'. No other functions are needed, so do not add unnecessary helper functions.
- Reminder Note - for all functions except 'main', the 'Entering <function name>' and 'Leaving <function name'> statements should be printed.
- Remember: 1 is not a prime number.
- Hint - try to complete your iterative code first and then convert it piece by piece to the recursive code.
- Takes an array of integers and its size as input params and returns a bool such that
- In your main:
- Declare a global integer constant called SORT_MAX_SIZE = 8.
- Print a one line message stating exactly "Please enter your input data on one line only."
- Then read ONE input line from standard input which will consist of several numbers separated by spaces such that
- The first positive integer number representing the number of elements in the array, followed by
- That many positive integer numbers representing the contents of the array to be checked for prime.
- You can expect that the user input will be correct as specified here.
- Create an array based on the size input provided by the user.
- Make a call to the primary iterative function passing the array and its size.
- If every member is a Prime, then the 'main' should print out exactly 'Array was found to be prime using iteration', otherwise print out 'Not a Prime Array using iteration'.
- Then make a call to the primary recursive function passing the array and its size.
- If every member is a Prime, then the 'main' should print out exactly 'Array was found to be prime using recursion', otherwise print out 'Not a Prime Array using recursion'.
- If your functions are coded correctly, both should come up with the same answer, except you should have lots more output statements using recursion.
- There is no sample output for you to match against but the instructions above are quite clear on how the output should look. The output for each run specified in #6 below can run into several screens.
- You should use primitive arrays - DO NOT USE
VECTORS , COLLECTIONS, SETS, BAGS or any other data structures from your programming language. - For python programmers - you are allowed to get input into a list and only use of append(), count() and index() methods for a Python list if needed.
- There will be only one code file in your submission and it should be called 'lab1.cpp' or 'lab1.java' or 'lab1.py'.
- Run your program twice in the console with the following inputs:
- 5 53 5099 1223 567 17
- 4 1871 8069 3581 6841
Expert Solution
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
This is a popular solution
bartleby
Trending nowThis is a popular solution!
bartleby
Step by stepSolved in 4 steps with 5 images
Knowledge Booster
Background pattern image
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
- Modify the recursive Fibonacci function to employ the memoization technique discussed in this chapter. The function creates a dictionary and then defines a nested recursive helper function named memoizedFib. You will need to create a dictionary to cache the sum of the fib function. The base case of the fib function is the same as before. However, before making any recursive calls, the helper function looks up the value for the function’s current argument in the dictionary (use the method get, with None as the default value). If the value exists, the function returns it and skips any recursive calls. Otherwise, after the helper function adds the results of its two recursive calls, it saves the sum in the dictionary with the current argument of the function as the key. Note: The program should output in the following format: n fib(n) 2 1 4 3 8 21 16 987 32 2178309 ---------------------------------------------------------------------------------- def...arrow_forwardWrite a recursive function to determine if an array of integers contains any even numbers: bool hasEvens(int nums[], int size)arrow_forwardT/F 11. A recursion will still be replaced by an iteration and the other way around.arrow_forward
- The Tower of Hanoi is a puzzle where n disks of different sizes arestacked in ascending order on one rod and there are two other rods with nodisks on them. The objective is to move all disks from the first rod to thethird, such that:- only one disk is moved at a time- a larger disk can never be placed on top of a smaller oneWrite a recursive function that outputs the sequence of steps needed tosolve the puzzle with n disks.Write a test program in C++ that allows the user to input number of disks andthen uses your function to output the steps needed to solve the puzzle.Hint: If you could move up n−1 of the disks from the first post to thethird post using the second post as a spare, the last disk could be moved fromthe first post to the second post. Then by using the same technique you canmove the n−1 disks from the third post to the second post, using the firstdisk as a spare. There! You have the puzzle solved. You only have to decidewhat the nonrecursive case is, what the recursive...arrow_forwardImplement a recursive is_palindrome(s:str)->bool function, which checks if the given string is a palindrome or not. Examples: >>> is_palindrome('racecar') True >>> is_palindrome('racecars') False please help my homework and put here screenshot. # instruction said not using loopsarrow_forwardConsider the recursive function provided above. After the initial call to the function ham has been made with argument 26 then how many subsequent recursive calls will be made before a value a final result can be returned? This question is internally recognized as variant 235. Q11) 1 2 3 4 5 6 7 8 none of the abovearrow_forward
- Midterm Practice Problems 1. Use recursion to write a function count_ones that returns how many Is there are in a number n when represented in decimal (base 10). For example, 1231 has two 1s. You can assume that n is nonnegative and at most 9 digits long. Do not use global (or static) variables. In main perform at least three tests of count_ones and use assert to check that the returned value is correct. Your function should have the following prototype: // count_ones (n) returns the number of is in the decimal representation of n // requires: 0 <= n < 10^9 int count_ones (int n);arrow_forwardMatlab Questionarrow_forwardThe following recursive definition of a set S over {a, b, c, d}. Basis: "", a, b, c E S. Recursive Step: If ax E S, then bax ES and cax E S. If bx € S, then cbx € S. If cx = S, then bax ES and bcx = S. If dx E S, then ddx E S. Closure: SE S only if it is a, b or c or it can be obtained from a, b or c using finitely many operations of the Recursive Step. a) What recursive step can be removed from the above definition and why? b) Derive from the definition of S that bcbc S. c) Explain why baa & S.arrow_forward
- PLZ help with the following: In Java Write a program using recursion to display all valid (i.e. properly open and closed) combinations of n-pairs of parentheses.arrow_forwardIn program C Write a recursive function find_sum(n)that calculates the sum of successive integers starting at 1and ending at n(i. e., find_sum( n) = 1 + 2 . . .+( n -1) + n.arrow_forwardwrite java codes to do the following: Write a recursive function to check if an integer array is negative symmetric, for example, an array of 10, 20, 30, 90, -30, -20, -10 is considered as negative symmetric, while an array of 10, 20, 30, 90, 30, 20, 10 is not considered as negative symmetric. public static boolean checkArraySym(int [ ] A, int first, int last) that receives an array A, first index, last index and checks if the array is negative symmetricarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education