UNIT I.pptxpython unit 1 engineering full unit completed

pavithrad67 21 views 47 slides Jul 29, 2024
Slide 1
Slide 1 of 47
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47

About This Presentation

python unit 1 engineering full unit completed


Slide Content

UNIT I COMPUTATIONAL THINKING AND PROBLEM SOLVING

IDENTIFICATION OF COMPUTATIONAL PROBLEMS:- It serves as a first step in a process to identify ,evaluate a problem and explore solutions. Consists of two steps Identifying and acknowledging that there is a problem Developing a problem identification statement. We need to define four steps related to the identification of problem and its solution. They are Decomposition Pattern recognition Abstraction Algorithm design

Decomposition The first step of computational thinking is decomposition. This stage starts by analyzing the problem, stating and establishing the criteria for the solution. A computational thinking approach to a solution starts by breaking the problem down into smaller more familiar components so that they can be manage easily. Pattern Recognition:- The second step is pattern recognition. If some problems are similar in nature, there is a good chance that they can be solved using similar are repeated techniques. This is a key skill to create efficient and effective solutions to given problems.

Abstraction :- The abstraction stage involves the identification of key components of the solution. Rather than looking specific details ,it requires the ability to filter out unnecessary elements of a problem so that only focus on important elements. Abstraction allows to consider all the key elements prior to the creation of the final solution ,while ignoring any unnecessary details.

Algorithm Design:- The final stage within the computational thinking is algorithm design. A detailed step by step set of instructions are created which explain how to solve problem.

Problem solving techniques There are three ways to represent the logical steps for finding the solution to the given problem. Algorithm Flow chart Pseudo code Algorithms:- It is a step by step procedure for solving any problem. Algorithm is an English like representation of the logic which is used to solve the problems. To succeed a particular task, different algorithms can be written.

The programmer selects the best suited algorithm for the given tasks to be solved. The algorithm is independent of any programming language. Guidelines for writing algorithms:- An algorithm should be clear, accurate and well defined. It should always begin with the word ‘start’ and ends with the word ‘stop’. Each step should be written in separate line. Steps should be numbered as step 1,step 2,step 3 and so on.

Algorithm1 to find the greatest among three numbers:- Step 1:start Step 2:Read three numbers A,B,C. Step 3:Compare A and B. If A is the greatest perform step 4 else perform step 5. Step 4: Compare A and C. If A is the greatest ,print “A is greater” else print “B is greater” Step 5: Compare B and C. If B is the greatest ,print “B is greater” else print “C is greater”. Step 6: Stop.

Algorithm2 to find the greatest among three numbers:- Step 1:start Step 2:Read three numbers A,B,C. Step 3:Compare A and B. If A is the greatest store A in MAX, else store B in MAX. Step 4: Compare MAX and C. If MAX is the greatest ,print “MAX is greater” else print “ C is greater” Step 5: Stop.

Properties of Algorithm:- Finiteness: An algorithm must be terminated after a finite number of steps. Definiteness: Each step of the algorithm must be accurately defined. Input: The data must be present before any operations can be performed on it. Output: After executing all the steps of algorithm at least one output must be obtained. Effectiveness: The operations to be performed in the algorithm can be carried out manually in finite intervals of time.

Advantages of Algorithm: It is simple to understand step by step solution of the problem. It is easy to debug. It is independent of programming languages. It is compatible to computers, because each step of an algorithm can be easily coded into its high level languages.

Building blocks of algorithm:- The building blocks are Statements State Control flow Functions. Statements/Instructions:- An algorithm is an sequence of instructions to succeed a task solve a problem. An instructions describes an action. The algorithm consists of finite number of statements. Its must be in ordered form.

State: In an algorithm the state of process can be represented by a set of variables. As the values of the variables are changed, the state changes. An algorithm starts from the initial state with some input values. As actions are performed ,its state changes. It ends with a final state. Control flow:- An algorithm is a sequence of statements. The statement to be executed next may depend on the state of the process. Thus the order in which the statements are executed may differ from the order in which they are written in the algorithm. The order of execution of statements is known as the control flow.

There are three control flow statements to alter the control flow depending on the state. They are Sequence control flow Selection control flow Iteration control flow. Sequence control flow: In Sequence control flow ,a sequence of statement is executed one after another in the same order as they written. The instructions in sequence control flow are executed exactly once.

Algorithm to find the sum of two numbers:- Step 1: Start Step 2:Read two numbers A and B. Step3:Calculate sum=A+B Step4:Print the sum value Step5:Stop This algorithm performs the steps in a purely sequential order.

Selection Control Flow: In this ,a condition of state is tested, and if the condition is true, one statement is executed; if the condition is false an alternative statement is executed. Step 1:start Step 2:Read three numbers A,B,C. Step 3:Compare A and B. If A is the greatest perform step 4 else perform step 5. Step 4: Compare A and C. If A is the greatest ,print “A is greater” else print “B is greater” Step 5: Compare B and C. If B is the greatest ,print “B is greater” else print “C is greater”. Step 6: Stop.

Iteration (looping)control flow: In this a set of statements are repetitively executed based on the condition. If a condition evaluates to true ,the set of statements is executed again and again. If the condition becomes false the repetition stops. This is also known as looping statement or iteration statement. Algorithm to find sum of first 100 integers. Step1:start Step2:Assigh sum=0,i=0; Step3:Calculate i =i+1 and sum = sum+i ; Step4: Check whether i >=100,if no repeat step3.Otherwise go to next step. Step5:Print the value of sum;

Functions:- A function is a block of organized and reusable code that is used to perform a similar task of same kind. Any complex problem will become simpler if the problem is broken smaller and then the problem is solved. Functions avoid the repetition of same codes over and over. Functions reduce program size. Functions help easy debugging, testing and understanding of the program.

NOTATIONS A notation is a system of characters,expressions,graphics or symbols used in problem solving process to represent technical facts to facilitate the best result for a problem. Example: Pseudocode, Flowchart. Pseudocode:- Pseudocode is a short, readable and formally styled English language used for explaining an algorithm. Pseudocode does not include details like variable declarations,subroutines,etc. It is easier for a programmer or non programmer to understand the general working of program. It is used to give a sketch of the structure of the program. It is not machine readable. Pseudocode cannot be compiled and executed.

Preparing a Pseudocode:- Pseudocode is written using structured English. The programmers use their own style for writing the pseudocode, which can be easily understood. Pseudocode uses some keywords to denote programming process. Some of them as follows Input :INPUT,GET,READ AND PROMPT. Output :OUTPUT,PRINT,DISPLAY AND SHOW. Processing :COMPUTE,CALCULATE,DETERMINE,ADD, SUBSTRACT,MULTIPLY AND DIVIDE. Initialize :SET and INITIALIZE. Incrementing :INCREMENT

The keywords should be capitalized. There are three control structures used in Pseudocode. They are Sequence control structure Selection control structure Iteration control structure. Sequence control structure:- In Sequence control flow ,a sequence of statement is executed one after another in the same order as they written from top to bottom. The instructions in sequence control flow are executed exactly once. Find the product of two numbers. READ values of A and B. Compute C by multiplying A with B. PRINT the result C.

Selection control flow:- In this,a condition of state is tested, and if the condition is true, one statement is executed; if the condition is false an alternative statement is executed. There are two main selection structures. They are IF THEN –ELSE statement CASE statement IF THEN ELSE statement: In this, if the condition is true ,then THEN part is executed. Otherwise the else part is executed. Syntax: IF condition THEN Process 1 ELSE Process 2 END IF

Example: READ values of A,B,C IF A is greater than B THEN ASSIGN A to MAX ELSE ASSIGN B to MAX IF MAX is greater than C THEN PRINT MAX is greatest. ELSE PRINT C is greatest STOP

The CASE Statement:- The case statement is used ,when many number of conditions to be checked. In this depending on the expression, one of the condition is true. Syntax: CASE value1: Process1 CASE value2: Process 2 CASE value n: Process n END CASE

Iterative control structures:- In this a set of statements are repetitively executed based on the condition. If a condition evaluates to true ,the set of statements is executed again and again. If the condition becomes false the repetition stops. This is also known as looping statement or iteration statement. There are two iterative control structures. They are WHILE DO – WHILE. In while loop, the condition is executed at the beginning of the loop. If the condition is false then the loop will not be executed. Syntax: WHILE condition statements END WHILE

In DO-WHILE loop the condition is executed at the end of the loop, so the loop is executed at least once Syntax: DO statements WHILE condition END DO Find sum of first 100 integers. INITIALIZE sum to zero INITIALIZE i to zero DO INCREMENT i by 1 ADD I to SUM and store in SUM WHILE(I less than 100) END DO PRINT SUM STOP

FLOW CHART A Flow chart is a diagrammatic representation of the logic for solving the task. A flow chart is drawn using boxes of different shapes with lines connecting them. The purpose of drawing a flowchart is to make the logic of the program clearer in an visual form.

FLOW CHART SYMBOLS:-

Guide lines for preparing a flowchart:- There can be only one start and one stop symbol in flow chart. Only one flowline can be used with the start and stop symbol. Direction of flow of information in a flow chart must be from top to bottom or from left to right. Only one flow line should come out from a process symbol. Only one flow line should enter a decision symbol, but two or three flow lines should come out from the decision symbol .

Sequential control structure: In Sequence control flow ,a sequence of statement is executed one after another in the same order as they written from top to bottom. The instructions in sequence control flow are executed exactly once.

Selection control structure:- In this, a condition of state is tested, and if the condition is true, one statement is executed; if the condition is false an alternative statement is executed.

Iterative control structures:- In this a set of statements are repetitively executed based on the condition. If a condition evaluates to true ,the set of statements is executed again and again. If the condition becomes false the repetition stops. This is also known as looping statement or iteration statement. There are two iterative control structures.

Advantages of flow chart:- The symbols used in a flow chart are self explanatory. This makes a flow chart easier to understand. With the help of flow chart, a problem can be analyzed in an effective way. Compared to algorithms and the Pseudo-code method, Flowcharts are very easy to understand. A flowchart is an important tool for planning and designing new systems. It helps us to understand the logic of given problems. Communication becomes effective. Mistakes can be easily identified

Disadvantages of flow chart:- Complex tasks cannot be presented through symbols so easily.  If there is any error found in the process or logic of the flowchart, it is difficult to alter or modify the same. Difficult to understand for people who don’t know flowchart symbols. It takes lot of time to represent a program diagrammatically.

PROGRAMMING LANGUAGES A programming language consists of a vocabulary containing a set of grammatical rules intended to convey instructions to computer or computing device to perform specific tasks. There are two types of programming languages. Low level languages High level languages Low level language:- include Assembly and Machine languages. Machine level language: is a language that consists of a set of instructions that are in binary form 0 and 1. It can not be easily understood by humans. It does not require any translator as the machine code is directly executed by the computer.

Machine language is only understand by the computers. Machine language is very difficult to understand by the human beings. Modifications and error fixing cannot be done in machine language. Machine language is very difficult to memorize so it is not possible to learn the machine language. Execution is fast in machine language because all data is already present in binary format. Assembly language:- Assembly language is only understand by human beings not by the computers. In assembly language data can be represented with the help of mnemonics such as Mov, Add, Sub, End etc.

Assembly language is easy to understand by the human being as compare to machine language. Modifications and error fixing can be done in assembly language. Easy to memorize the assembly language because some alphabets and mnemonics are used. Execution is slow as compared to machine language. Assembler is used as translator to convert mnemonics into machine understandable form.

High level languages:- The high-level language is a programming language that allows a programmer to write the programs which are independent of a particular type of computer. The high level languages are considered as high level because they are closer to human languages than machine level languages. A compiler is required to translate high level languages into a low level language. C,C++,JAVA are high level languages.

Algorithmic problem solving:- Problem solving is the process of identifying a problem, developing an algorithm for the identified problem and finally implementing the algorithm to develop a computer program. Key steps to required for solving a problem using a computer are Step1 :Obtain a description of the problem Step2 :Analyze the problem Step3 :Develop ahigh level algorithm. Step4 :Refine the algorithm by adding more details Step5 :Review the algorithm.

Step1:Obtain a description of the problem The algorithmic problem solving process starts by obtaining a description of the problem. In a software development process, the word ‘client’ refers to the who wants to find the solution to the problem. The word ‘developer ’refers to a person who finds a way to solve the problem. The developer must create an algorithm that will solve the client’s problem. The client is responsible for creating a description of the problem, but this is the weakest part of the algorithm. A problem description suffers from one or more of the following defects

The description may be expressing more than one meaning. The description may be incomplete. The description may depend on unstated assumptions. These defects are due to carelessness by the client. Part of the developer’s responsibility is to identify ,the defects in the description of the problem and to work with the client to rectify those defects. Step2:Analyze the problem To read and analyze the problem statement carefully in order to list the principle components of the problem and decide the core functionalities that our solution should have. By analyzing the problem, we would be able to figure out what are the inputs that our program to accept and outputs that it should produce.

Step 3:Develop a high level algorithm It is essential to find a solution before writing a program code for a given problem. The solution is represented in natural language and is called an algorithm. For a given problem ,more than one algorithm is possible and we have to select the most suitable solution. It is better to start with a high level algorithm that includes a major part of a solution Step4:Refine the algorithm by adding more detail For larger, more complex problems ,go through this process several times. Each time, more details are added to the previous algorithm, for further refinement. This technique is gradually working from a high level to a detailed algorithm is often called stepwise refinement.

Step 5:Review the algorithm The final step is to review the algorithm. Work through the algorithm step by step whether or not, it will solve the original problem. Once algorithm is developed, translate it into a computer program in some programming languages.

SIMPLE STRATEGIES FOR DEVELOPING ALGORITHMS SIMPLE STRATEGIES FOR DEVELOPING ALGORITHMS:- Iteration Recursion Iteration:- Iteration is the process of repeating the same set of statements again and again until the specified condition holds true. Computer execute the same set of statements again and again by putting them in loop. In general the loops are classified as 1.Counter controlled loops 2.Sentinel-controlled loops

Counter controlled loops:- Counter controlled looping is a form of looping in which the number of iterations to be performed is known in advance. Example:- i =1 sum=0 while( i <=100): sum= sum+i i =i+1 i <=100 sum= sum+i i =i+1

Sentinel-Controlled loops: In sentinel-controlled looping, the number of times the iteration is to be performed is not known before. Example:- Step1:Start Step2:Read N. Step3:Assign sum=0,i=0; Step4:Calculatei=i+1 and sum= sum+i Step5:Check whether i >= N,if not repeat step 4.Otherwise goto next step. Step6:Print the value of sum Step7:Stop

Recursion:- A function call itself again and again is known as recursion. Example: Step1:Start Step2:Read number n Step3:Call factorial(n) Step4:Print factorial f Step5:Stop Factorial(n) Step1:if n==1 then return 1 Step2:Else f=n*factorial(n-1) Step3:Return f