GE8151 PROBLEM SOLVING AND PYTHON PROGRAMMING QUESTION BANK 2 marks with Answers Unit I
1. Define an algorithm An algorithm is a procedure or formula for solving a problem, based on conducting a sequence of specified actions 2. Specify any 5 programming languages Java, C, C++, Python, PHP 3. Distinguish between pseudo code and flowchart Flowchart is usually a graphical representation, where as pseudo-code is something written in a language. Note that they both show the step by step procedure for solving a problem. One is graphical while one is text based. 4. Define recursion Recursion is the process of defining a problem (or the solution to a problem) in terms of a simpler version of itself. A recursive procedure or routine is one that has the ability to call itself. 5. Define control flow statement. A program's control flow is the order in which the program's code executes. The control flow of a Python program is regulated by conditional statements, loops, and function calls. 6. What is the concept of towers of Hanoi. The objective of the game is to move the entire stack of disks from Tower 1 to Tower 3. You can move only one disk at a time. No disk may be placed on top of a smaller disk. With 3 disks, the puzzle can be solved in 7 moves. The minimal number of moves required to solve a n Tower of Hanoi puzzle is 2 − 1, where n is the number of disks. 7. Explain list. In computer science, a list or sequence is an abstract data type that represents a countable number of ordered values, where the same value may occur more than once. The name list is also used for several concrete data structures that can be used to implement abstract lists, especially linked lists. Many programming languages provide support for list data types, and have special syntax and semantics for lists and list operations. 8. What is Iteration? Iteration is the repetition of a process in a computer program, usually done with the help of loops. Many computer programs and programming languages use iterations to perform specific tasks, solve problems, and present solutions. 9. Explain how do you assess problem solving method. The problem solving method is the process of working through details of a problem to reach a solution. Problem solving may include mathematical or systematic operations and can be a gauge of an individual's critical thinking skills. Methods for assessing problem-solving learning outcomes vary with the nature of the -problem. Problem solving processes are normally assessed by coding schemes. Based on that assumption, numerous models of problem solving have been suggested, most of which involve a sequence of steps, including: Define the problem. Analyze the problem (identify possible causes). • •
JIJU
Investigate the problem (gather information). Generate possible solutions. Evaluate the alternative solutions. 10. What is meant by sorting? Mention its types Sorting refers to arranging data in a particular format. Sorting algorithm specifies the way to arrange data in a particular order. Types of Sorting Techniques Bubble Sort. Insertion Sort. Selection Sort. Quick Sort. Merge Sort. Heap Sort. 11. Define programming language. A programming language is a vocabulary and set of grammatical rules for instructing a computer or computing device to perform specific tasks. The term programming language usually refers to high-level languages, such as BASIC, C, C++, COBOL, Java, FORTRAN, Ada, and Pascal. 12. Discuss building blocks of algorithm. Any algorithm can be constructed from just three basic building blocks. These three building blocks are Sequence, Selection, and Iteration. Sequence is an action in which one or more instructions that the computer performs in sequential order (from first to last). Selection is a Decision making choice among several actions. Iteration can be a Loop in which one or more instructions that the computer performs repeatedly. • • •
• • • • • •
13. What are the steps for developing algorithms. Problem definition Development of a model Specification of Algorithm Designing an Algorithm Checking the correctness of Algorithm Analysis of Algorithm Implementation of Algorithm Program testing Documentation Preparation • • • • • • • • •
14. Give an example for recursion function #To find the factorial of a number def calc_factorial(x): if x == 1: return 1 else: return (x * calc_factorial(x-1)) num = 4 print("The factorial of", num, "is", calc_factorial(num))
JIJU
output : The factorial of 4 is 24 15. Discuss building blocks of algorithm. Any algorithm can be constructed from just three basic building blocks. These three building blocks are Sequence, Selection, and Iteration. Sequence is an action in which one or more instructions that the computer performs in sequential order (from first to last). Selection is a Decision making choice among several actions. Iteration can be a Loop in which one or more instructions that the computer performs repeatedly. 16. Differentiate predefined function and user defined function. Predefined functions are part of the programming language. For eg. built-in C functions, like printf( ) and scanf( ). A user-defined function is a function which the programmer creates and uses in a program.
JIJU