SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
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) .

Weitere ähnliche Inhalte

Was ist angesagt?

Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2Self-Employed
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting AlgorithmsPranay Neema
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST Kathirvel Ayyaswamy
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfMCCMOTOR
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursionAbdullah Al-hazmy
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquerKrish_ver2
 
Queue data structure
Queue data structureQueue data structure
Queue data structureanooppjoseph
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsArvind Krishnaa
 
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Hassan Ahmed
 

Was ist angesagt? (20)

Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Strassen.ppt
Strassen.pptStrassen.ppt
Strassen.ppt
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Python list
Python listPython list
Python list
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
B trees
B treesB trees
B trees
 
B tree
B treeB tree
B tree
 
Recursion
RecursionRecursion
Recursion
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
 

Andere mochten auch

Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5Kumar
 
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 StructureTalha Shaikh
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTUREArchie Jamwal
 

Andere mochten auch (11)

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
 
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
 

Ähnlich wie 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.pdfVinayNassa3
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0BG Java EE Course
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm AnalysisMary Margarat
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
Data Structures Notes
Data Structures NotesData Structures Notes
Data Structures NotesRobinRohit2
 
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 searchingMvenkatarao
 
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
 
CS3114_09212011.ppt
CS3114_09212011.pptCS3114_09212011.ppt
CS3114_09212011.pptArumugam90
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsRajendran
 
Data structures using C
Data structures using CData structures using C
Data structures using CPdr Patnaik
 
Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02Ds12 140715025807-phpapp02
Ds12 140715025807-phpapp02Salman Qamar
 
Data Structure & Algorithms - Introduction
Data Structure & Algorithms - IntroductionData Structure & Algorithms - Introduction
Data Structure & Algorithms - Introductionbabuk110
 
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
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptxrajesshs31r
 

Ähnlich wie 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...
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
 

Mehr von 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
 

Kürzlich hochgeladen

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 

Kürzlich hochgeladen (20)

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

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) .