Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13
Unit 1
Introduction to Algorithm and Data
structure Problem Solving • What is Problem Solving? – Problem solving is the process of identifying a problem, developing an algorithm for the identified problem and finally implementing the algorithm to develop a computer program. – Problem is the core of computer science. – Programmers must first understand how a human solves a problem, then understand how to translate this "algorithm" into something a computer can do, and finally how to "write" the specific syntax. Problem Solving Introduction to algorithm • Algorithm: – It is a finite set of instructions which accomplish a particular task. – An algorithm is used for data processing, calculation and other operations. – Ex. Write an algorithm to add two numbers entered by user. Algorithms In Programming:-> Step 1: Start Step 2: Declare variables num1, num2 and sum. Step 3: Read values num1 and num2. Step 4: Add num1 and num2 and assign the result to sum. sum←num1+num2 Step 5: Display sum Step 6: Stop Characteristics of Algorithm ❖ Input: There are zero or more quantities which are externally supplied
❖ Output: At least one quantity is produced
❖ Definiteness: Each instruction must be clear and unambiguous
❖ Finiteness: If we trace out the instructions of an algorithm, then
for all cases the algorithm will terminate after a finite number of steps
❖ Effectiveness: Each step should be basic so that it can be easily
converted into a program . Algorithm design tools • Pseudo code: – Pseudo-code is a method of describing computer algorithms using a combination of natural language and programming language. – Set of instructions that mimic programming language instructions – It has no syntax like any of the programming language and thus can’t be compiled or interpreted by the computer. Example of Pseudo code Pseudo code-> A false code Advantages and Disadvantages of Pseudo code • Advantages of Pseudo-code: – Improves the readability of any approach. – Acts as a bridge between the program and the algorithm or flowchart. – In industries, the approach of documentation is essential. And that’s where a pseudo-code proves vital. – It makes the code construction phase easier for the programmer. • Disadvantages of Pseudo-code: – It does not provide a visual representation of the logic of programming. – There is no proper format for writing the pseudo-code. Algorithm Design Tools • Flowchart: – A flowchart is a schematic representation of an algorithm or a stepwise process, showing the steps as boxes of various kinds, and their order by connecting these with arrows. – Flowcharts are used in designing or documenting a process or program. – It is a graphical representation of a process or system that details the sequencing of steps required to create output. Flowchart Symbol Example of Algorithm Advantages of Flowchart ▪ Communication: Flowcharts are better way of communicating the logic of a system ▪ Effective analysis: With the help of flowchart, problem can be analyzed in more effective way. ▪ Proper documentation: Program flowcharts serve as a good program documentation ▪ Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and program development phase. ▪ Proper Debugging: The flowchart helps in debugging process. ▪ Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. Conversion of flowchart into Pseudo- code