You are on page 1of 6

1.define flowchart. mention the symbols used in flowchart.

Flowchart :
flow chart is a graphical representation of the algorithm. using specific notations the algorithm is
represented using the flowchart.

Mention the symbols used in flowchart:

2.What do you mean by recursion?


Recursion is a method of solving problems that involves breaking a problem down into smaller and
smaller subproblems until you get to a small enough problem that it can be solved trivially. Usually
recursion involves a function calling itself. While it may not seem like much on the surface, recursion
allows us to write elegant solutions to problems that may otherwise be very difficult to program.

3. Define tuple. Give example.


(i)Tuble is a collection of elements and it is smilar to the list.but the items of the tuples are seprated by
comma and the elements are enclosed in () parenthesis.
(ii)   A tuple is an immutable list. i.e. once a tuple has been created, you can't add elements to a
tuple or remove elements from the tuple.
4. Difference between algoritm and program.
Algorithm: The algorithm is a solution to a given problem in the form of simple and logical steps.
The algorithm can be expressed using flowchart or a natural language.
Program: program refers to the code which follows the basic rules of the concerned programming
language.
Program is expressed in a programming language code which is complied and executed on computer.
5. Briefly discuss about the basic building block of algorithm. Give an
example.
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.

6. Describe in detail about the towers of hanoi with a neat diagram.


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

7.(i)write an algorithm to insert a card into a list of sorted cards.


ALGORITHM:
Step 1: Start
Step 2: Declare the variables N, List[],I and X
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

(ii)Draw an flowchart 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"

8.(i)what do you mean by debugging? Mention the types of errors


involved in debugging.
MODES OF PYTHON INTERPRETER:
Python Interpreter is a program that reads and executes Python code. It uses 2 modes of
Execution.
 1.  Interactive mode
2.   Script mode
 1. Interactive mode:
v   Interactive Mode, as the name suggests, allows us to interact with OS.
v   When we type Python statement, interpreter displays the result(s) immediately.
Advantages:
   Python, in interactive mode, is good enough to learn, experiment or explore.
   Working in interactive mode is convenient for beginners and for testing small pieces of code.
Drawback:
   We cannot save the statements and have to retype all the statements once again to re-run them.
 

2.
Script mode:
v   In script mode, we type python program in a file and then use interpreter to execute the content of the
file.
v   Scripts can be saved to disk for future use. Python scripts have the extension .py, meaning that the
filename ends with .py

(ii)Discuss in detail about the values and types in python.

Numbers:
   Number data type stores Numerical Values.
  This data type is immutable [i.e. values/items cannot be changed].
   Python supports integers, floating point numbers and complex numbers.
 There are three types of sequence data type available in Python, they are
1. Strings
2.  Lists
3.  Tuples

1. Strings
Ø   A String in Python consists of a series or sequence of characters - letters, numbers, and special
characters.
Ø   Strings are marked by quotes:
·  single quotes (' ') Eg, 'This a string in single quotes'
·  double quotes (" ") Eg, "'This a string in double quotes'"

2. Lists
 List is an ordered sequence of items. Values in the list are called elements / items.
It can be written as a list of comma-separated items (values) between square brackets[ ].3. Tuple:
 A tuple is same as list, except that the set of elements is enclosed in parentheses instead of square
brackets.
   A tuple is an immutable list. i.e. once a tuple has been created, you can't add elements to a tuple or
remove elements from the tuple.

Dictionaries:
v   Lists are ordered sets of objects, whereas dictionaries are unordered sets.
v   Dictionary is created by using curly brackets. i,e. {}

You might also like