Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Question
Chapter 2.1, Problem 4E
Program Plan Intro
To state the problem formally and also write the pseudo code for adding two integers.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Develop python program of function randomArray(m, n) that takes two integers as argument and returns a 2D m-by-n array with random elements in it.
Develop python program of function adder(a1, a2) that reads two 2D arrays of the same size and returns an array that is the summation of a1 and a2. To add the two arrays, you need to add their elements, correspondingly.
Develop a python program of function inverseArray(a) that takes a 2D-array as argument and inverses the array. You will need to inverse the rows, first and then inverse the columns, next. For instance, if the array = [[2, 3, 4], [5, 6, 7]], the inverse will be = [[7, 6, 5], [4, 3, 2]]
Language: C
Print a Mayo pyramid with # characters depending on user input, i.e., the pyramid height h. To this end, update the size of the array for each level of the pyramid (for each for loop passing) using the realloc function. First of all, allocate an array for the first row. You need the allocate the memory for h + 2 characters for the first row. Fill it with spaces, using the memset(row, ’ ’, h+2) command. For each row i, expand the array size to h + 4 + i, replace the last two characters of the line with # sign, followed by the string’s null terminator. That’s why you need increase the size by 2, with the respect to the original allocation, and then by 1 at each step. You also need to replace the space at the position h − 1 − i with the # character (the left slope of the pyramid). Print and examine your results, free the memory and use the valgrind function to check memory usage.
The MPI program 'Standard-Deviation.c' computes the standard deviation for an array of elements.Here, we assume that the maximum number of elements in the array is 10. Some necessary error checkings are performed to ensure that the number of inputs is correct and their values are valid.
(a) mpiexec -n 2 ./Stddev (b) mpiexec -n 2 ./Stddev 0 (c) mpiexec -n 3 ./Stddev 7
(d) mpiexec -n 3 ./Stddev 9 (e) mpiexec -n 4 ./Stddev 21
Standard-Deviation.c. This code is giving me an error when I compile
/////////////////////////////////////////////////////////////////////////////////////////// This is an MPI program that computes the standard deviation for an array of elements.//// Note: The array is generated according to its size (the number of elements), which // is specified by users from the command line. In the program, we assume its // maximum number is 10.//// Compile: mpicc Standard-Deviation.c -o Stddev -lm// // Run: mpiexec -n…
Chapter 2 Solutions
Introduction to Algorithms
Knowledge Booster
Similar questions
- barcode scanner for Universal Product Codes(UPCs) verifies the 12-digit code scanned by comparing thecode’s last digit (called a check digit ) to its owncomputation of the check digit from the first 11 digits asfollows:I. [step 1]Calculate the sum of the digits in theodd-numbered positions (the first, third, …,eleventh digits) and multiply this sum by 3.II. [step 2]Calculate the sum of the digits in theeven-numbered positions (the second, fourth, …,tenth digits) and add this to the previousresult(result of step1).III. [step 3]If the last digit of the result from step2 is 0, then 0 is the check digit. Otherwise,subtract the last digit from 10 to calculate thecheck digit.IV. [step 4]If the check digit matches the final digitof the 12-digit UPC, the UPC is assumed correct.1. Write main function that prompts the user to enterthe 12 digits of a barcode. The program shouldstore the digits in an integer array.2. Write a “check” function to calculate the checkdigit, and compare it to the final…arrow_forwardUsing C Language:Write a program that will input 20 values to array BSIT. Call the function EVEN to sum up the content of all even index. Print array BSIT and the sum of all even index.arrow_forwardDevelop python program of function random array(m, n) that takes two integers as an argument and returns a 2D m-by-n array with random elements in it. Develop python program of function adder(a1, a2) that reads two 2D arrays of the same size and returns an array that summarizes a1 and a2. To add the two arrays, you need to add their elements correspondingly. Develop a python program of function inverse ray(a) that takes a 2D-array as an argument and inverses the array. You will need to inverse the rows first and then inverse the columns next. For instance, if the array = [[2, 3, 4], [5, 6, 7]], the inverse will be = [[7, 6, 5], [4, 3, 2]]arrow_forward
- Using C language barcode scanner for Universal Product Codes(UPCs) verifies the 12-digit code scanned by comparing thecode’s last digit (called a check digit ) to its owncomputation of the check digit from the first 11 digits asfollows:I. [step 1]Calculate the sum of the digits in theodd-numbered positions (the first, third, …,eleventh digits) and multiply this sum by 3.II. [step 2]Calculate the sum of the digits in theeven-numbered positions (the second, fourth, …,tenth digits) and add this to the previousresult(result of step1).III. [step 3]If the last digit of the result from step2 is 0, then 0 is the check digit. Otherwise,subtract the last digit from 10 to calculate thecheck digit.IV. [step 4]If the check digit matches the final digitof the 12-digit UPC, the UPC is assumed correct.1. Write main function that prompts the user to enterthe 12 digits of a barcode. The program shouldstore the digits in an integer array.2. Write a “check” function to calculate the checkdigit, and…arrow_forwardtranslate the following MIPS code to C. Assume that the variables i, j, and k areassigned to the registers $s0, $s1, and $s2, respectively. Assume that the baseaddress of the array A is in registers $s6.Loop: blt $s0, $s1, Exitbge $s1, $s2, Exitaddi $s1, $s1, 5j LoopExit:addi $t0, $zero, 4ble $s0, $t0, Donesll $t1, $s0, 2add $t2, $s6, $t1sw $zero, 0($t2)Done:arrow_forward[Python (py3)] The code below is for matrix operations (addition, multiplication, scalar multiplication and transposition). Please annotate what happens in EACH line so that I can fully understand the code below. Some lines are already annotated. Please annotate EACH line. Do not just copy the code below and take it as the answer without modifying anything. I already encountered such case many times before. Sample input 1:add2 353 -4 17 31 22 3 67 2 2-34 6 3 Sample output 1:120 -2 3-27 37 5 ________________________________________________________________________________ Sample input 2:scalMultiply2 253 -47 312Sample output 2:106 -814 62 _______________________________________________________________________Sample input 3:multiply3 3 34 10 37 8 346 2 123 21 23 45 6 Sample output 3:79 126201 25072 92_______________________________________________________________________Sample input 4:transpose3 334 10 37 8 346 2 12Sample output 4:34 7 610 8 2 3 34 12…arrow_forward
- Answer in C++ only Given a sorted array arr, remove the duplicates from arr such that each element appears only once and display the new array. Input 1 3 112 Output 12arrow_forwardReference the image below.(a) Write a code in python to implement Hoare's algorithm.(b) Using LArray = {36, 12, 39, 34, 89, 2, 47, 95, 17, 19, 78, 22} as input, display the finaloutput and the array LArray after it has been manipulated by the algorithm.(c) Modify the algorithm to display the LArray after each swap done, being sure to indicatewhat swap is being observed.arrow_forwardWrite a C program to enter two arrays A[15] & B[15]. Use pointer (p) to fill them with random numbers in the range ( 45 - 65) and the range (40-60) 1- A zern in hott 3- print the biggest number in each array and their address 4-combine the two arrays in one array C[30] and print itarrow_forward
- Q) Write a program in assembly language to compares the elements of two arrays, A(1) and B(1), each array contains 100 16-bit signed number. Assume that the arrays start in the current data segment at offset addresses A000H and B000H respectively. If the two arrays are found to be unequal, save the address of the first unequal element of A(1) in the memory location with offset F00011. Otherwise, if the two arrays are found to be equal, write all O's into this location.arrow_forwardB) Write a program to shift all the zero present in the array in the alternative order, For example. Input array: - 12085006 Output array: - 10280506 Sample Input: First input should describe the number of elements in the array and in the second line take all the input. 01203 Output: - 10203arrow_forward. Write a program in C to convert a binary number into a decimal number without using array, function and while loop. Test Data :Input a binary number :1010101Expected Output :The Binary Number : 1010101The equivalent Decimal Number : 85arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education