The document provides an introduction to algorithms and computer programming. It defines an algorithm as a step-by-step procedure for solving a problem. It also discusses key algorithm concepts like decomposition, abstraction, and problem solving techniques such as divide and conquer. The document presents examples of algorithms using pseudocode and flowcharts. It explains different representations of algorithms and how to trace an algorithm's execution using a trace table.
This document provides an overview of the topics covered in Unit V: Linear Programming. It begins with an introduction to operations research and some example problems that can be modeled as linear programs. It then discusses formulations of linear programs, including the standard and slack forms. The document outlines the simplex algorithm for solving linear programs and how to convert between standard and slack forms. It provides examples demonstrating these concepts. The key topics covered are linear programming models, formulations, and the simplex algorithm.
The document discusses the simplex algorithm for solving linear programming problems. It begins with an introduction and overview of the simplex algorithm. It then describes the key steps of the algorithm, which are: 1) converting the problem into slack format, 2) constructing the initial simplex tableau, 3) selecting the pivot column and calculating the theta ratio to determine the departing variable, 4) pivoting to create the next tableau. The document provides examples to illustrate these steps. It also briefly discusses cycling issues, software implementations, efficiency considerations and variants of the simplex algorithm.
- The document discusses linear programming models and their use in business analytics and decision making.
- It provides an overview of linear programming, including its basic assumptions, requirements, and how to formulate linear programming problems.
- As an example, it formulates the linear programming problem of Flair Furniture Company, which seeks to maximize profit by determining the optimal production mix of tables and chairs given resource constraints.
- Graphical and Excel solutions to the Flair Furniture problem are presented to illustrate how to solve linear programming problems.
The document provides an introduction to the analysis of algorithms. It discusses key concepts like the definition of an algorithm, properties of algorithms, common computational problems, and basic issues related to algorithms. It also covers algorithm design strategies, fundamental data structures, and the fundamentals of analyzing algorithm efficiency. Examples of algorithms for computing the greatest common divisor and checking for prime numbers are provided to illustrate algorithm design and analysis.
The steps of the simplex method for solving a linear programming problem are:
1) Convert the problem to one of maximization and make the right-hand sides of constraints non-negative.
2) Introduce slack/surplus variables to convert inequalities to equations.
3) Obtain an initial basic feasible solution and compute net evolutions.
4) If a negative net evolution exists, select the most negative column and row ratios to identify a new basis.
5) Iterate steps 5-8 until an optimum solution is found or the problem is determined to be unbounded.
The document provides an outline of topics related to linear programming, including:
1) An introduction to linear programming models and examples of problems that can be solved using linear programming.
2) Developing linear programming models by determining objectives, constraints, and decision variables.
3) Graphical and simplex methods for solving linear programming problems.
4) Using a simplex tableau to iteratively solve a sample product mix problem to find the optimal solution.
This document provides information about operation research and the graphical method for solving linear programming problems. It defines operation research and describes the general structure of a linear programming model, which includes decision variables, the objective function, and constraints. The document then formulates a sample linear programming problem and provides the step-by-step graphical solution, identifying the feasible region and finding the optimal solution that maximizes the objective function.
This document provides an introduction to linear programming. It defines linear programming as a mathematical modeling technique used to optimize resource allocation. The key requirements are a well-defined objective function, constraints on available resources, and alternative courses of action represented by decision variables. The assumptions of linear programming include proportionality, additivity, continuity, certainty, and finite choices. Formulating a problem as a linear program involves defining the objective function and constraints mathematically. Graphical and analytical solutions can then be used to find the optimal solution. Linear programming has many applications in fields like industrial production, transportation, and facility location.
This document provides an overview of the topics covered in Unit V: Linear Programming. It begins with an introduction to operations research and some example problems that can be modeled as linear programs. It then discusses formulations of linear programs, including the standard and slack forms. The document outlines the simplex algorithm for solving linear programs and how to convert between standard and slack forms. It provides examples demonstrating these concepts. The key topics covered are linear programming models, formulations, and the simplex algorithm.
The document discusses the simplex algorithm for solving linear programming problems. It begins with an introduction and overview of the simplex algorithm. It then describes the key steps of the algorithm, which are: 1) converting the problem into slack format, 2) constructing the initial simplex tableau, 3) selecting the pivot column and calculating the theta ratio to determine the departing variable, 4) pivoting to create the next tableau. The document provides examples to illustrate these steps. It also briefly discusses cycling issues, software implementations, efficiency considerations and variants of the simplex algorithm.
- The document discusses linear programming models and their use in business analytics and decision making.
- It provides an overview of linear programming, including its basic assumptions, requirements, and how to formulate linear programming problems.
- As an example, it formulates the linear programming problem of Flair Furniture Company, which seeks to maximize profit by determining the optimal production mix of tables and chairs given resource constraints.
- Graphical and Excel solutions to the Flair Furniture problem are presented to illustrate how to solve linear programming problems.
The document provides an introduction to the analysis of algorithms. It discusses key concepts like the definition of an algorithm, properties of algorithms, common computational problems, and basic issues related to algorithms. It also covers algorithm design strategies, fundamental data structures, and the fundamentals of analyzing algorithm efficiency. Examples of algorithms for computing the greatest common divisor and checking for prime numbers are provided to illustrate algorithm design and analysis.
The steps of the simplex method for solving a linear programming problem are:
1) Convert the problem to one of maximization and make the right-hand sides of constraints non-negative.
2) Introduce slack/surplus variables to convert inequalities to equations.
3) Obtain an initial basic feasible solution and compute net evolutions.
4) If a negative net evolution exists, select the most negative column and row ratios to identify a new basis.
5) Iterate steps 5-8 until an optimum solution is found or the problem is determined to be unbounded.
The document provides an outline of topics related to linear programming, including:
1) An introduction to linear programming models and examples of problems that can be solved using linear programming.
2) Developing linear programming models by determining objectives, constraints, and decision variables.
3) Graphical and simplex methods for solving linear programming problems.
4) Using a simplex tableau to iteratively solve a sample product mix problem to find the optimal solution.
This document provides information about operation research and the graphical method for solving linear programming problems. It defines operation research and describes the general structure of a linear programming model, which includes decision variables, the objective function, and constraints. The document then formulates a sample linear programming problem and provides the step-by-step graphical solution, identifying the feasible region and finding the optimal solution that maximizes the objective function.
This document provides an introduction to linear programming. It defines linear programming as a mathematical modeling technique used to optimize resource allocation. The key requirements are a well-defined objective function, constraints on available resources, and alternative courses of action represented by decision variables. The assumptions of linear programming include proportionality, additivity, continuity, certainty, and finite choices. Formulating a problem as a linear program involves defining the objective function and constraints mathematically. Graphical and analytical solutions can then be used to find the optimal solution. Linear programming has many applications in fields like industrial production, transportation, and facility location.
This document provides an introduction to linear programming models. It discusses key components of linear models including decision variables, objective functions, and constraints. It then presents a prototype example of using linear programming to optimize production levels at Galaxy Industries. The optimal solution is found using Excel Solver and sensitivity analysis is performed to analyze how changes impact the optimal solution. Various scenarios where models may not have a unique optimal solution are also discussed.
This document discusses duality in linear programming. It defines the dual problem as another linear program systematically constructed from the original or primal problem, such that the optimal solutions of one provide the optimal solutions of the other. The document provides rules for constructing the dual problem based on whether the primal problem is a maximization or minimization problem. It also gives examples of writing the dual of a primal problem and solving both problems to verify the optimal objective values are equal. Finally, it discusses economic interpretations of duality and the relationship between primal and dual problems and solutions.
Linear programming is a technique for choosing the best alternative from a set of feasible alternatives by expressing the objective function and constraints as linear mathematical functions. It requires a clear objective, quantitative terms, identifiable constraints, and feasible alternative choices. The objective functions and constraints define a feasible region, and the simplex method is an iterative algorithm that generates corner point solutions to find the optimal solution at an extreme point of the feasible region. It works by maintaining a basic feasible solution and performing elementary row operations at each iteration to improve the objective function value until reaching the optimal solution.
This document discusses representing the logic of programs with conditions using flowcharts. It covers variables, constants, data types, operators, and decision structures. Examples are provided to demonstrate how to represent accepting input, performing calculations, and making conditional decisions in a flowchart. Key topics include declaring variables, arithmetic, relational and logical operators, and using decision boxes to apply conditions.
This document provides an overview of linear programming models and techniques. It discusses the basic assumptions and requirements of linear programming problems, including having an objective function to maximize or minimize, constraints, alternative courses of action, and linear expressions. The document then covers how to formulate a linear programming problem by understanding the problem, identifying the objective and constraints, defining decision variables, and writing mathematical expressions. It provides an example problem involving determining the optimal product mix for a furniture company. Finally, it discusses solutions methods for linear programming problems, including graphical methods of analyzing the feasible region and using isoprofit lines or analyzing corner points to find the optimal solution.
This document discusses linear programming (LP) and how to formulate and solve LP problems graphically. LP is used to help managers allocate limited resources optimally. All LP problems seek to maximize or minimize an objective function subject to constraints. The document presents an example of formulating an LP problem for a furniture company to determine the optimal product mix to maximize profit. It shows how to graphically represent the constraints and objective function and find the optimal solution by using isoprofit lines or evaluating the objective function at each corner point of the feasible region. The optimal solution for the furniture company problem is 30 tables and 40 chairs for a maximum profit of $4,100.
This document discusses linear programming techniques for managerial decision making. Linear programming can determine the optimal allocation of scarce resources among competing demands. It consists of linear objectives and constraints where variables have a proportionate relationship. Essential elements of a linear programming model include limited resources, objectives to maximize or minimize, linear relationships between variables, homogeneity of products/resources, and divisibility of resources/products. The linear programming problem is formulated by defining variables and constraints, with the objective of optimizing a linear function subject to the constraints. It is then solved using graphical or simplex methods through an iterative process to find the optimal solution.
The document provides information about linear programming problems (LPP), including:
- LPPs involve optimization of a linear objective function subject to linear constraints.
- Graphical and algebraic methods can be used to find the optimal solution, which must occur at a corner point of the feasible region.
- The simplex method is an algorithm that moves from one corner point to another to optimize the objective function.
- Examples are provided to illustrate LPP formulation, graphical solution, and use of the simplex method to iteratively find an optimal solution.
The document provides an overview of algorithms and data structures. It discusses what an algorithm is, different algorithm design strategies, approaches to analyzing algorithms, and key computational problems like sorting, searching, and graph problems. It also covers fundamental data structures like lists, stacks, queues, and trees. Major sections include introductions to algorithms, analysis of algorithms, problem solving techniques, and linear and non-linear data structures.
The document discusses algorithms and their analysis. It begins by defining an algorithm and listing requirements like being unambiguous and finite. It describes writing algorithms using pseudocode or flowcharts and proving their correctness. The document then discusses analyzing algorithms by measuring their time and space efficiency using orders of growth. It explains analyzing best, worst, and average cases and counting basic operations. Finally, it provides examples of analyzing simple algorithms involving if statements and loops.
Numerical analysis dual, primal, revised simplexSHAMJITH KM
The document discusses linear programming optimization methods including the revised simplex method, duality of LP problems, dual simplex method, and sensitivity analysis. It provides details on the iterative steps of the revised and dual simplex methods. Examples are provided to illustrate finding the dual of a primal LP problem and solving the dual using the dual simplex method. Sensitivity analysis is introduced as examining how changes to coefficients or right-hand sides can impact optimality and feasibility.
This document discusses different ways to classify optimization problems. It describes classifications based on:
1) The existence of constraints - problems are either constrained or unconstrained.
2) The nature of design variables - problems involve either parameter/static optimization or trajectory/dynamic optimization.
3) The physical structure - problems are either optimal control problems or non-optimal control problems.
4) The nature of equations - problems involve linear, nonlinear, geometric, or quadratic equations.
5) The permissible variable values - problems have either integer/discrete or real-valued variables.
6) The variable determinism - problems have either deterministic or stochastic/probabilistic variables.
7) The function
This document contains a question bank with multiple choice questions related to operations research. It covers topics in linear programming problems (LPP) such as the definition of an LPP, feasible solutions, graphical representation, simplex method, objective functions, constraints, unbounded/bounded solutions, degenerate solutions, and slack and surplus variables. There are 27 total multiple choice questions across two units related to modeling problems as LPPs and using the simplex method to solve LPPs.
The document discusses stochastic control for optimal dynamic trading strategies. It examines Merton's portfolio problem in various market models using dynamic programming. Specifically:
- It applies dynamic programming to solve Merton's portfolio problem in the Black-Scholes model under different utility functions, showing the optimal strategy is to hold a constant proportion of wealth in the risky asset.
- It also examines the problem with stochastic volatility, finding the problem can still be solved explicitly through a non-stochastic function of time.
- A brief overview presents the difficulties introduced by incorporating transaction costs into the model.
This document discusses operators and expressions in C programming. It defines expressions as combinations of constants, variables, and functions that have a value and type. Various types of operators are covered, including arithmetic, relational, logical, assignment, and unary operators. Key points about operator precedence and associativity are explained. Examples of expressions using different operators are provided to illustrate concepts.
This document discusses the process of problem solving through programming. It begins by defining an algorithm as a sequence of instructions to solve a problem and a program as an algorithm expressed in a language a computer can understand. It then outlines the programming process of analyzing a problem to determine the input and output, planning an algorithm using tools like IPO charts and pseudocode, and coding the algorithm. It provides examples of analyzing problems, planning algorithms, and desk-checking algorithms on sample data.
The document discusses algorithms and how to represent them using pseudocode and flowcharts. It provides examples of algorithms to calculate student grades and averages, and represents them in pseudocode and flowcharts. The key steps are to define the inputs, processing such as calculations, and outputs. Pseudocode uses a natural language format while flowcharts use graphical symbols to depict the program logic and flow.
The document discusses problem solving skills in computer programming. It explains the four basic operations of input, output, processing, and storage. It provides examples of how each operation is represented in pseudocode. The document also outlines the steps for problem solving, including defining the problem, creating an algorithm using pseudocode, and implementing the algorithm in a programming language. It provides examples of algorithms and flowcharts to illustrate problem solving techniques.
This document provides an introduction to flowcharting and algorithms. It discusses the basic components of flowcharts like terminals, input/output operations, processes, and different flowchart structures like sequence, decision, repetition, and case. It also compares flowcharts and pseudocode as ways to represent algorithms independent of programming language. Examples of each flowchart structure are provided. The document emphasizes that flowcharts provide a visual representation of the flow or steps in a process to solve a problem.
The document provides an overview of general problem-solving concepts and programming tools used for problem-solving. It discusses types of problems, problem-solving strategies like top-down design, and program design tools like algorithms, flowcharts, and pseudocode. It also provides basics of the Python programming language, including its features, history, and how to write and execute a Python program.
This document provides an introduction to linear programming models. It discusses key components of linear models including decision variables, objective functions, and constraints. It then presents a prototype example of using linear programming to optimize production levels at Galaxy Industries. The optimal solution is found using Excel Solver and sensitivity analysis is performed to analyze how changes impact the optimal solution. Various scenarios where models may not have a unique optimal solution are also discussed.
This document discusses duality in linear programming. It defines the dual problem as another linear program systematically constructed from the original or primal problem, such that the optimal solutions of one provide the optimal solutions of the other. The document provides rules for constructing the dual problem based on whether the primal problem is a maximization or minimization problem. It also gives examples of writing the dual of a primal problem and solving both problems to verify the optimal objective values are equal. Finally, it discusses economic interpretations of duality and the relationship between primal and dual problems and solutions.
Linear programming is a technique for choosing the best alternative from a set of feasible alternatives by expressing the objective function and constraints as linear mathematical functions. It requires a clear objective, quantitative terms, identifiable constraints, and feasible alternative choices. The objective functions and constraints define a feasible region, and the simplex method is an iterative algorithm that generates corner point solutions to find the optimal solution at an extreme point of the feasible region. It works by maintaining a basic feasible solution and performing elementary row operations at each iteration to improve the objective function value until reaching the optimal solution.
This document discusses representing the logic of programs with conditions using flowcharts. It covers variables, constants, data types, operators, and decision structures. Examples are provided to demonstrate how to represent accepting input, performing calculations, and making conditional decisions in a flowchart. Key topics include declaring variables, arithmetic, relational and logical operators, and using decision boxes to apply conditions.
This document provides an overview of linear programming models and techniques. It discusses the basic assumptions and requirements of linear programming problems, including having an objective function to maximize or minimize, constraints, alternative courses of action, and linear expressions. The document then covers how to formulate a linear programming problem by understanding the problem, identifying the objective and constraints, defining decision variables, and writing mathematical expressions. It provides an example problem involving determining the optimal product mix for a furniture company. Finally, it discusses solutions methods for linear programming problems, including graphical methods of analyzing the feasible region and using isoprofit lines or analyzing corner points to find the optimal solution.
This document discusses linear programming (LP) and how to formulate and solve LP problems graphically. LP is used to help managers allocate limited resources optimally. All LP problems seek to maximize or minimize an objective function subject to constraints. The document presents an example of formulating an LP problem for a furniture company to determine the optimal product mix to maximize profit. It shows how to graphically represent the constraints and objective function and find the optimal solution by using isoprofit lines or evaluating the objective function at each corner point of the feasible region. The optimal solution for the furniture company problem is 30 tables and 40 chairs for a maximum profit of $4,100.
This document discusses linear programming techniques for managerial decision making. Linear programming can determine the optimal allocation of scarce resources among competing demands. It consists of linear objectives and constraints where variables have a proportionate relationship. Essential elements of a linear programming model include limited resources, objectives to maximize or minimize, linear relationships between variables, homogeneity of products/resources, and divisibility of resources/products. The linear programming problem is formulated by defining variables and constraints, with the objective of optimizing a linear function subject to the constraints. It is then solved using graphical or simplex methods through an iterative process to find the optimal solution.
The document provides information about linear programming problems (LPP), including:
- LPPs involve optimization of a linear objective function subject to linear constraints.
- Graphical and algebraic methods can be used to find the optimal solution, which must occur at a corner point of the feasible region.
- The simplex method is an algorithm that moves from one corner point to another to optimize the objective function.
- Examples are provided to illustrate LPP formulation, graphical solution, and use of the simplex method to iteratively find an optimal solution.
The document provides an overview of algorithms and data structures. It discusses what an algorithm is, different algorithm design strategies, approaches to analyzing algorithms, and key computational problems like sorting, searching, and graph problems. It also covers fundamental data structures like lists, stacks, queues, and trees. Major sections include introductions to algorithms, analysis of algorithms, problem solving techniques, and linear and non-linear data structures.
The document discusses algorithms and their analysis. It begins by defining an algorithm and listing requirements like being unambiguous and finite. It describes writing algorithms using pseudocode or flowcharts and proving their correctness. The document then discusses analyzing algorithms by measuring their time and space efficiency using orders of growth. It explains analyzing best, worst, and average cases and counting basic operations. Finally, it provides examples of analyzing simple algorithms involving if statements and loops.
Numerical analysis dual, primal, revised simplexSHAMJITH KM
The document discusses linear programming optimization methods including the revised simplex method, duality of LP problems, dual simplex method, and sensitivity analysis. It provides details on the iterative steps of the revised and dual simplex methods. Examples are provided to illustrate finding the dual of a primal LP problem and solving the dual using the dual simplex method. Sensitivity analysis is introduced as examining how changes to coefficients or right-hand sides can impact optimality and feasibility.
This document discusses different ways to classify optimization problems. It describes classifications based on:
1) The existence of constraints - problems are either constrained or unconstrained.
2) The nature of design variables - problems involve either parameter/static optimization or trajectory/dynamic optimization.
3) The physical structure - problems are either optimal control problems or non-optimal control problems.
4) The nature of equations - problems involve linear, nonlinear, geometric, or quadratic equations.
5) The permissible variable values - problems have either integer/discrete or real-valued variables.
6) The variable determinism - problems have either deterministic or stochastic/probabilistic variables.
7) The function
This document contains a question bank with multiple choice questions related to operations research. It covers topics in linear programming problems (LPP) such as the definition of an LPP, feasible solutions, graphical representation, simplex method, objective functions, constraints, unbounded/bounded solutions, degenerate solutions, and slack and surplus variables. There are 27 total multiple choice questions across two units related to modeling problems as LPPs and using the simplex method to solve LPPs.
The document discusses stochastic control for optimal dynamic trading strategies. It examines Merton's portfolio problem in various market models using dynamic programming. Specifically:
- It applies dynamic programming to solve Merton's portfolio problem in the Black-Scholes model under different utility functions, showing the optimal strategy is to hold a constant proportion of wealth in the risky asset.
- It also examines the problem with stochastic volatility, finding the problem can still be solved explicitly through a non-stochastic function of time.
- A brief overview presents the difficulties introduced by incorporating transaction costs into the model.
This document discusses operators and expressions in C programming. It defines expressions as combinations of constants, variables, and functions that have a value and type. Various types of operators are covered, including arithmetic, relational, logical, assignment, and unary operators. Key points about operator precedence and associativity are explained. Examples of expressions using different operators are provided to illustrate concepts.
This document discusses the process of problem solving through programming. It begins by defining an algorithm as a sequence of instructions to solve a problem and a program as an algorithm expressed in a language a computer can understand. It then outlines the programming process of analyzing a problem to determine the input and output, planning an algorithm using tools like IPO charts and pseudocode, and coding the algorithm. It provides examples of analyzing problems, planning algorithms, and desk-checking algorithms on sample data.
The document discusses algorithms and how to represent them using pseudocode and flowcharts. It provides examples of algorithms to calculate student grades and averages, and represents them in pseudocode and flowcharts. The key steps are to define the inputs, processing such as calculations, and outputs. Pseudocode uses a natural language format while flowcharts use graphical symbols to depict the program logic and flow.
The document discusses problem solving skills in computer programming. It explains the four basic operations of input, output, processing, and storage. It provides examples of how each operation is represented in pseudocode. The document also outlines the steps for problem solving, including defining the problem, creating an algorithm using pseudocode, and implementing the algorithm in a programming language. It provides examples of algorithms and flowcharts to illustrate problem solving techniques.
This document provides an introduction to flowcharting and algorithms. It discusses the basic components of flowcharts like terminals, input/output operations, processes, and different flowchart structures like sequence, decision, repetition, and case. It also compares flowcharts and pseudocode as ways to represent algorithms independent of programming language. Examples of each flowchart structure are provided. The document emphasizes that flowcharts provide a visual representation of the flow or steps in a process to solve a problem.
The document provides an overview of general problem-solving concepts and programming tools used for problem-solving. It discusses types of problems, problem-solving strategies like top-down design, and program design tools like algorithms, flowcharts, and pseudocode. It also provides basics of the Python programming language, including its features, history, and how to write and execute a Python program.
Identify and explain the problem-solving steps. • Compare/contrast ideas within algorithms (pseudo-code and Flowcharts) to apply logical thinking in problem-solving.
The document provides information about the COMP 102 Programming I course for spring 2012. It includes the instructor's contact information, class meeting times, grading criteria, attendance policy, and academic honesty policy. It also lists the topics that will be covered in the course, such as programming concepts, flowcharts, pseudocode, and Java programming.
The document provides an introduction to basic computer programming concepts such as what a computer is, how it works, its parts, programming, and problem solving steps. It then gives examples of writing algorithms, pseudocode, and flowcharts to solve problems such as calculating the area of a rectangle and determining a student's final grade. The document concludes with an introduction to programming fundamentals and methods.
The document provides an introduction to problem solving and programming fundamentals. It defines a computer program as a set of instructions that directs a computer to solve a problem. The document outlines a four-step problem solving process of understanding the problem, devising a plan, carrying out the plan, and looking back. It also discusses analyzing a problem by identifying inputs, outputs, processing, and storage. The design phase involves developing an algorithm to solve the problem. Debugging addresses fixing syntax, runtime, and semantic errors in a program.
The document discusses algorithms, flowcharts, and problem solving. It provides examples of writing pseudocode and algorithms to solve problems. It also explains the basic symbols used in flowcharts and provides examples of flowcharts. Key points include:
- Algorithms are step-by-step solutions to problems, while flowcharts show the logic visually using standard symbols.
- Pseudocode is an informal language similar to English that helps develop algorithms.
- Examples show algorithms and flowcharts for calculating grades, converting feet to centimeters, and finding the area of a rectangle.
- Standard flowchart symbols include shapes for start/end, processes, inputs/outputs, and decisions.
Basic Slides on Algorithms and Flowchartsmoazwinner
This document discusses algorithms, flowcharts, and problem solving. It provides examples of writing pseudocode algorithms and creating corresponding flowcharts. Key points:
- Algorithms are step-by-step solutions to problems, while flowcharts use symbols to visually represent algorithm logic and flow.
- Pseudocode uses everyday language to describe algorithms before implementation.
- Common flowchart symbols include shapes for start/end, input/output, decisions, and processes connected by arrows showing flow.
- Examples show algorithms and flowcharts for calculating grades, converting units, finding a rectangle area, and other problems.
The document discusses algorithms and flowcharts. It defines algorithms as step-by-step solutions to problems and flowcharts as graphical representations of algorithms using standard symbols. It provides examples of pseudocode algorithms and corresponding flowcharts to calculate student grades, convert between feet and centimeters, and calculate rectangle area. The key flowchart symbols are defined including start/end, input/output, decision, and process symbols connected by flow lines.
The document provides information on problem solving and office automation. It discusses key concepts like algorithms, program development cycles, and control structures. For algorithms, it covers characteristics, representations using flowcharts and pseudocode, and examples. The main program development methodologies covered are the program planning method and waterfall method. Control structures discussed include sequence, selection, and looping. Examples provided include finding largest of three numbers, quadratic equation, swapping variables, and checking leap year.
The document provides information on problem solving and office automation. It discusses key concepts like algorithms, program development cycles, and control structures. For algorithms, it covers characteristics, representations using flowcharts and pseudocode, and examples. The main program development methodologies covered are the program planning method and waterfall method. Control structures discussed include sequence, selection, and looping. Examples provided include finding largest of three numbers, quadratic equation, swapping variables, and checking leap year.
The document summarizes the topics covered in an introduction to programming and problem solving lecture, including: 1) the six basic computer operations, 2) what programming is and the steps of program development, 3) structured programming and the three main control structures (sequence, selection, repetition), 4) data and data structures, and 5) two examples (calculating the area and circumference of a circle and solving a payroll problem) to illustrate the concepts.
algorithms and flow chart overview.pdfAmanPratik11
This document discusses algorithms, flowcharts, and pseudocode. It provides examples of algorithms and flowcharts to calculate a student's grade, convert feet to centimeters, calculate the area of a rectangle, and find the roots of a quadratic equation. Algorithms are step-by-step solutions to problems, while flowcharts use graphical symbols to represent the logic and steps of an algorithm. Pseudocode is an informal language that helps develop algorithms. The document also lists common flowchart symbols and provides exercises to create algorithms and flowcharts.
The document discusses algorithms and flowcharts. It defines an algorithm as a finite set of steps to solve a problem and notes that algorithms can be expressed in various ways, including pseudocode and flowcharts. Pseudocode uses a language similar to programming but without specific syntax, making it readable by programmers familiar with different languages. A flowchart provides a graphical representation of an algorithm's logical flow. The document provides examples of algorithms expressed in pseudocode and represented through flowcharts, such as finding the average of two numbers and calculating the largest of several inputs. It also discusses common flowchart structures like sequence, selection, and iteration.
This document provides an introduction to the CS-701 Advanced Analysis of Algorithms course. It includes the course objectives, which are to design and analyze modern algorithms and evaluate their efficiency. The instructor and contact information are provided. The document outlines the course contents, including topics like sorting algorithms, graph algorithms, and complexity theory. It also discusses what algorithms are, how to represent them, and examples of algorithm applications. Common algorithm design techniques like greedy algorithms and heuristics are introduced.
1. Introduction To Computer Science
(ITC)
Lecture 05
Introduction to Algorithms
24 September 2012
Instructor: Adeela Waqar
adeela.waqar@nu.edu.pk, adeela.abbas@gmail.com
National University of Computer and Emerging Sciences, Islamabad
1
2. Algorithm
Algorithm is a step by step procedure for solving a
problem
It represents a process that a computer carries
out, in order to complete a well defined task
The objective of computer science is to solve
problems by developing, analyzing, and
implementing algorithmic solutions
2
3. Al-Khwarizmi Principle
• All complex problems can be broken into
simpler sub-problems.
• Solve a complex problem by breaking it down
into smaller sub-problems and then solve them
(in a specified order), one at a time.
• When all the steps are solved, the original
problem itself has also been solved.
• This process is called Algorithm.
(Originating from al-Khwārizmī)
3
4. Computer Programming
• Computer is a powerful tool
• It is not intelligent!
• In order to use computer to solve our problems,
we must tell it what we want done and the order
in which we want it done.
• These instructions are called computer program.
• Writing these instructions is called computer
programming.
• The person giving these instructions is called a
computer programmer.
4
5. Computer Programming
• Analyze the problem
• Develop a sequence of instructions for
solving the problem.
• Communicate it to the computer.
5
6. Phases of the software life cycle
• Requirement definition
• Analysis and design
• Coding
• Testing
• Implementation
• Maintenance
6
7. Problem Solving Techniques
• Ask questions
• Look for things that are similar
• Means-ends analysis
• Divide and Conquer
• Merging solutions
7
8. Ask Questions
• Ask questions until you have developed a clear
understanding of the problem.
• Who, What, Why, Where, When.
– What do I have to work with? (my data or input)
– How much data is there?
– What should my output look like?
– How many times is the process going to be
repeated?
– What are the exceptions to the main course?
– What special error condition might come up?
8
9. Look for things that are Similar
• Do not reinvent the wheel!
• Draw Analogies
9
10. Means-Ends analysis
• Starting point and ending state are known.
• You need to devise the transformation
function.
• Ends are defined – you need to analyze
your means of getting between them.
• Lahore to Islamabad
– What are the options?
– Narrow down the options?
– Figure out the details?
10
11. Divide and Conquer
• Same as the Al-khwarizmi Principle.
• Breakup the large problem into smaller
units and then solve them one at a time.
• Building block approach.
11
12. Divide and Conquer
Hard Problem
Easy Sub-problem Hard Sub-problem Easy Sub-problem
Easy Sub-problem Easy Sub-problem
12
13. Merging Solution
• Sometimes merging two independent
solutions solves the problem more
efficiently?
• Calculate Average
– Count values
– Sum Values
– Divide sum by count
• Alternative approach
– calculate partial sum as you count
13
14. Problem Solving Techniques
• What is the unknown?
– What is required?
• What are the data?
– What is given?
• What is the condition?
– By what condition the unknown is linked to the
data?
14
15. Conversion from Fahrenheit to Celsius
• Output
– Temperature in Celsius (C)
• Inputs
– Temperature in Fahrenheit (F)
• Process
5
C = (F − 32)
9
15
16. Calculate and print the average grade of 3
tests for the entire class
• Input
– 3 test scores for each student
• output
– Average of 3 tests for each student
• Process
1. Get three scores
2. Add them together
3. Divide by three to get the average
4. Print the average
5. Repeat step 1 to 4 for next student
6. Stop if there are no more students
16
17. Flow Charts
A flowchart is a visual or graphical
representation of an algorithm.
The arrows, each of which represents a
flowchart employs a series of blocks
and
particular operation or step in the
algorithm.
The arrows represent the sequence in
which the operations are implemented.
17
18. Flowcharts – Most Common Symbols
Symbol Name Function
Terminal Represents the beginning or end of a
program.
Flow-line Represents the flow of logic.
Process Represents calculations or data
manipulation.
Input/Output Represents inputs or outputs of data
and information.
Decision Represents a comparison, question,
or decision that determines
alternative paths to be followed.
18
19. Flowcharts – An Example
Find the solution of a quadratic equation
Ax2+Bx+C=0, given A, B and C.
A
START
INPUT X1 = (-B+R)/(2A)
A, B, C X2 = (-B-R)/(2A)
Calculate PRINT
R = SQRT(B2-4AC) A, B, C, X1, X2
A
END
19
20. Flow Charting
Expresses the flow of processing in a
structured pictorial format.
Flow
Input and Processing of
Output Steps Steps data
Decision Terminator
Connectors
20
21. Begin
Flow chart for
Converting
Get temp. in ‘F’
Fahrenheit
into Celsius
Calculate 5
C = (F − 32)
9
Print ‘C’
Stop
21
22. Flow chart for
Get three scores
calculating
Add them together average of
three scores
Divide the result by three
Print the average
Yes No
More students? Stop
22
23. Comparison of Algorithm representations in Natural
language, flowchart and Pseudo-code
START
INPUT
Step 1: Begin the calculations A, B
BEGIN Adder
Step 2: Input two values A and B Input A and B
C = A + B
Add A to B
Step 3: Add the values PRINT C
and store in C
END Adder
Step 4: Display the result
OUTPUT
Step 5: End the calculation
C
END
Natural language Flowchart Pseudo-code
23
24. Algorithm Representation
(Natural Languages)
• English or some other natural language.
• Are not particularly good:
– too verbose
– unstructured
– too rich in interpretation (ambiguous)
– imprecise
24
25. Algorithm Representation
(Using Programming Language)
{
int I, m, Carry;
int a[100], b[100], c[100];
cin >> m;
for ( int j = 0 ; k <= m-1 ; j++ ) {
cin >> a[j];
cin >> b[j];
}
Carry = 0;
i = 0; 25
while ( i < m ) { …
26. Programming Languages
• Are not particularly good either
– Too many implementation details to worry
about
– Too rigid syntax
• Easy to lose sight of the real task
26
27. Pseudo-code
• We need a compromise between the two:
Pseudo-code
• Computer scientists use pseudo-code to
express algorithms:
– English like constructs (or other natural
language), but
– modeled to look like statements in typical
programming languages.
27
28. Pseudo-code Primitives
Three basic kind of operations:
• Sequential
– Computation ( Set … )
– Input/Output ( Get ... / Print ... )
• Conditional
– If … Else
– If …
• Iterative / looping
– Repeat ...
– While ...
28
29. Computation
General format:
Set the value of <variable> to <expression>
Performs a computation and stores the
result.
Example:
Set the value of C to (A + B)
Set the value of location to 0
Set the value of GPA to (sum / count) 29
30. Variables
A variable is a named storage.
- A value can be stored into it, overwriting
the previous value
- Its value can be copied
Examples:
Set the value of A to 3
The variable A holds the value 3 after its
execution
Set the value of A to (A+1)
Same as: add 1 to the value of A ( A is now 4) 30
31. Not too Strict on Syntax
• Pseudo-code is kind of a programming language
without a rigid syntax, for example we can write:
– Set the value of A to (B+C)
• as
– Set A to (B+C)
• or even:
• Set the value of sum to 0
• Set the value of GPA to 0
• as
• Set sum and GPA to 0
31
32. Sequential Operations - Input/Output
Input
Outside world
Output
•The Computer needs to communicate with
the outside world:
INPUT operations allow the computing agent to
receive from the outside world data values to use in
subsequent computations.
OUTPUT operations allow the computing agent to
communicate results of computations to the outside
world.
32
33. Input
General format:
Get a value for <variable>
The computing agent (computer) suspends
executions and waits for an input value.
33
34. Input - Examples
• Examples:
– Get value for grade
– Get values for N, M
• Can write:
– Get value for N1
– ...
– Get value for N100
• as
– Get value for N1,..., N100
34
35. Output
General format:
Print the value of <variable>
Print the message, "<text>"
The computing agent (computer) displays the value
of the variable(s).
35
36. Output - Examples
• Examples:
– Print the value of grade
– Print the message, "Hello"
• Can write:
– Print the value of N1
– ...
– Print the value of N100
• as
– Print the values of N1,..., N100
36
37. Example
• Write an algorithm to calculate the
average of three numbers.
Steps Operations
1 Get values for N1, N2, and N3
2 Set the value of Average to (N1+N2+N3)/3
3 Print the value of Average
4 Stop
37
38. Conditional Operations
If <condition> then
operations for the then-part
Else
operations for the else-part
1. Evaluate <condition> expression to see
whether it is true or false.
2. If true, then execute operations in then-part
3. Otherwise, execute operations in else-part.
38
39. Conditions, or Boolean Expressions
• A condition is one whose value is true or
false, for example:
3>2 is greater than (true)
3=2 is equal to (false)
A>2 is true if A’s value is greater
than 2 (at the time this is
executed), false otherwise.
39
40. Conditions may be compounded
E1 or E2
true if at least one of them is true; false
otherwise.
E.g. 3 > 2 or 2 > 3 is true
E1 and E2
true if both are true; false otherwise
E.g. 3 > 2 and 2 > 3 is false
not E
true if E is false, false if E is true
40
41. Example
1. Get a value for A
2. If A = 0 then
3. Print the message, “The input is zero”
Else
4. Print the message, “The input is not zero”
1. Get a value for grade
2. If grade < 1 or grade > 9 then
3. Print the message, “Invalid grade”
Else
4. Set the value of total to (grade + total) 41
42. Iterative Operation - While
While <condition> remains true do steps i to j
step i: operation
step i+1: operation
…
step j: operation
1. Evaluate <condition>
2. If condition is true, execute steps i to j,
then go back to i.
3. Otherwise, if condition is false,continue
execution from step j+1. 42
43. Example
1 Get a value for count
2 While count < 10 do
3 Set square to (count * count)
4 Print the values of count and square
5 Add 1 to count
6 Stop
43
44. While Loops
What happens when it gets executed?
If count starts with 7, we get printout
7 49
8 64
9 81
What if count starts with 11?
Nothing is printed, loop is executed 0 times.
44
45. Exercise
What does the following algorithm do?
Set value of A equal to 1
While A > 0
Print message, “Enter an integer”
Get a value for A
End of the loop
Stop
45
46. Tracing an algorithm
The current values of algorithm variables at
various points during execution can be
known by tracing the algorithm with a table
called Trace Table
46
47. Trace Table
Problem: Determine the value of the variable x and y
after the following algorithm is executed
Pseudocode:
Ne
x=5
st
Y=7
in
If x = 5 then
g?
y= 8
? ?
else
y= 0
if y = 7 then
x=6
else
x=3
if x = y then 47
y=0
48. … Continued
Trace table for algorithm
Step X y
No.
1 5 -
2 5 7
3 5 8
4.1 5 8
4.2 3 8
4.3 3 8
48
49. Sequential Search: an Example
Find the phone number of a given Name in an
(unsorted) list of names and their phone numbers
Names Phone numbers
N1 T1
N2 T2
…
N1000 T1000
49
50. Sequential Search: an Example
d:
fin
to
e o hn
Nam ,J
it h
1 553614
Sm
2 442563
3 521463
4 541236
5 452361
6 442563
7 551123
8 441155
9 521364
10 528975
11 541258 50
51. Sequential Search: 1st Attempt
1. Get value for Name
2. Get values for N1,…,N1000
3. Get values for T1,…,T1000
4. If Name = N1 then print the value of T1
5. If Name = N2 then print the value of T2
…
1002. If Name = N999 then print the value of T999
1003. If Name = N1000 then print the value of 1000
1005. Stop
51
52. Sequential Search: Using a Loop
Get values for Name, N1,…, N1000, T1,…, T1000
Set the value i to 1 and the value of Found to 0
While Found = 0 AND i <= 1000 do
If Name = Ni then
Print the value of Ti
Set the value of Found to 1
Else
Add 1 to the value of I
EndIF
End of While loop
52
Stop
53. Selection: Find the Largest Number
Given a list of variables A1, A2, …, An, find the
largest value and its (first) location
Location A1 A2 A3 A4 A5 A6 A7
Value 5 2 8 4 8 6 4
The largest is 8 at location 3
Idea (sketch): Go through the entire list, at each
iteration find the largest-so-far and record its
location
53
54. i
Location A1 A2 A3 A4 A5 A6 A7
Value 5 2 8 4 8 6 4
To begin with,
set largest-so-far to (the value of) A1
set location to 1
set i to 2
54
55. i
Location A1 A2 A3 A4 A5 A6 A7
Value 5 2 8 4 8 6 4
Compare A1 and A2
largest-so-far still holds the value of A1
set i to i+1
55
56. i
Location A1 A2 A3 A4 A5 A6 A7
Value 5 2 8 4 8 6 4
Compare A1 and A3
largest-so-far now holds the value of A3
location is 3
set i to i+1
56
57. i
Location A1 A2 A3 A4 A5 A6 A7
Value 5 2 8 4 8 6 4
Continue the similar process until i = 8
57
58. Selection: Find The Largest Number
Get a value for n, the size of the list
Get values for A1, A2, …, An, the list to be searched
Set largest_so_far to A1 and set location to 1
Set the value of i to 2
While i is less or equal to n do
If Ai > largest_so_far then
Set the value of largest_so_far to Ai
Set the value of location to I
EndIF
Add 1 to the value of i
End of While loop
Print the values of largest_so_far and location
58