Anna GE 8151 - ALGORITHMIC PROBLEM SOLVING

Unformatted text preview:

GE8151 PROBLEM SOLVING AND PYTHON PROGRAMMING QUESTION BANK UNIT I ALGORITHMIC PROBLEM SOLVING PART B 16 MARKS 1 What are the building blocks of an algorithm Explain in detail Dec Jan 2017 The building blocks of algorithm are Statements State Control flow Functions Statements There are 3 types of statements Input Output Statement Assignment Statement Control Statement State There are 3 types of state Initial state Current state Final state Control flow Sequence The sequence structure is the construct where one statement is executed after another Selection The selection structure is the construct where statements can executed or skipped depending on whether a condition evaluates to TRUE or FALSE There are three selection structures in C 1 IF 2 IF ELSE 3 SWITCH Repetition The repetition structure is the construct where statements can be executed repeatedly until a condition evaluates to TRUE or FALSE There are two repetition structures in C 1 WHILE 2 FOR Functions A function is a block of organized reusable code that is used to perform a single action 2 Briefly describe iteration and recursion Illustrate with an example Apr May 2021 ITERATION S no Iteration Recursion 1 The process is repeated until the The function calls itself until the base condition is 2 3 4 5 condition fails satisfied It consumes less memory It consumes more memory It is faster The code is long It is slower The code is short Tracing is easier if any problem Tracing is difficult if any problem occurs occurs Example Iterative algorithm for factorial of a number Step 1 Start Step 2 Read numbern Step 3 Call factorial n Step 4 Print factorial f Step 5 Stop factorial n Step 1 Initialize f 1 i 1 Step 2 Repeat step 2 1 and 2 2 until i n Step 2 1 f f i Step 2 2 Increment i by 1 i i 1 Step 3 Return f Example Recursive algorithm for factorial of number Step 1 Start Step 2 Read numbern Step 3 Call factorial n Step 4 Print factorial f Step 5 Stop factorial n Step 1 If n 1 then return 1 Step 2 Else f n factorial n 1 Step 3 Return f 3 Explain in detail Algorithmic problem solving Apr May 2019 4 Write an algorithm and draw a flowchart to calculate 24 Algorithm Step 1 Start Step 2 Initialize the value of result r 1 Step 3 Repeat step4 for 4 times Step 4 calculate r r 2 Step 5 Print the value of r Step 6 Stop Flowchart 5 a Describe pseudo code with its guidelines Pseudo code consists of short readable and formally styled English language used for explaining an algorithm Pseudo code does not include details like variable declarations subroutines etc Preparing a Pseudo Code Pseudo code is written using structured English In a pseudo code some terms are commonly used to represent the various actions For example for inputting data the terms may be INPUT GET READ for outputting data OUTPUT PRINT DISPLAY for calculations COMPUTE CALCULATE for incrementing INCREMENT in addition to words like ADD SUBTRACT INITIALIZE used for addition subtraction and initialization respectively The control structures sequence selection and iteration are also used while writing the pseudo code The sequence structure is simply a sequence of steps to be executed in linear order The selection constructs if statement and case statement In the if statement if the condition is true then the THEN part is executed otherwise the ELSE part is executed There can be variations of the if statement also like there may not be any ELSE part or there may be nested ifs The case statement is used where there are a number of conditions to be checked In a case statement depending on the value of the expression one of the conditions is true for which the corresponding statements are executed If no match for the expression occurs then the OTHERS option which is also the default option is executed WHILE and FOR are the two iterative statements b Give an example for pseudo code Pseudocode for finding maximum in a list BEGIN SET numlist GET n FOR i 1 to n GET numlist elements ENDFOR SET maximum numlist 0 FOR i in numlist IF n maximum maximum n ENDIF ENDFOR PRINT maximum END c Write the pseudo code for Towers of Hanoi Pseudocode START Procedure Hanoi disk source dest aux IF disk 0 THEN move disk from source to dest ELSE Hanoi disk 1 source aux dest move disk from source to dest Hanoi disk 1 aux dest source END IF END Procedure 6 a What is flowchart Apr May 2019 Flowchart is a diagrammatic representation of the logic for solving a task A flowchart is drawn using boxes of different shapes with lines connecting them to show the flow of control The purpose of drawing a flowchart is to make the logic of the program clearer in a visual form b List down symbols and rules for writing flowchart c Draw a flowchart to count and print from1 to 10 7 a Write an algorithm and give the flowchart to find the net salary of an employee Apr May 2019 Algorithm Step 1 Start Step 2 Read the basic salary Step 3 IF the basic is greater than or equal to 4000 ELSE Goto Step 4 Step 3 1 DA 0 32 basic Dearness Allowance Step 3 2 HRA 0 15 basic House Rent Allowance Step 3 3 CCA 325 City Compensatory Allowance Step 3 4 Net Salary Step 4 Print the Net Salary Step 5 Stop basic DA HRA CCA b Write an algorithm and give the pseudo code to guess an integer number in a range Algorithm step 1 Start the program step 2 Read an n number step 3 Read an Guess number step 4 if Guess n print Your Guess too high Step 5 elif Guess n print Your Guess too low step 6 elif Guess n print Good job Step 7 else print Nope Step 8 Stop the program Pseudocode BEGIN READ n READ Guess 20 IF Guess n print Your Guess too High elif Guess n print Your Guess too low elif Guess 20 print Good Job ELSE print Nope ALGORITHM Step 1 Start Step 2 Declare the variables N List I and X 8 a Write an algorithm to insert a card in a list of sorted cards Nov Dec 2019 Step 3 READ Number of element in sorted list as N Step 4 SET i 0 Step 5 IF i N THEN go to step 6 ELSE go to step 9 Step 6 READ Sorted list element as List i Step 7 i i 1 Step 8 go to step 5 Step 9 READ Element to be insert as X Step 10 SET i N 1 Step 11 IF i 0 AND X List i THEN go to step 12 ELSE go to step 15 Step 13 i i 1 Step 14 go to step 11 Step 15 List i 1 X Step 16 Stop b Write an algorithm to find the minimum number in a list Algorithm Step 1 Start Step 2 Initialize …


View Full Document

Anna GE 8151 - ALGORITHMIC PROBLEM SOLVING

Download ALGORITHMIC PROBLEM SOLVING
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view ALGORITHMIC PROBLEM SOLVING and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view ALGORITHMIC PROBLEM SOLVING 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?