Skip to main content

Chapter -1 Introduction of Algorithm and Data Structure -Technology369kk

  Introduction of Algorithm and Data Structure

Post Intro :-In this post we will learn algorithm and data structure in DSA Tutorial in details So let's go start now. 

Table of Content


Introduction of Algorithm 

The Study of algorithm is fundamental to computer science curricula. The word algorithms is derived from the name of Abu Ja far Mohammad ibn al Khwarizmi, an 825 A.D. Persian mathematician. The dictionary meaning of algorithm given in Webster's Ninth New Collegiate Dictionary is A Procedure for solving a  mathematical problem(as of finding the greatest common divisor) in a finite number of steps that frequently involves repetition of an operations. Broadly: a  step - by - step producers for solving a problem or accomplishing some end.  
                    The meaning of algorithm has gone through many changes but what we are interested in it, its meaning that helps us write better computer programs. 

For the purpose of the subject of "Data Structures and Algorithms", algorithm can be defined as - a finite sequence of computational steps that takes a finite set of values as input and produces a finite set of values as input and solves some computational problem in finite amount of time. Usually a computational procedure also does the same thing but it may or may not terminate. As per the definition, an algorithm has to terminate after finite time. There are no fixed values for finiteness of input, output, sequence of steps and time involved These can be as large as required but must not be infinite. Accordingly, an algorithm may take years to terminate but we must be able to prove analytically that the algorithm would terminate.

Definition:  

  • An set of rules is a step by step manner to solve a trouble, where every step suggests an intermediate undertaking. Set of rules carries finite variety of steps that results in the solution of the problem..

 Features of an Algorithm:

Algorithm has the following basic properties 

  • Input-Output:- Algorithm takes ‘0’ or more input and produces the required output. This is the basic characteristic of an algorithm. 
  • Finiteness:- An algorithm must terminate in countable number of steps. 
  • Definiteness: Each step of an algorithm must be stated clearly and unambiguously. 
  • Effectiveness: Each and every step in an algorithm can be converted in to programming language statement. 
  • Generality: Algorithm is generalized one. It works on all set of inputs and provides the required output. In other words it is not restricted to a single input value

Types of Algorithm 

  • Sequence
  • Selection and 
  • Iteration 

Sequence:

  • The steps described in an algorithm are performed successively one by one without skipping any step. 
  • The sequence of steps defined in an algorithm should be simple and easy to understand. Each instruction of such an algorithm is executed, because no selection procedure or conditional branching exists in a sequence algorithm.

Example: 

  • Step 1: Start
  • Step 2: read a, b, c;
  • Step 3: sum =a + b;
  • Step 4: write sum
  • Step 5: Stop  

Selection : 

  • The sequence type of algorithms are not sufficient to solve the problems, which involves decision and conditions.
  •  In order to solve the problem which involve decision making or option selection, we go for Selection type of algorithm. 
  • The general format of Selection type of statement is as shown below.

Example: 

if(condition) 
Statement-1; 
else 
Statement-2; 


Example Explanation :- The above syntax specifies that if the condition is true, statement-1 will be executed otherwise statement-2 will be executed. In case the operation is unsuccessful. Then sequence of algorithm should be changed/ corrected in such a way that the system will re execute until the operation is successful.

Example 1: Check the age of a persons eligibility for vote. 

  • Step 1: Start
  • Step 2: read age
  • Step 3: if age >= 18 then steps_4 run else steps_5 run  ;
  • Step 4: Write "You are eligible for vote"
  • Step 5: Write "You are not eligible for vote"
  • Step 6: Stop

Example 2 : Check Biggest number between two numbers 

  • Step 1: Start
  • Step 2: read a, b
  • Step 3: if a >b then
  • Step 4: Write "A is  biggest number of B "
  • Step 5: else
  • Step 5: Write "B is biggest number of A " 
  • Step 6: Stop

Iteration:

  • Iteration type algorithms are used in solving the problems which involves repetition of statement. In this type of algorithms, a particular number of statements are repeated ‘n’ no. of times. 

Example : Sum of 10 natural number

  • Step 1 : Start
  • Step 2 : read n 
  • Step 3 : repeat Step 4 until n>0
  • Step 4:      (a) r=n mod 10 
  •                  (b) s=s+r 
  •                  (c) n=n/10 
  • Step 5 : write s 
  • Step 6 : Stop 

Complexity of Algorithm: 

In this case of Complexity of algorithm can be efficiency of an algorithm can be measured by the two types :
  1. Time Complexity   
  2. Space  Complexity

1. Time Complexity: 

  • Time Complexity of a computer programs tells us the amount of time the program would take to complete a job, Usually, the program takes time on an advanced computer than on older.
  • Time Complexity of a program  depends on number of things like, time a complier takes to translate the program into machine code, exception time, number and types of mathematical computers carried out, etc. 
  •  The amount of time required for an algorithm to complete its execution is its time complexity.
  • An algorithm is said to be efficient if it takes the minimum (reasonable) amount of time to complete its execution.

2. Space Complexity:

  • The amount of space occupied by an algorithm is known as Space Complexity. 
  • An algorithm is said to be efficient if it occupies less space and required the minimum amount of time to complete its execution.

Chapter Exercise:

 Q1. Write a algorithm for roots of a Quadratic Equations?   

  • Step 1 : START 
  • Step 2 : reads a, b, c 
  • Step 3 : if(a = 0) then execute  steps_4 else step_5
  • Step 4 : Write "Given Numbers is a linear equations 
  • Step 5 : d=(b*b)_(4*a*c) 
  • Step 6 : if (d>0) then step_7 else_8 
  • Step 7 : Write "Roots are real and Distinct"
  • Step 8 : if (d>0) then step_9 else step_10
  • Step 9 : Write "Roots are real and equal "
  • Step 10 : Write "Roots are imaginary"
  • Step 11 : Stop

Q2. Write an algorithm find the largest among three numbers.

  • Step 1: START 
  • Step 2: declared variable a, b and c
  • Step 3: read a, b, c 
  • Step 4:
  •  if a>b
    • if a>c
    • Write " A is greatest " 
    • else 
    • Write " C is greatest " 
  • else 
    • if b>c
    • Write " B is greatest "
    • else 
    • Write " C is greatest"
  • Step 5: STOP

Q3. Write an algorithm find the factorial numbers. 

  • Step 1: START 
  • Step 2: declared variable num, fact and i
  • Step 3: Initialize variables  in fact = 1 and i= 1 
  • Step 4:Read value num
  • Step 5: 
    • Repeat the steps until i=num
    • fact = fact *i
    • i=i+1
  • Step 6: Write "Your Factorial value is "
  • Step 7: Display fact
  • Step 8: STOP

Q4. Write an algorithm find the simple interest .

  • Step 1: START 
  • Step 2: read P, R, T, store, 
  • Step 3: Calculate  store = (P*T*R)/100
  • Step 4: Print store 
  • Step 5: STOP
I Hope this post is helpful for you, Next post is similar uploaded.. 

Comments

Popular posts from this blog

Assignment of ITA/ Information Technology and Application BCA- Technology369kk

Q1. What is  computer Explain basic computer architecture and Difference components.  2. Discuss the use of memory in computer system, Explain memory hierarchy  in details. 3. What is software? Explain difference types of software with explain. 4. Write short notes on the given:- (I) Internet. (II) LAN (Local area network ) (III) Search engine (IV) Web browser  Q 1.What is computer Explain basic computer architecture, Difference components of computer.   Computer :- Computer is defined as an electronic device that takes input data and instructions from the user and after processing them, it generates useful and desired output quickly.   A computer is designed to execute applications and provides a variety of solutions through integrated hardware and software components.                            It is fast and automatic device. It works with the help of programs and represents the d...

C++ and Java Practical All Questions Answers - BCA -Technology369kk

C++ and Java  In this post see most important questions for practical questions given by college all questions with answers . Guys I want to say that this is only for suggested post for your practical please request to you change same alphabets, words or anything  methods name and variables name because if you write all words same then this is copy paste for another peoples.  Used Topics:  Keywords, Variables, Condition Statements, Function , Array, Structure, Pointer.                           In OOPs, Class and Objects, Constructor, Poly morph, Encapsulation, Access Specifiers,                               Inheritance etc.  So, Without Time Lose Come to the Points, let's go start Now:        *************************************************************************  C++ 12 ...

Assignment of PMO (Principal of Management and Organization) - Technology369kk

 ** Assignment Of PMO ** Agenda: -  4 Questions discuss in this post. Question 1. Write a d etails note on selection why it Called. negative process.  Question 2. Write a details note on 'span of control. Question 3. Planning is an essential process, do you agree ? Discuss  Question 4. Write a note on management function. Q 1. Write a d etails note on selection why it called negative process.  Ans :-  Selection is the process of choosing the most suitable candidates out of the several candidates available.          Selection is a negative process because there may be more rejected then those selected in most of the candidates that is called selection is a negative process. → Selection process has the following steps:-  [ A .] Screening of applicants - Based on the screening of applicants only those candidates. It Called further process of selection. Who are found eligible for the job Standards of the the organization. [ B .] S...