SlideShare a Scribd company logo
Computer Algorithms .
Algorithm
● the Latin form of Al-Khw?rizm .
● Algorithm:is well-defined computation
  procedure that takes some value,or set of
  values, as input and produces some value
  , or set of values,as output.
● a sequence of computational steps that
  transfer the input into the output
● a tool for solving a well-specified
  computional problem
Example of Algorithms :

● when you need to sort asequence of
  numbers into nondecreasing order
  (31,42,59,26,58)

      Input:A sequence of n numbers
(instance of program) (31,42,59,26,58).

       Output:A reordering of the input
       sequence (26,31,42,58,59).
Solve this problem with python:
                def sort(a,n):
                   i=0
                   for i in range(n):
                     min=i
                     m=i+1
                     for m in range(n):
                        if a[m]<a[min]:
                           min=m
                           temp=a[i]
                           a[i]=a[min]
                           a[min]=temp
Computer algorithms :
● in computer systems, an algorithm is
  basically an instance of logic written
  in software by software developers
  to be effective for the target
  computer, in order for the target
  machines to produce output from
  given input .
Why computer algorithms are important ?

 ● The topic of algorithms is important in
   computer science because it allows for
   analysis on different ways to compute
   things and ultimately come up with the best
   way to solve a particular problem. By best I
   mean one that consumes the least amount of
   resources or has the fastest running time.
What Kinds of problems are solved by
algorithms?
●    The Human Genome Project : made a
    great progress toward the goals of
    identifying all the 100.000 genes in human
    DNA determining the sequences of the 3
    billion chemical base pairs that make up
    human DNA ,sorting the information in
    databases,and developing tools for data
    analysis.Each of these steps requires
    algorithms.
What Kinds of problems are solved by
algorithms?
● The Internet enables people around the
  world to quick access and retrieve large
  amounts of information.
● Electronic commerce enables goods and
  services to be exchanged electronically.
● Manufacturing and other commerical
  enterprises need to allocate rescources in
  the most beneficial way.
Advantages of "Python" as a
 Programming Language

● Python is an interpreted, high-level programming
  language, pure object-oriented, and powerful
  server-side scripting language for the Web. Like
  all scripting languages, Python code resembles
  pseudo code. Its syntax's rules and elegant design
  make it readable even among multiprogrammer
  development teams.
Advantages of "Python" as a
Programming Language :
Readability :

● Python's syntax is clear and readable.
● Python has fewer "dialects" than other l
  languages, such as Perl. And because the
  block structures in Python are defined by
  indentations
Advantages of "Python" as a
Programming Language :
It Is Simple to Get Support :

● Python community always provides support
  to Python users.
● Python code is freely available for everyone.
● many people are creating new
  enhancements to the language and sending
  them for approval
Advantages of "Python" as a
Programming Language :
Fast to Learm .
Fast to Code :

● Python provides fast feedback in several
  ways.
● Python provides a bottom-up development
  style in which you can build your
  applications by importing and testing critical
  functions in the interpreter before you write
  the top-level code that calls the functions.
Advantages of "Python" as a
Programming Language :

Reusability :

● You can easily share functionality between
  your programs by breaking the programs
  into modules, and reusing the modules as
  components of other programs.
Advantages of "Python" as a
Programming Language :
Portability :

● Besides running on multiple systems, Python
  has the same interface on multiple
  platforms. Its design isn't attached to a
  specific operational system because it is
  written in portable ANSI C. This means that
  you can write a Python program on a Mac,
  test it using a Linux environment, and
  upload it to a Windows server.
Advantages of "Python" as a
Programming Language :
Object-Oriented Programming :

● Some of the implemented OO functionality in
  Python is inheritance and polymorphism.
Examples of "Python based Solutions" for

     different "Computer Algorithms   " ..
SEARCHING :
● The operation of finding the location LOC of
  ITEM in DATA, or printing some message
  that ITEM does not appear there.

● There are many differtent serarching
  algorithms :
       The algorithm deponds on the way the
        information in DATA is organized.
Linear Search :
● Known as sequential search
● is a method for finding a particular
   value in alist,
   that consists of checking every one of
its     elements,
  one at a time and in sequence, until the
desired one is found.
linear search:
 #linear search in python:
def linear_search (a,n,item):
  k=0
  for k in range(n):
     if item ==a[k]:
        loc=k
  return loc
the disadvantages of linear search :

 ● in linear search it needs more space and
   time complexity.


 ● in linear search if the key element is the last
   element and the search is from first element
   that is a worst case, if the key element is the
   first element and the search is from last
   element then also is the worst case.
Best, Worst and Average
Cases :
● Worst case :-     O(n)


● Average case :-     O(n).
binary search :

●       Suppose DATA ia an array which i
    stored in increasing numerical order or
    alphabetically.

     Then There are an extremely efficient
searching algorithm , called binary search,
     That can be used to find the location LOC
of a given ITEM of information in DATA.
Binary search :
Binary Search :
 def binary_search(data,n,lb,ub,item):
   beg=lb
   end=up
   mid=(beg+end)/2
   while beg<=end and data[mid]!=item:
      if item<data[mid]:
         end=mid-1
      else:
         beg=mid+1
      mid=(beg+end)/2
Binary Search :


 if data[mid]==item:
    loc=mid
 else :
    loc=-1
 return loc
Best, Worst and Average
cases :
● Worst case :-     O(log2 n).

● Average case :-     O(log2 n).
The Binary Search Algorithm
   works as follows :
● During each stage of our algorithm, our search
  for ITEM is reduced to a segment of element of
  DATA:       DATA[BEG],DATA[BEG+1],.............,
  DATA[END]

● The algorithm compares ITEM with the middle
  element DATA[MID] of the segment

             MID=((BEG+END)/2)
The Binary Search Algorithm
  works as follows :
● If ITEM < DATA[MID], then ITEM can appear
   only in the left half of the segment:
           DATA[BEG],DATA[BEG+1],.............,
DATA[MID-1]
-reset END=MID-1.
● If ITEM > DATA[MID], then ITEM can appear
   only in the right half of the segment::

DATA[MID+1],DATA[MID+2],...........,DATA[END].
-reset BEG=MID+1.
Limitations of the Binary Search
Algorithm :
●    -The Binary Search Algorithm requires
    two conditions:

(1) the list must be sorted.

(2) direct access to the middle element in any
sublist.
Limitations of the Binary Search
Algorithm :
● keeping data in sorted array is normally
  very expensive when there are many
  insertions and deletions.

● Thus one may use a different data structure
  such as linked list or a binary search tree
Sorting :

● Sorting : is the process of rearranging the
  data in array or list in insreasing or
  decreasing order .
Insertion Sort :
● Simple sorting algorithim .
● Ii is very popular when first sorting .
● Efficient for sorting small data .
(more efficient than bubble and selection sort)
● Slow for sorting large data, thus Time can
  be saved by performing a binary search to
  find the location in which insert data[i] in
  the in input array .
● Online : can sort input array as it recevied .
Insertion Sort :
● insertion sort works as follows :
     ■ removes an element from the input
       data, inserting it into the correct
       position , to find the correct position we
       compare this element with each
       element in the input array, from right to
       left, until no input elements remain.
Insertion Sorting :
def InsertionSort(data,n):
  for j in range(1,n):
     key = data[j]
     i=j-1
     while (data[i] > key):
       data[i+1] = data[i]
       i=i-1
     data[i+1] = key
Best, Worst and Average
Cases :
The Best Case:
      in which the input array was already
    sorted .This gives Inserting Sort linear
    running time O(n).
● The Worst Case :
     in which the input array was sorted in
  reverse order .This gives Inserting Sort
  quadratic running time O(n2).
● The Average Case : O(n2) .
Selection Sort :
● Selection sort works as follows :
       ● Find the location loc of the smallest
          element in input array and put it in
          the first position, find the location
          loc of the second smallest element
          and put it in the second position,
          And so on .
Selection Sort :
 def sort(a,n):
   i=0
   for i in range(n):
     min=i
     m=i+1
     for m in range(n):
       if a[m]<a[min]:
          min=m
          temp=a[i]
         a[i]=a[min]
         a[min]=temp
Best, Worst and Average
Cases :

● Best case :    O(n2) .

● Worst case :     O(n2) .

● Average case :      O(n2) .
Merge Sort :
● Merge sort : a divide and conquer algorithm
  that was invented by John von Neumann in
  1945.
Merge Sort :
● Merge Sort works as follows :
      ● Divide the unsorted list into n
         sublists, repeatedly merge sublists
         to produce new sublists until each
         sublist contain one element .
         (list of one element consider sorted )
Best, Worst and Average
Cases :
● Best case :      O(n log n) .

● Worst case :      O(n log n) .

● Average case :       O(n log n) .

More Related Content

What's hot

Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
Protap Mondal
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)Tech_MX
 
Uninformed Search technique
Uninformed Search techniqueUninformed Search technique
Uninformed Search technique
Kapil Dahal
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
Dr Geetha Mohan
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
Trupti Agrawal
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
International Islamic University
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm propertiesLincoln School
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
Amrinder Arora
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
Dr Shashikant Athawale
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
jehan1987
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
University of Science and Technology Chitttagong
 
Queue ppt
Queue pptQueue ppt
Queue ppt
SouravKumar328
 
Heuristic Search Techniques Unit -II.ppt
Heuristic Search Techniques Unit -II.pptHeuristic Search Techniques Unit -II.ppt
Heuristic Search Techniques Unit -II.ppt
karthikaparthasarath
 

What's hot (20)

Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
 
Uninformed Search technique
Uninformed Search techniqueUninformed Search technique
Uninformed Search technique
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm properties
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentationMerge sort algorithm power point presentation
Merge sort algorithm power point presentation
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Heuristic Search Techniques Unit -II.ppt
Heuristic Search Techniques Unit -II.pptHeuristic Search Techniques Unit -II.ppt
Heuristic Search Techniques Unit -II.ppt
 

Viewers also liked

Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5Kumar
 
Search Algprithms
Search AlgprithmsSearch Algprithms
Search Algprithms
Shivam Singh
 
Native Code & Off-Heap Data Structures for Solr: Presented by Yonik Seeley, H...
Native Code & Off-Heap Data Structures for Solr: Presented by Yonik Seeley, H...Native Code & Off-Heap Data Structures for Solr: Presented by Yonik Seeley, H...
Native Code & Off-Heap Data Structures for Solr: Presented by Yonik Seeley, H...
Lucidworks
 
Basic Garbage Collection Techniques
Basic  Garbage  Collection  TechniquesBasic  Garbage  Collection  Techniques
Basic Garbage Collection TechniquesAn Khuong
 
Binary search
Binary search Binary search
Binary search Raghu nath
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data Structure
Talha Shaikh
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Binary search
Binary searchBinary search
Binary search
Gaurav Solanki
 
Link List
Link ListLink List
Link List
umiekalsum
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
 

Viewers also liked (12)

Data Structures & Algorithms
Data Structures & AlgorithmsData Structures & Algorithms
Data Structures & Algorithms
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
 
Search Algprithms
Search AlgprithmsSearch Algprithms
Search Algprithms
 
Native Code & Off-Heap Data Structures for Solr: Presented by Yonik Seeley, H...
Native Code & Off-Heap Data Structures for Solr: Presented by Yonik Seeley, H...Native Code & Off-Heap Data Structures for Solr: Presented by Yonik Seeley, H...
Native Code & Off-Heap Data Structures for Solr: Presented by Yonik Seeley, H...
 
Basic Garbage Collection Techniques
Basic  Garbage  Collection  TechniquesBasic  Garbage  Collection  Techniques
Basic Garbage Collection Techniques
 
Binary search
Binary search Binary search
Binary search
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data Structure
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Binary search
Binary searchBinary search
Binary search
 
Link List
Link ListLink List
Link List
 
Decision trees
Decision treesDecision trees
Decision trees
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 

Similar to Algorithms.

jn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdfjn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdf
VinayNassa3
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
BG Java EE Course
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
Mary Margarat
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
Tribhuvan University
 
Data Structures Notes
Data Structures NotesData Structures Notes
Data Structures Notes
RobinRohit2
 
Introduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searchingIntroduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searching
Mvenkatarao
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure Eman magdy
 
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures  Design-Notes-Searching-Hashing.pdfAD3251-Data Structures  Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
Ramco Institute of Technology, Rajapalayam, Tamilnadu, India
 
Chapter two
Chapter twoChapter two
Chapter two
mihiretu kassaye
 
Algorithms
Algorithms Algorithms
Algorithms
yashodhaHR2
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.ppt
Arumugam90
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
Computer Hardware & Trouble shooting
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notations
Rajendran
 
Data structures using C
Data structures using CData structures using C
Data structures using C
Pdr Patnaik
 
Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02
Salman Qamar
 
Data Structure & Algorithms - Introduction
Data Structure & Algorithms - IntroductionData Structure & Algorithms - Introduction
Data Structure & Algorithms - Introduction
babuk110
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
DrkhanchanaR
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
rajesshs31r
 

Similar to Algorithms. (20)

Iare ds ppt_3
Iare ds ppt_3Iare ds ppt_3
Iare ds ppt_3
 
jn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdfjn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdf
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
Data Structures Notes
Data Structures NotesData Structures Notes
Data Structures Notes
 
Introduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searchingIntroduction to Data Structures Sorting and searching
Introduction to Data Structures Sorting and searching
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
 
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures  Design-Notes-Searching-Hashing.pdfAD3251-Data Structures  Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
 
Chapter two
Chapter twoChapter two
Chapter two
 
Algorithms
Algorithms Algorithms
Algorithms
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.ppt
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notations
 
Data structures using C
Data structures using CData structures using C
Data structures using C
 
Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02
 
Data Structure & Algorithms - Introduction
Data Structure & Algorithms - IntroductionData Structure & Algorithms - Introduction
Data Structure & Algorithms - Introduction
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
 

More from Faculty of Science , portsaid Univeristy

Library Management System
Library Management SystemLibrary Management System
Library Management System
Faculty of Science , portsaid Univeristy
 

More from Faculty of Science , portsaid Univeristy (8)

Library Management System
Library Management SystemLibrary Management System
Library Management System
 
compiler vs interpreter
compiler vs interpretercompiler vs interpreter
compiler vs interpreter
 
الحسن بن الهيثم
الحسن بن الهيثمالحسن بن الهيثم
الحسن بن الهيثم
 
الحسن بن الهيثم
الحسن بن الهيثمالحسن بن الهيثم
الحسن بن الهيثم
 
Html course
Html courseHtml course
Html course
 
Teach yourself html_ar
Teach yourself html_arTeach yourself html_ar
Teach yourself html_ar
 
GUI
GUI GUI
GUI
 
Algorithms python arraylistmatrix
Algorithms python arraylistmatrixAlgorithms python arraylistmatrix
Algorithms python arraylistmatrix
 

Recently uploaded

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 

Recently uploaded (20)

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 

Algorithms.

  • 2. Algorithm ● the Latin form of Al-Khw?rizm . ● Algorithm:is well-defined computation procedure that takes some value,or set of values, as input and produces some value , or set of values,as output. ● a sequence of computational steps that transfer the input into the output ● a tool for solving a well-specified computional problem
  • 3. Example of Algorithms : ● when you need to sort asequence of numbers into nondecreasing order (31,42,59,26,58) Input:A sequence of n numbers (instance of program) (31,42,59,26,58). Output:A reordering of the input sequence (26,31,42,58,59).
  • 4. Solve this problem with python: def sort(a,n): i=0 for i in range(n): min=i m=i+1 for m in range(n): if a[m]<a[min]: min=m temp=a[i] a[i]=a[min] a[min]=temp
  • 5. Computer algorithms : ● in computer systems, an algorithm is basically an instance of logic written in software by software developers to be effective for the target computer, in order for the target machines to produce output from given input .
  • 6. Why computer algorithms are important ? ● The topic of algorithms is important in computer science because it allows for analysis on different ways to compute things and ultimately come up with the best way to solve a particular problem. By best I mean one that consumes the least amount of resources or has the fastest running time.
  • 7. What Kinds of problems are solved by algorithms? ● The Human Genome Project : made a great progress toward the goals of identifying all the 100.000 genes in human DNA determining the sequences of the 3 billion chemical base pairs that make up human DNA ,sorting the information in databases,and developing tools for data analysis.Each of these steps requires algorithms.
  • 8. What Kinds of problems are solved by algorithms? ● The Internet enables people around the world to quick access and retrieve large amounts of information. ● Electronic commerce enables goods and services to be exchanged electronically. ● Manufacturing and other commerical enterprises need to allocate rescources in the most beneficial way.
  • 9. Advantages of "Python" as a Programming Language ● Python is an interpreted, high-level programming language, pure object-oriented, and powerful server-side scripting language for the Web. Like all scripting languages, Python code resembles pseudo code. Its syntax's rules and elegant design make it readable even among multiprogrammer development teams.
  • 10. Advantages of "Python" as a Programming Language : Readability : ● Python's syntax is clear and readable. ● Python has fewer "dialects" than other l languages, such as Perl. And because the block structures in Python are defined by indentations
  • 11. Advantages of "Python" as a Programming Language : It Is Simple to Get Support : ● Python community always provides support to Python users. ● Python code is freely available for everyone. ● many people are creating new enhancements to the language and sending them for approval
  • 12. Advantages of "Python" as a Programming Language : Fast to Learm . Fast to Code : ● Python provides fast feedback in several ways. ● Python provides a bottom-up development style in which you can build your applications by importing and testing critical functions in the interpreter before you write the top-level code that calls the functions.
  • 13. Advantages of "Python" as a Programming Language : Reusability : ● You can easily share functionality between your programs by breaking the programs into modules, and reusing the modules as components of other programs.
  • 14. Advantages of "Python" as a Programming Language : Portability : ● Besides running on multiple systems, Python has the same interface on multiple platforms. Its design isn't attached to a specific operational system because it is written in portable ANSI C. This means that you can write a Python program on a Mac, test it using a Linux environment, and upload it to a Windows server.
  • 15. Advantages of "Python" as a Programming Language : Object-Oriented Programming : ● Some of the implemented OO functionality in Python is inheritance and polymorphism.
  • 16. Examples of "Python based Solutions" for different "Computer Algorithms " ..
  • 17. SEARCHING : ● The operation of finding the location LOC of ITEM in DATA, or printing some message that ITEM does not appear there. ● There are many differtent serarching algorithms : The algorithm deponds on the way the information in DATA is organized.
  • 18. Linear Search : ● Known as sequential search ● is a method for finding a particular value in alist, that consists of checking every one of its elements, one at a time and in sequence, until the desired one is found.
  • 19. linear search: #linear search in python: def linear_search (a,n,item): k=0 for k in range(n): if item ==a[k]: loc=k return loc
  • 20. the disadvantages of linear search : ● in linear search it needs more space and time complexity. ● in linear search if the key element is the last element and the search is from first element that is a worst case, if the key element is the first element and the search is from last element then also is the worst case.
  • 21. Best, Worst and Average Cases : ● Worst case :- O(n) ● Average case :- O(n).
  • 22. binary search : ● Suppose DATA ia an array which i stored in increasing numerical order or alphabetically. Then There are an extremely efficient searching algorithm , called binary search, That can be used to find the location LOC of a given ITEM of information in DATA.
  • 24. Binary Search : def binary_search(data,n,lb,ub,item): beg=lb end=up mid=(beg+end)/2 while beg<=end and data[mid]!=item: if item<data[mid]: end=mid-1 else: beg=mid+1 mid=(beg+end)/2
  • 25. Binary Search : if data[mid]==item: loc=mid else : loc=-1 return loc
  • 26. Best, Worst and Average cases : ● Worst case :- O(log2 n). ● Average case :- O(log2 n).
  • 27. The Binary Search Algorithm works as follows : ● During each stage of our algorithm, our search for ITEM is reduced to a segment of element of DATA: DATA[BEG],DATA[BEG+1],............., DATA[END] ● The algorithm compares ITEM with the middle element DATA[MID] of the segment MID=((BEG+END)/2)
  • 28. The Binary Search Algorithm works as follows : ● If ITEM < DATA[MID], then ITEM can appear only in the left half of the segment: DATA[BEG],DATA[BEG+1],............., DATA[MID-1] -reset END=MID-1. ● If ITEM > DATA[MID], then ITEM can appear only in the right half of the segment:: DATA[MID+1],DATA[MID+2],...........,DATA[END]. -reset BEG=MID+1.
  • 29. Limitations of the Binary Search Algorithm : ● -The Binary Search Algorithm requires two conditions: (1) the list must be sorted. (2) direct access to the middle element in any sublist.
  • 30. Limitations of the Binary Search Algorithm : ● keeping data in sorted array is normally very expensive when there are many insertions and deletions. ● Thus one may use a different data structure such as linked list or a binary search tree
  • 31. Sorting : ● Sorting : is the process of rearranging the data in array or list in insreasing or decreasing order .
  • 32. Insertion Sort : ● Simple sorting algorithim . ● Ii is very popular when first sorting . ● Efficient for sorting small data . (more efficient than bubble and selection sort) ● Slow for sorting large data, thus Time can be saved by performing a binary search to find the location in which insert data[i] in the in input array . ● Online : can sort input array as it recevied .
  • 33. Insertion Sort : ● insertion sort works as follows : ■ removes an element from the input data, inserting it into the correct position , to find the correct position we compare this element with each element in the input array, from right to left, until no input elements remain.
  • 34.
  • 35. Insertion Sorting : def InsertionSort(data,n): for j in range(1,n): key = data[j] i=j-1 while (data[i] > key): data[i+1] = data[i] i=i-1 data[i+1] = key
  • 36. Best, Worst and Average Cases : The Best Case: in which the input array was already sorted .This gives Inserting Sort linear running time O(n). ● The Worst Case : in which the input array was sorted in reverse order .This gives Inserting Sort quadratic running time O(n2). ● The Average Case : O(n2) .
  • 37. Selection Sort : ● Selection sort works as follows : ● Find the location loc of the smallest element in input array and put it in the first position, find the location loc of the second smallest element and put it in the second position, And so on .
  • 38.
  • 39. Selection Sort : def sort(a,n): i=0 for i in range(n): min=i m=i+1 for m in range(n): if a[m]<a[min]: min=m temp=a[i] a[i]=a[min] a[min]=temp
  • 40. Best, Worst and Average Cases : ● Best case : O(n2) . ● Worst case : O(n2) . ● Average case : O(n2) .
  • 41. Merge Sort : ● Merge sort : a divide and conquer algorithm that was invented by John von Neumann in 1945.
  • 42. Merge Sort : ● Merge Sort works as follows : ● Divide the unsorted list into n sublists, repeatedly merge sublists to produce new sublists until each sublist contain one element . (list of one element consider sorted )
  • 43.
  • 44. Best, Worst and Average Cases : ● Best case : O(n log n) . ● Worst case : O(n log n) . ● Average case : O(n log n) .