DATA structures algorithm, Slides of Data Structures and Algorithms

This doc is DSA notes for IT students

Typology: Slides

2021/2022

Uploaded on 05/21/2022

taniya-sharon
taniya-sharon 🇱🇰

1 document

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
HND in Computing and Software
Engineering
SEC5213: Data Structures and Algorithm
Level: 5
Credit Value: 20
Lesson 02 – Introduction to Algorithms
Lecturer: Ms. Sathananthy 05/21/2022
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download DATA structures algorithm and more Slides Data Structures and Algorithms in PDF only on Docsity!

HND in Computing and Software

Engineering

SEC5213: Data Structures and Algorithm

Level: 5

Credit Value: 20

Lesson 02 – Introduction to Algorithms

Lecturer: Ms. Sathananthy

1 05/21/

Learning Outcome 02 Understand the fundamentals of various common algorithms 2 05/21/

Algorithm 4 05/21/ An algorithm is a procedure having well defined steps for solving a particular problem. Algorithm is finite set of logic or instructions, written in order for accomplish the certain predefined task.  It is not the complete program or code, it is just a solution (logic) of a problem, which can be represented either as an informal description using a Flowchart or Pseudo code.

Algorithm – problem solving 5

Example 1: Calculate the Interest of a

Bank Deposit

Algorithm:

Step 1: Read amount,

Step 2: Read years,

Step 3: Read rate,

Step 4: Calculate the interest with formula

"Interest=AmountYearsRate/

Step 5: Print interest,

05/21/

Algorithm – problem solving 7  (^) Example 3: Determine whether a temperature is Below or Above the Freezing Point Algorithm: Step 1: Input temperature, Step 2: If it is less than 32, then print "below freezing point", otherwise print "above freezing point Step 3: Print output 05/21/

Algorithm – problem solving 8  Example 4: log in to Facebook account Algorithm: Step 1: Enter www.facebook.com in your browser. (I/O) Step 2: Facebook Home page loads (PROCESS) Step 3: Enter your Email ID and Password (I/O) Step 4: Is Email ID and Password Valid (DECISION) if NO then Log in error (PROCESS) go to step 3 else Display Facebook Account (I/O) Stop 05/21/

Miscellaneous problems solving 10

1. Do You Owe Me Money?

There are three brothers named John, James and William, who look

exactly alike. John and James always lie, but William always tells the

truth. You meet one of the brothers on the street one day, and want to

know if he is John (because John owes you money). You are allowed to

ask ONE question that can be answered “yes” or “no”, but the

question may not contain more than 3 words. What question would

05/21/

Solution 11 05/21/ The questions would be, “Are you James?”(The goal is to find John, the one that owes you money?) If the person is James, he will answer “NO”(because he lies) If the person is John, he will say “Yes”(he owes you money and he lies) If the person is William, he will say “No”(he tells the truth) So, if the answer is “yes” you know that it is John and you can then demand your money. You have a 50% probability of knowing if it is James with this question.

Characteristics of an Algorithm 13 05/21/ An algorithm must follow the mentioned below characteristics:  Input: An algorithm must have 0 or well defined inputs.  Output: An algorithm must have 1 or well defined outputs, and should match with the desired output.  Feasibility: An algorithm must be terminated after the finite number of steps.  Independent: An algorithm must have step-by-step directions which is independent of any programming code.  Unambiguous: An algorithm must be unambiguous and clear. Each of their steps and input/outputs must be clear and lead to only one meaning.

Performance of Algorithm The performance of algorithm is measured on the basis of following properties: i. Time complexity: It is a way of representing the amount of time needed by a program to run to the completion. ii. Space complexity: It is the amount of memory space required by an algorithm, during a course of its execution. Space complexity is required in situations when limited memory is available and for the multi user system. Each algorithm must have: iii. Specification: Description of the computational procedure. iv. Pre-conditions: The condition(s) on input. v. Body of the Algorithm: A sequence of clear and unambiguous instructions. vi. Post-conditions: The condition(s) on output. 14

Algorithms – contd.Commonly used algorithms include are useful for:

Searching for a particular item

Sorting the data

Iterating through all the items in a data structure

16

Next – Asymptotic Analysis 17 05/21/