1. Reference  2  Algorithm :- Outline the essence of a computational procedure, step by step instructions.  Program :- an.

Slides:



Advertisements
Similar presentations
MATH 224 – Discrete Mathematics
Advertisements

Functions in C++. Functions  Groups a number of program statements into a unit & gives it a name.  Is a complete and independent program.  Divides.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 Overview 7.1 Introduction to Arrays 7.2 Arrays in Functions 7.3.
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
Introduction to Analysis of Algorithms
Analysis of Algorithms Algorithm Input Output. Analysis of Algorithms2 Outline and Reading Running time (§1.1) Pseudo-code (§1.1) Counting primitive operations.
Analysis of Algorithms (Chapter 4)
Program Design and Development
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Introduction to Analysis of Algorithms Prof. Thomas Costello (reorganized by Prof. Karen Daniels)
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
VB .NET Programming Fundamentals
Review Algorithm Analysis Problem Solving Space Complexity
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
Describing algorithms in pseudo code To describe algorithms we need a language which is: – less formal than programming languages (implementation details.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Chapter 1 Algorithm Analysis
High-Level Programming Languages: C++
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
CIS Computer Programming Logic
1 R. Johnsonbaugh, Discrete Mathematics Chapter 4 Algorithms.
Data Structures & AlgorithmsIT 0501 Algorithm Analysis I.
Analysis of Algorithms1 Running Time Pseudo-Code Analysis of Algorithms Asymptotic Notation Asymptotic Analysis Mathematical facts.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Programming For Security Professionals March 23, 2010 MIS 4600 – MBA © Abdou Illia.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
1 Analysis of Algorithms CS 105 Introduction to Data Structures and Algorithms.
C++ Programming: Basic Elements of C++.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Introduction to Data Structures and Algorithms CS 110: Data Structures and Algorithms First Semester,
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Procedural programming in Java Methods, parameters and return values.
CHAPTER 10 ARRAYS AND FUNCTIONS Prepared by: Lec. Ghader Kurdi.
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
1 MODULAR DESIGN AND ABSTRACTION. 2 SPECIFYING THE DETAILS OF A PROBLEM INTO A RELATED SET OF SMALLER PROBLEMS.
Recap……Last Time [Variables, Data Types and Constants]
Data Structures & Algorithms CHAPTER 1 Introduction Ms. Manal Al-Asmari.
Controlling Program Flow with Decision Structures.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
A Sample Program #include using namespace std; int main(void) { cout
CS 1428 Final Exam Review. Exam Format 200 Total Points – 60 Points Writing Programs – 45 Points Tracing Algorithms and determining results – 20 Points.
Lecture 2. Algorithms and Algorithm Convention 1.
Chapter Topics The Basics of a C++ Program Data Types
REPETITION CONTROL STRUCTURE
Data Structures and Algorithms
GC211Data Structure Lecture2 Sara Alhajjam.
Basic Elements of C++.
Introduction to C++.
Computer Programming Methodology Introduction to Java
Basic Elements of C++ Chapter 2.
Describing algorithms in pseudo code
Programming Funamental slides
Programming Funamental slides
CS 1428 Final Exam Review.
Some slides are borrowed from Mr. Mohammad Alqahtani
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Revision of C++.
Fundamental Programming
Analysis of Algorithms
Course Outcomes of Programming In C (PIC) (17212, C203):
Presentation transcript:

1

Reference  2

 Algorithm :- Outline the essence of a computational procedure, step by step instructions.  Program :- an implementation of an algorithm in some programming language  Data Structure :- Organization of data needed to solve the problem. 3

Algorithm: Finite set of instructions that, if followed, accomplishes a particular task. Describe : Representation of algorithm can written By :- in natural language ( English ) / pseudo-code / diagrams / etc. 4

Any computing algorithm will have AT MOST five kinds of components: Data structures to hold data Instructions change data values Conditional expressions to make decisions Control structures to act on decisions Modules to make the algorithm manageable by abstraction, i.e., grouping related components 5

6 Relations between Problems, Algorithms and Programs Problem Algorithm Program....

What is a Good Algorithm ?  Efficient :-  Running Time  Space Used  Efficiency as function of input size :-  The number of bits in an input number  Number of data elements ( numbers, points ) 7

8 W ORST - / AVERAGE - / BEST - CASE Worst-case running time of an algorithm  The longest running time for any input of size n  An upper bound on the running time for any input  guarantee that the algorithm will never take longer  Example: Sort a set of numbers in increasing order; and the data is in decreasing order  The worst case can occur fairly often E.g. in searching a database for a particular piece of information Best-case running time sort a set of numbers in increasing order; and the data is already in increasing order Average-case running time Average number of steps taken on any instance of size n

9 Pseudo- code :- A mixture of natural language and high – level programming concepts that describes the main ideas behind a generic implementation of a data structure or algorithm Eg:- Algorithm arrayMax ( A, n ) input : An array A sorting n integers Output : The Maximum element in A currentMax A[0] for i 1 to n-1 do if currentMax < A[i] then currentMax A[i] return currentMax

Pseudo – Code It is more structured than usual language but less formal than a programming language. Expressions :  Use standard mathematical symbols to describe numeric and Boolean expression.  Use for assignment ( “=“ in java )  Use = for the equality relationship( “==“ in java ) 10

Pseudo- Code  Programming Constructs :-  decision structures :- if …. Then … [ else ]  while – loops : while.. Do  repeat – loops : repeat … until..  for – loop : for.. Do  array indexing : A[i], A[I,j]  Methods :  Calls : object method ( args )  returns : return value 11

Simple Algorithm Find sum n numbers between any given range numbers 1- Start 2- Read N 3- Sum =0 4- For I= 1 to N 4.1 sum = sum + I 4.1 next I 5- print Sum 6- End 12

Basic Structure of C++ Language 13 Documentation Section Link Section Definition Section Global Declaration Section Subprogram Section Function 1 ….. Function n main(){ Declaration Section Executable Section }

14 Language Built-inUser-defined Data Operators Assignment ( = ) Arithmetic (+,-,*,/,%) Relational (, >=,==,!=) Logical (&&, ||) Unary (++, --) DataOperators Atomic int (2 bytes) char (1 byte) float (4 bytes) double (8 bytes)

Tokens The smallest element in the C language is the token. Tokens can be: Numeric constants : 123, 98.6, Character constants : ‘A’, ‘a’, ‘$’, ‘4’ String constants : “UMBC”, “I like ice cream.”, “123”, “CAR”, “car” Keywords : int, while, for Names (identifiers) Punctuation : ; :, ‘ “ [ ] { } ( ) Operators: =, +, -, *, /, <>,, >=, !=, &&, ||, ++, --

Simple C++Program /*---- Hello World C Example ("hello.c") */ /* ANSI C Headers */ #include /* Main Program starts here */ void main ( ) { int i = 0; /* End of declarations... */ for ( i = 0; i < 10; i++ ) { cout<<“ Hello World”<<endl<< i ); /* print to standard output */ } 15 Include headers if you need to use functions in these files Comment: /*.. */ Declare all your variables first

Control Statement SelectionIterationJump IfForBreak SwitchWhileContinue …………Do- whileReturn 16

Eg:- to calculate the average of n number /*Calculate the average of n numbers*/ #include void main(){ int n, count=1; float x, average,sum=0; cout<<"Enter the limit”<<endl; /*initialize and read in a value for n*/ cin>>n; while(count<=n) /*Read in the numbers*/ { cout<<"x= “; cin>>x; sum+=x; ++count; } /*calculate the average and display result*/ average=sum/n; cout<<“The average is ”<<average; getch();} 17

While Syntax :- While (Expression ) { Statement (s ) Increment counter } Do – while Syntax :- Do { statement(s) Counter } While(expression ); 18

Functions A function is a self contained program segment that carries out some specific,well-defined task. C regards main() as function Functions should be defined separately before or after main. A function will process information that is passed to it from the calling program and return a single value Each function contains: A function heading (function name), followed by optional list of arguments enclosed in parentheses. A list of argument declarations A compound statement enclosed within a pair of braces { } 19

Functions Cont.. Function Definition: returntype fn_name(type1 arg1,type2 arg2, …..type n,arg n) { localvariables functioncode } Example: int maximum(int x, int y) { int z; z=(x>=y) ? x:y; return(z);} Calling A function: function-name(arg1,arg2,….arg n); Function Prototype: returntype fn_name(type1 arg1,type2 arg2, …..type n,arg n);

C ++ Program illustrating Function /*Program to calculate the area of a circle*/ #include const float PI= 3.14; float areacircle( float radius) ; /* function prototype*/ main() { float radius, area; cout<<"Enter value of radius“<<endl; cin>>radius; area=areacircle(radius); /* call function */ cout<<“Area= “<<area ; getch(); } float areacircle(float r) { /* definition of function */ a= PI*r*r; return(a); } 20

Assignment -1- Write algorithm for the following  sum of n numbers between given range ( Using while )  sum of n numbers between given range ( Using Do… while )  count even& odd numbers in given range( Using For )  count even & odd numbers in given range( Using while )  count even & odd numbers in given range(Using Do.. while) 21