ARASU ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
GE3151 – Problem Solving and Python Programming
Anna University Syllabus, 2017 Regulation
UNIT – 1
COMPUTATIONAL THINKING AND PROBLEM SOLVING
1
ARASU ENGINEERING COLLEGE
Department of CSE
OBJECTIVES:
P
To understand the basics of algorithmic problem solving.
S
To learn to solve problems using Python conditionals and loops.
P To define Python functions and use function calls to solve problems.
P To use Python data structures - lists, tuples, dictionaries to represent
U complex data.
N To do input/output with files in Python.
I
T
-I
ARASU ENGINEERING COLLEGE
Department of CSE
UNIT I ALGORITHMIC PROBLEM SOLVING 9
P
Fundamentals of Computing – Identification of Computational Problems
S
Algorithms, building blocks of algorithms (statements, state, control
P flow,functions), notation (pseudo code, flow chart, programming language),
P algorithmic problem solving, simple strategies for developing algorithms
U (iteration, recursion). Illustrative problems: find minimum in a list, insert a card
N in a list of sorted cards, guess an integer number in a range, Towers of Hanoi.
I UNIT II DATA, EXPRESSIONS, STATEMENTS 9
T Python interpreter and interactive mode; values and types: int, float, boolean,
string, and list; variables, expressions, statements, tuple assignment, precedence of
-I
operators, comments; modules and functions, function definition and use, flow of
execution, parameters and arguments; Illustrative programs: exchange the values
of two variables, circulate the values of n variables, distance between two points.
ARASU ENGINEERING COLLEGE
Department of CSE
UNIT III CONTROL FLOW, FUNCTIONS 9
P Conditionals: Boolean values and operators, conditional (if), alternative (if-else), chained
S conditional (if-elif-else); Iteration: state, while, for, break, continue, pass; Fruitful
P functions: return values, parameters, local and global scope, function composition,
P recursion; Strings: string slices, immutability, string functions and methods, string module;
Lists as arrays. Illustrative programs: square root, gcd, exponentiation, sum an array of
U
numbers, linear search, binary search.
N
I UNIT IV LISTS, TUPLES, DICTIONARIES 9
T Lists: list operations, list slices, list methods, list loop, mutability, aliasing, cloning lists, list
-I parameters; Tuples: tuple assignment, tuple as return value; Dictionaries: operations and
methods; advanced list processing - list comprehension; Illustrative programs: selection
sort, insertion sort, mergesort, histogram.
ARASU ENGINEERING COLLEGE
Department of CSE
UNIT VFILES, MODULES, PACKAGES 9
P Files and exception: text files, reading and writing files, format operator; command line
S arguments, errors and exceptions, handling exceptions, modules, packages; Illustrative
P programs: word count, copy file.
P TOTAL: 45 PERIODS
U
OUTCOMES:
N Upon completion of the course, students will be able to
I Develop algorithmic solutions to simple computational problems
T Read, write, execute by hand simple Python programs.
-I Structure simple Python programs for solving problems.
Decompose a Python program into functions.
Represent compound data using Python lists, tuples, dictionaries.
Read and write data from/to files in Python Programs.
ARASU ENGINEERING COLLEGE
Department of CSE
TEXT BOOKS:
P
Allen B. Downey, ``Think Python: How to Think Like a Computer Scientist’’, 2 nd
S
edition, Updated for Python 3, Shroff/O’Reilly Publishers, 2016 (
P http://greenteapress.com/wp/think- python/)
P Guido van Rossum and Fred L. Drake Jr, “An Introduction to Python – Revised and
U updated for Python 3.2, Network Theory Ltd., 2011.
N
I
T
-I
Introduction ARASU ENGINEERING COLLEGE
Department of CSE
P • Python is a widely used general-purpose, high level programming
S language.
P • It is an interpreter, object-oriented, high-level programming
P language.
U • It was created by Guido van Rossum in 1991 and further developed
N by the Python Software Foundation.
I • It was designed with an emphasis on code readability, and its syntax
allows programmers to express their concepts in fewer lines of code.
T
• Python is a programming language that work quickly and integrate
-I systems more efficiently.
Problem Solving Techniques ARASU ENGINEERING COLLEGE
Department of CSE
P • Problem solving technique is a set of methods which helps us to provide a logic
S for solving a problem or a given task.
P
• These problem-solving techniques can be defined by the following three
P components
U • Algorithm – step by step description of the solution.
N • Flowchart - diagrammatic representation of the solution.
I • Pseudocode – high-level description of an algorithm for the selected
solution.
T
-I • These three components can be expressed in the form of any programming
languages to give a proper solution of a particular task or a problem.
Algorithm ARASU ENGINEERING COLLEGE
Department of CSE
• “Algorithm is a step- by-step procedure for solving a task or a problem. It is an
P ordered sequence of finite, well defined, unambiguous instructions for
S completing a task.”
P • It is English like representation of the logic used to solve the problem.
P
Example: Algorithm to display a message
U
Step 1: Start
N
Step 2:Get/Read the message
I Step 3: Print the message
T Step 4: Stop
-I
Algorithm ARASU ENGINEERING COLLEGE
Department of CSE
P Simple python code to display a message
S
# Script Begins
P
A=input(“Enter a message”)
P
print(A)
U # Scripts Ends
N
I Output:
T Welcome to python
-I
Algorithm ARASU ENGINEERING COLLEGE
Department of CSE
P Find the largest among three different numbers
Step 1: Start
S
Step 2 : Read the variables a , b and c
P
Step 3 : If a>b
P
3.1 : If a>c
U 3.2 : Display a is the largest number.
N 3.3 : elif b>c
I 3.4 : Display b is the largest number.
T 3.5 : else
-I 3.6 : Display c is the greatest number.
Step 4 : Stop
Need of an Algorithm ARASU ENGINEERING COLLEGE
Department of CSE
P An algorithm serves variety purposes as followed
S
P • To understand the basic idea of the problem.
P • To find an approach to solve the problem.
U • To improve the efficiency of existing techniques.
N • To give a clear description of requirements and goal of the
problem to the designer.
I • To understand the flow of the problem.
T
-I
Characteristics of an Algorithm ARASU ENGINEERING COLLEGE
Department of CSE
1. Definiteness: Each step of an algorithm must be precisely defined; the actions to be
P carried out must be rigorously and unambiguously specified for each case.
S 2. Effectiveness: An algorithm is also generally expected to be effective. This means that
P each step of an algorithm must be feasible and it should not contain any unnecessary
or redundant steps which could make an algorithm ineffective.
P
3. Finiteness: An algorithm must always terminate after a finite number of steps.
U 4. Independent: An algorithm should have step-by-step directions, which should be
N independent of any programming language.
I 5. Input specified: The input is the data to be transformed during the computation to
produce the output. An algorithm should have 0 or more well-defined inputs.
T
6. Output specified: The output is the data resulting from the computation (your
-I intended result). An algorithm should have 1 or more well-defined outputs, and should
match the desired output.
7. Correctness: Finite steps in an algorithm must return a correct output for any given
input.
Steps for Developing an Algorithm ARASU ENGINEERING COLLEGE
Department of CSE
P • An algorithm is a plan for solving a problem.
S
• The development of an algorithm is a key step in solving a problem. Once we
P have an algorithm, we can translate it into a computer program in some
P programming languages.
U
N • The algorithm development process consists of five major steps.
I Step 1: Obtain a description of the problem.
T Step 2: Analyze the problem.
-I Step 3: Develop a high-level algorithm.
Step 4: Refine the algorithm by adding more detail.
Step 5: Review the algorithm.
Advantages and Disadvantages ARASU ENGINEERING COLLEGE
Department of CSE
P Advantages:
• Easy to understand
S
• Provides definite solution
P
• Independent of programming languages
P
• Easy to debug
U
Disadvantages:
N • Hard to design a logical problem
I • Need more knowledge to create a program
T • Difficult to represent branching and looping statements
-I • Take more time to convert as a program