1 / 63

Introduction to Programming Logic    

Introduction to Programming Logic    . Instructor: Professor Stephen Osborne. What is a problem? . A problem can present itself in many forms. Examples of problems are as follows : Question: What movie should we see? Need to do something: Generate the monthly payroll.

alastair
Télécharger la présentation

Introduction to Programming Logic    

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Programming Logic     Instructor: Professor Stephen Osborne

  2. What is a problem? A problem can present itself in many forms. Examples of problems are as follows: • Question: What movie should we see? • Need to do something: Generate the monthly payroll. • Obstacle to progress: A part is missing that is causing work to halt on a project. • Status of a process: What is the status of the project? • What-if simulation: How much money needs to be deducted from each pay check to save for a down payment on a car? • Evaluation of a solution to another problem: Should traveling be done by train or car? • Lack of information: How much money is left on the mortgage? • Undesirable state: A person has gone into debt. • Lack of control: A company has decided to downsize.

  3. What is a problem solution? There are many ways in which a problem can be solved. The following Are some of the possibilities: • Algorithm: An algorithm is a series of steps used to arrive at an outcome that represents the best answer to a problem. It is a specification of a behavioral process. An algorithm is a finite set of instructions that govern a behavior step by step, such as the manipulation of data. Problems that require algorithms are often the problems that computers solve best (Sprankle, 2006, p. 5). • Heuristic solutions: Heuristic solutions involve the use of human ingenuity and reasoning. They are based on learning through experience (Sprankle, 2006, p. 5). • Passing of time: Some problems are solved simply by the passing of time. An undesirable state may change, or it may no longer be a problem. • Gaining resources: The solution to a problem may be more resources—such as more money, time, or people.

  4. The Six Steps of Problem Solving The six steps of problem solving include the following 1. Identify the problem: What is the problem that needs to be solved? 2. Understand the problem: Are there considerations that need to be taken into account? 3. Identify alternative ways to solve the problem: There may be multiple solutions to the problem. Write down all possible solutions, and at this point, don’t rule anything out.

  5. 4. Select the best way to solve the problem from the list of alternative solutions: Factors involved in selecting the best solution include efficiency, schedule, cost, available resources, or the need for a long-term solution. 5. List instructions that enable you to solve the problem using the selected solution: When solving a problem with computers, this can include pseudocode, or a combination of English and code. 6. Evaluate the solution: Determine if the solution solves the problem. If not, return to identifying and understanding the problem.

  6. Algorithmic Problem Solving • Using best decision is found for solving problem • Step-by-step instructions are used in reaching your chosen decision  • These steps are known as algorithm

  7. Heuristic Problem Solving • Cannot be always be reached through a series of steps but instead require using: • Reasoning built on knowledge and experience • Process of trial and error

  8. Difficulties with Problem Solving Following are some of the difficulties that people encounter with problem solving: • Lack of training or natural ability for problem solving • Fear of decision making, even when faced with evidence • Inadequate use of the problem-solving steps • Personal biases inserted into the process • Misunderstanding the problem—solving the wrong problem • Inability to explain or abstract the problem in a form that is usable by a computer Using a proven process, such as the six steps problem solving process, can help facilitate understanding and solving a problem. When attempting to use computers to solve problems, it is important to abstract the problem in a form that the computer can use. Remember, computers work best with step-by- step or algorithmic solutions.

  9. Algorithm Design • There are two sides to computer science. The first is the applied side, which involves programming and system and software design. The other side is the theoretical side. The theoretical side fuels the applied side. One example of this is all well-known algorithms, such as sorting and searching, pathfinding, or optimization algorithms are all designed in a general manner on the theoretical side. • The applied side takes the breakthroughs from the theoretical side and applies it to specific situations. However, regardless of how applied the focus of a programmer might be, there are always situations where no prior algorithm applies and a new one must be developed.

  10. There are several generic methods of problem solving that are widely used for many problems. These methods include brute force, greedy, divide and conquer, and backtracking. • Solving any given problem efficiently requires both consideration of all possible methods as well as a bit of creativity, insight, and luck.

  11. Brute Force • The brute force method of algorithm design is intended to bring into mind hammering a screw into a board of wood. The solution may not be elegant or efficient, but it will work. Generally, this involves considering every aspect of every element of an array, regardless of whether each element is important. It is an exhaustive, programmatic consideration of everything, which takes time. Generally, brute force methods are inefficient but still serviceable in many situations. • The biggest place where the brute force method shows its difficulty is in very large numbers of input. A brute force method can perform some tasks quickly with 10 elements, but it may bog down with 10 million elements. This is particularly telling if an efficient algorithm could cut that number in half, by a tenth, or even drop it down to the square root of the brute force method.

  12. Greedy • Greedy algorithms involve considering the largest portion of the problem set first. For example, if the problem considers how to pack a set of items into a bag or a box, the greedy method would put the largest item in first, followed by the second largest, and so forth. • The greedy method will occasionally find an efficient method; however, more often than not, the solution will be similar to a brute force method.

  13. Divide and Conquer • Suppose that a problem involved shuffling a deck of cards. It could be determined that a deck of cards is shuffled if each half of the deck is shuffled and randomly recombined. Due to the fact each half could be considered a deck, what occurs is a recursive solution. The only component left to define is the base case, which would say that the dividing of decks stops when the deck only consists of one card. • Afterwards, each subdeck could be randomly combined to reproduce the larger deck. This could be continued until the full deck is shuffled. This method is called divide and conquer, when the algorithm seeks to divide the problem into smaller problems which are, in turn, solved in the same manner.

  14. Backtracking • A method often called backtracking is one other possibility toward finding an efficient solution by starting with the solution and finding the problem. • If an algorithm can be developed that takes an appropriate solution and slowly takes parts of it away until it comes to the problem and the algorithm can be reversed, it is sometimes possible to determine an efficient solution to a problem.

  15. Summary • Algorithm design is often considered an art and a science. It often takes luck in addition to perseverance to solve any problem. However, research often yields a preexisting solution.

  16. Now Let’s Look at our Assignment

  17. Task Type: Discussion Board 2   Deliverable Length: See Assignment Details    Points Possible: 75   Due Date: 9/09/2011 11:59:59 PM  CT Students will be expected to post their first initial discussion board posting by Wednesday of each week. Discussion posts will be graded and late submissions will be assigned a late penalty in accordance with the late penalty policy found in the syllabus. NOTE: All submission posting times are based on midnight Central Time. Students are expected to post their responses to peers by Sunday. NOTE: All submission posting times are based on midnight Central Time. Primary Task Response: Within the Discussion Board area, write 400–600 words that respond to the following questions with your thoughts, ideas, and comments. This will be the foundation for future discussions by your classmates. Be substantive and clear, and use examples to reinforce your ideas: Choose a problem that you would like to see corrected in your community that could be solved through an algorithmic process. Write an essay that demonstrates how you can use the 6 problem-solving steps discussed in your text to solve the problem. The step-by-step instructions for step 5 should be detailed and clear enough that they could be executed by someone else without asking any questions. Responses to Other Students: Respond to at least 2 of your fellow classmates with a reply of at least 100 words about their primary task response regarding items you found to be compelling and enlightening. To help you with your discussion, please consider the following questions: What did you learn from your classmate's posting? What additional questions do you have after reading the posting? What clarification do you need regarding the posting? What differences or similarities do you see between your posting and other classmates' postings?

  18. Phase 1 Discussion Board 2 Resolution Use the 6 step problem solving method for the below scenario: • Choose a problem that you would like to see corrected in your community that could be solved through an algorithmic process. Write an essay that demonstrates how you can use the 6 problem-solving steps discussed in your text to solve the problem. The step-by-step instructions for step 5 should be detailed and clear enough that they could be executed by someone else without asking any questions. Or Choose a problem of your own selection and then apply the 6 step problem solving method to it. The main idea here is to know how apply the problem solving technique to any situation.

  19. Six Step Solving Process Example Scenario of a problem “What to do this evening”

  20. 1. Identify the problem. How do individuals wish to spend the evening? • 2. Understand the problem. With this simple problem, also, the knowledge base of the participants must be considered. the only solutions that should be selected are ones that everyone involved would know how to do. You probably would not select as a possible solution playing a game of chess if the participants did not know how to play. • 3. Identify alternatives • Watch television • Invite friends over • Play video games • Go to the movies • Play miniature golf • Go to the amusement park • Go to a friend’s party • The list is complete only when only you can think of no more alternatives.

  21. 4. Select the best way to solve the problem. • Weed out alternatives that are not acceptable, such as those that cost too much money or do not interest one of the individuals involved. • Specify the pros and cons of each remaining alternative. • Weigh the pros and cons to make the final decision. this solution will be the best alternative if all other steps were completed well. • 5. Prepare a list of steps (instructions) that will result in a fun evening. • 6. Evaluate the solution. Are we having fun yet? If nobody is having fun, then the planner needs to review the steps to have a fun evening to • see whether anything can be changed, if not then the process must start again.

  22. Step 5 List of Instructions • Chose going to a movie as it was an economical choice due to it got us out of the house but only cost a little over $20.00. • Examined the entertainment section of daily news paper to select a movie that everyone would like. • Dressed for a casual evening. • Got into the car and drove to the movie theater. • Went into the movie theater and found seating to our liking. • Watched movie and enjoyed it very much.

  23. Problem Solving in Programming Why do we need problem-solving techniques, and how does this relate to computer programming? • Problem solving is something that we do all day, every day, almost without thinking about the process at all. With bigger problems and with problems that have outcomes of higher risk, such as with strategic business issues, it is wise to follow the basic steps of problem solving. This will mitigate the risk that comes when the problem is not fully understood.

  24. Each step in a problem-solving technique is related to a programmer's step to building a program. A programmer will first seek to fully understand the problem. He or she will then plan the logic and flow of a program. • Next, the programmer writes pseudocode and translates it into the chosen programming language. Finally, the programmer implements the program and begins testing and adjusting as needed.

  25. What is the role of logic in problem solving, • and what does it look like in business? • Logic helps us organize activities into the right order and display particular outcomes for defined circumstances. • Many people are familiar with logic problems: brainteasers in which decision tables are used to find a solution.

  26. An example of such a problem would sound like this: • There are three appointment openings at a dental office, and three individuals want to come in on that day. Person A must arrive before 10 a.m., person B cannot come before 10:30 a.m., and person C wants to be the first appointment of the day. • How can you accommodate each individual? This is the kind of work that can be automated by implementing the right logic and business rules.

  27. What is the purpose of a decision table? • Decision tables are used to help the programmer understand all the possible outcomes to a situation and to help the programmer build all variables into the program's decision engine. • Decision tables are made up of four parts: conditions, possible combinations, possible actions based on the conditions, and actual actions to be taken based on conditions.

  28. Definition • Components • A decision table lists causes and effects in a matrix. Each column represents a unique combination. • Purpose is to structure logic Cause = conditionEffect = action = expected results

  29. Why is problem solving critical in information systems? • Problem-solving technique and following all the steps to analyze all sides of the problem are imperative when considering information systems. If a business person bypasses one of the critical steps, then a system or program could be built that does not actually solve the problems at hand. • It is expensive and time consuming to build a system, so being thorough and systematic to ensure that that it fully solves the problem at hand is simply good business.

  30. Programming Tools of the Trade • Software programs are often created in teams. The person who writes the code may not be the person who designed the solution. In many development projects, one person or team meets with the customer to define the requirements while another team member designs and documents the solution. A development team codes the solution, and a software quality assurance team tests the code. • To support the team development environment, tools have been developed to document the results of the various phases of the project. During the analysis phase of the project, tools help to clarify the problem and facilitate communication with other team members.

  31. Programming Tools

  32. The following are analysis/design tools Problem analysis chart Structure chart Input-processing-output (IPO) chart Pseudocode Flowchart It is important that analysis and design take place before writing code.

  33. Problem Analysis Chart The problem analysis chart is a way to document the analysis of a problem. It consists of four sections What data do I have? What is the expected outcome? What processing must take place? What are alternative solutions? The problem analysis chart documents the information that is known. It helps to clarify the expected outcome. The third step concentrates on the solution or what processing will take place to solve the problem. It is important to consider alternate solutions because initial solutions may not be feasible due to budget, time, or human resource constraints. Overall, the tool helps to focus the team on relevant information that can be used to solve a problem.

  34. Problem Analysis Chart

  35. Structure Chart (Interactivity Chart) • The structure chart, also known as an interactivity chart, shows the relationships of subtasks for a given solution. The tasks are displayed in hierarchical order from general to specific. • A structure chart shows what will happen but not how it will happen. The following example shows that the solution will input data, compute results, and print results. It does not show how those routines will work.

  36. A structure chart is read from top to bottom, and left to right. It may indicate how many times a subroutine is called. Each module is assigned a tracking number. The number is used to reference the module in other charts, and it is also used to reflect the relationship to the other modules in the chart. Structure charts show activities and in what order they must occur for a program to implement a solution.

  37. IPO Chart • The IPO chart is an extension of information in the problem analysis chart. The information in the chart includes input, output, processing, and optionally a module tracking number. An IPO chart should have a section built for each subroutine or task in a process. • The input shows what data are needed in a particular task. The processing is a verbal description of what is happening in the task. Any formulas or calculations should be documented in this section. The output section documents the information that is output from the task.

  38. Input, Processing, Output IPO Chart

  39. Study the following "millionaire list" IPO chart example: Problem: Construct an algorithm that will produce a list containing the names of millionaires who paid less in taxes than you (or the user).

  40. Pseudocode • Pseudocode (or algorithm) is the set of specific instructions drawn from the IPO chart. These steps are written in a combination of English and code. As the programmer becomes more comfortable with a programming language, the pseudocode generally becomes more like code and less like English. • When writing pseudocode, no assumptions are allowed, and no steps can be skipped. The steps are listed in the order they are to be executed, and all steps must be included. An algorithm is a logical step-by-step solution.

  41. Flowchart • A flowchart is a graphic representation of an algorithm. Flowcharts capture the flow of data and any logical decisions that must be made concerning the data. • In large and complex programs, creating a flowchart for each coding construct may not be possible. In some cases, pseudocode is a better choice for mapping logic to code.

  42. A flow chart can therefore be used to: • Define and analyze processes. • Build a step-by-step picture of the process for analysis, discussion, or communication. • Define, standardize or find areas for improvement in a process • Also, by conveying the information or processes in a step-by-step flow, you can then concentrate more intently on each individual step, without feeling overwhelmed by the bigger picture.

  43. How to Use the Tool: Most flow charts are made up of three main types of symbol: Elongated circles, which signify the start or end of a process. Rectangles, which show instructions or actions. Diamonds, which show decisions that must be made. Within each symbol, write down what the symbol represents. This could be the start or finish of the process, the action to be taken, or the decision to be made. Symbols are connected one to the other by arrows, showing the flow of the process.

  44. To draw the flow chart, brainstorm process tasks, and list them in the order they occur. Ask questions such as "What really happens next in the process?" and "Does a decision need to be made before the next step?" or "What approvals are required before moving on to the next task?“ • Start the flow chart by drawing the elongated circle shape, and labeling it "Start". • Then move to the first action or question, and draw a rectangle or diamond appropriately. Write the action or question down, and draw an arrow from the start symbol to this shape.

  45. Work through your whole process, showing actions and decisions appropriately in the order they occur, and linking these together using arrows to show the flow of the process. Where a decision needs to be made, draw arrows leaving the decision diamond for each possible outcome, and label them with the outcome. And remember to show the end of the process using an elongated circle labeled "Finish". • Finally, challenge your flow chart. Work from step to step asking yourself if you have correctly represented the sequence of actions and decisions involved in the process. And then (if you're looking to improve the process) look at the steps identified and think about whether work is duplicated, whether other steps should be involved, and whether the right people are doing the right jobs.

  46. Example: The example below shows part of a simple flow chart which helps receptionists route incoming phone calls to the correct department in a company:

  47. Start of Program True False Processing Instructions Processing Instructions . Assignment Decision Flowchart

  48. Summary • There may be a redundancy of data or duplication of information among the charts. While this is true to a certain extent, it is still important to organize the problem before beginning to write code. • Different team members will be using different charts as they work on their part of the solution.

More Related