Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore Algorithm

Algorithm

Published by Teamlease Edtech Ltd (Amita Chitroda), 2023-06-14 12:22:40

Description: Algorithm

Search

Read the Text Version

Algorithms



An algorithm is “a finite set of precise instructions for performing a computation or for solving a problem” • A program is one type of algorithm ⚬ All programs are algorithms ⚬ Not all algorithms are programs! Examples: • Directions to somebody’s house is an algorithm • A recipe for cooking a cake is an algorithm • The steps to compute the cosine of 90° is an algorithm

Algorithms generally share a set of properties: What the algorithm takes in as input Input What the algorithm produces as output Output The steps are defined precisely Definiteness Should produce the correct output Correctness The steps required should be finite Finiteness Each step must be able to be performed in a finite amount of time Effectiveness The algorithm should be applicable to all problems of a similar form

Here are a few common representations of Algorithms can be represented in various algorithms: ways, depending on the context and the • Natural language intended use. • Psuedocode • Flowcharts • structured english • Programming languages • Mathematical equations





What is a flowchart? Flowcharts are graphical representations of algorithms that use symbols and arrows to depict the flow of control and the sequence of steps. Different shapes represent different operations or actions, such as rectangles for process steps, diamonds for decision points, and arrows for the flow between steps.

Flowcharts offer several advantages in representing algorithms and processes: • Visual Representation • Easy-to-Follow Logic • Simplified Communication • Problem-Solving Aid • Documentation and Maintenance • Integration with Development

While flowcharts have numerous advantages, they also come with a few limitations and disadvantages: • Complexity Limitations • Lack of Standardization • Limited Detail • Inflexibility • Ambiguity and Subjectivity • Learning Curve

Here are some commonly used flowchart Flowcharts use various symbols to represent symbols: different operations, actions, decision points, • Terminal/Start/End is represented by a rounded and connectors. rectangle • Process/Operation is represented by a rectangle • Input/Output is represented by a parallelogram • Decision/Conditional is represented by a diamond shape • Connector/Flowline is represented by an arrow or line

Here are some commonly used flowchart Flowcharts use various symbols to represent symbols: different operations, actions, decision points, • Subroutine/Function is represented by a rectangle and connectors. with double vertical lines on each side • Loop/Iteration is represented by a curved arrow or rectangle • Delay/Wait is represented by a rectangle with a wavy bottom line • Off-page Connector is represented by a small circle or square with a number or letter inside

When drawing a flowchart, there are some general rules and guidelines to keep in mind to ensure clarity and readability: • Use Standard Symbols • Follow a Top-to-Bottom, Left-to-Right Orientation • Keep It Simple • Use Meaningful Labels • Use Arrows for Flow Direction • Use White Space Effectively • Test and Review



What is a pseudocode? Pseudocode is a high-level, informal description of a computer program or algorithm. It is a hybrid between natural language and programming language constructs, designed to express the logic of an algorithm without being tied to any specific programming language syntax.

While there is no strict standard for writing Pseudocode follows a logical structure that pseudocode, the following are some of the main allows for the clear representation of components of pseudocode: algorithmic logic. • Sequence logic • Selection logic • Iteration logic

Here's an example of pseudocode demonstrating The sequence logic in pseudocode refers to the sequence logic: the sequential execution of statements or Step 1: Read input from the user. steps in an algorithm. It represents the Step 2: Perform calculations based on the input. natural flow of actions, where each step is Step 3: Store the result in a variable. Step 4: Display the result to the user. executed in the order it appears. Step 5: End the algorithm.

There are different types of conditional statements Selection logic in pseudocode refers to the commonly used in pseudocode to implement inclusion of conditional statements that selection logic: allow the algorithm to make decisions and • If-Else Statements choose different paths of execution based on • Switch-Case Statements • Nested If Statements certain conditions. Example: if condition is true then // execute statements else // execute alternate statements endif

There are different types of loop constructs Iteration logic, also known as looping logic, in commonly used in pseudocode to implement pseudocode refers to the ability of an iteration logic: algorithm to repeat a set of instructions • While Loop multiple times. It allows for the execution of • Do-While Loop • For Loop a specific block of code repeatedly until a certain condition is met. Example: while condition is true do // execute statements endwhile

While there are no strict rules for writing pseudocode, following certain guidelines can help ensure clarity, readability, and consistency. Here are some commonly recommended rules for writing pseudocode: • Use Plain English • Focus on Logic, Not Syntax • Use Indentation • Use Meaningful Variable and Function Names • Comment the Code • Follow a Consistent Style • Use Standard Control Structures • Test the Pseudocode

Pseudocode offers several advantages when designing, planning, and communicating algorithms. Some key advantages of using pseudocode include: • Readability and Clarity • Language Independence • Simplicity and Abstraction • Iterative Design and Planning • Collaboration and Communication • Focus on Algorithmic Thinking

While pseudocode offers numerous advantages, it is important to consider some potential disadvantages as well. Here are a few limitations or challenges associated with using ps•euAdmobciogdueit:y • Lack of Standardization • Limited Expressiveness • Lack of Error Checking • Limited Execution • Difficulty in Scaling


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook