Wednesday, July 17, 2019
Algorithm: Flowchart and Trailer Record
Student happen upon Syed Haseeb Hashmi Registration FA11-BCS-075 Course Title physical body and Analysis of Algorithm Assignment 1 Submitted To Sir Tanveer Ahmed Siddiqui Due Date 19-03-2013 For Odd map Number Group Q1. How does a flow diagram help a weapons platformmer in a program schooling? Ans. Flowgraphs countenance the visual representation of a construct and make it clear. A flow chart serves as a blue scrape of the program. Flowcharts helps a programmer organize his/her thoughts in a logical systemal order and their presentation.Program development with show up art may be less effective. In big projects it gets difficult to keep things together. Flowcharts take into account flexibility, so that you bottom make changes and structure the project as you move shape up and, according to requirement. Flowcharts act as a guide during the analysis and program development phase. More everyplace they are also stabilising in debugging process. Q2. Draw a flow diagram of t he logical steps needed to give rise a printed listing of either students over the advance of 20 in a class. The foreplay records contain the name and grow of the students. turn out a guide zero(preno minal)rish of 99 for the age field of the lagger record. Sol. Q3. The early 20 records in a data set are to be deal and printed. Draw a flowchart for the algorithmic ruleic ruleic ruleic rule to do this job. Make sure that the impact stops after the twentieth record. Sol. Q4. For the employees job of head 40 ( yet multitude Q3), we want to count and print the chassis of just male employees in the age group of 25 to 30. go for that the input records contain SexCode and Age fields to admit this information. Draw a flowchart for the algorithm to effect this job. Sol. Q5.A set of examination papers, which defecate been graded with scores form 0 to 100 is to be searched to queue how galore(postnominal) of them are above 90. The total has to be printed. Prep are a flowchart to do this job. As unificati matchless a suitable sentinel value for the pigeon berry record. Sol. Q6. A tradesman wants to brace a general program for his personal data processor, which pull up stakes prepare bills for distributively node as and when he sells goods to them. His view is that as soon as the customer purchases some goods from his shop, he will lend the description, social unit price, and the standard purchased for each item. s input to the computer. He wants that with this information, the computer should print each item along with its unit price, quantity purchased and the total price. Fin altogethery the computer should also print the total greet of all the items purchased by the customer. As meansing a sentinel value of zero for the quantity purchased field in the trailer record, cajole a flowchart for the logic to do this job. Q7. Each employee fee record includes the hours worked and the pay rate. The gross pay is to be dictated as h ours worked propagation pay rate, and is to be printed for each employee.For all hours worked in tautologic of 40, the over cadence rate, which is 1. 5 time the rhythmical rate, is to be paid. Draw a flowchart for the problem logic to do this. As trade unione a suitable sentinel value for either(prenominal) of the input fields of the trailer record. Q8. The data file of Question 48 (even group Q7) is expanded to include some(prenominal) sets of data, each requiring calculation of its average. Each data set is followed by a trailer record with a value of -1 up to now the last data is followed by a trailer record with a value of -2.Draw a flowchart for the logic to perform this task. Solution. Q9. Draw a flow chart to add up all the even numbers racket between 0 and 100. onward ending, print the result of calculation. Solution. Q10. Draw a flowchart for the logic to insure out whether a given triangle first rudiment is a right angled triangle. Assume that the sides are supp lied as input and data. fall guy the answer as yes or no. Solution. Q11. Draw a flowchart for the logic to convert a number from hateful 10 to new base victimization division remainder technique. Solution. Question 2 ) Determine which characteristics of an algorithm the following purposes have and which they lack. process 1 double(n demonstrable integer)// The pattern of this procedure is to double a confirming integer slice n =0 do n 2n functioning 2 lead(a, b integers)// The purpose of this procedure is to choose a number from two confirmative numbers x either a or b Procedure 3 sum(npositive integer)// The purpose of this procedure is to find the sum of first 9 digits. sum = 0while i 10 do sum sum + i 1.Procedure 4 divide(npositive integer) // The purpose of this procedure is to find the joint of a positive integer n till 1. while n= 0 do m 1/n n n-1 Solution Procedure Input make Precision Finiteness Definiteness nicety Generality 1 NO NO YES YES NO YES YES 2 NO YE S NO NO YES YES NO 3 YES YES YES YES YES NO YES 4 NO YES NO NO YES YES NO b) Modify above procedure so that they satisfies all the properties Procedure 1 if n = 0 n 2n Procedure 2 if a0 && b0 either a or b Procedure 3 i 0 sum 0 while i 10 do sum sum + i i++ Procedure 4 While n 0 do m 1/n n n 1 Question 3 a) Find gcd(31415, 14142) by applying Euclids algorithm. Sol. gcd(31415%14142) gcd(14142%3131) gcd(3131%1618) gcd(1618%1513) gcd(1513%105) gcd(105%43) gcd(43%19) gcd(19%5) gcd(5%4) gcd(4%1) gcd(1%0) = 1 Answer. b) Estimate how many times faster it will be to find gcd(31415, 14142) by Euclids algorithm compared with the algorithm based on checking consecutive integers from minm, n down to gcd(m, n). Ans.The algorithm for purpose gcd based on checking consecutive integers will take 14142 steps, whereas the Euclids algorithm took sightly 11 steps. So, 14142/11 we get 1285. We can say that Euclids algorithm is 1285 time faster. Question 4 What does Euclids algorithm do for a pair of numbers in which the first number is little than the second one? What is the largest number of times this can happen during the algorithms execution on such an input? Ans. According to Euclids algorithm if the first number is smaller the second one then we have to swap the twain values.We will have to swap only once. Question 5 a) What is the smallest number of divisions do by Euclids algorithm among all inputs 1 ? m, n ? 10? b) Ans. For any possible combination of inputs among 1 ? m, n ? 10, the smallest number of division make by Euclids algorithm is 1. c) What is the largest number of divisions made by Euclids algorithm among all inputs 1 ? m, n ? 10? d) Ans. For any possible combination of inputs among 1 ? m, n ? 10, the largest number of divisions made by Euclids algorithm is 5 for (5,8). Question 6Euclids algorithm, as presented in Euclids treatise, uses subtractions quite a than integer divisions. Write a impostor code for this version of Euclids algorithm. Ans. If a0 X b2-4ac If X 0 print no real roots exits else X1 -b+sqrt(X)/2a X2 -b-sqrt(X)/2a Return X1 and X2.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.