David Prieto
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Zwischenablage
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Reines HTML
Menü Note settings Note Insights Versions and GitHub Sync Sharing URL Create Hilfe
Create Create new note Create a note from template
Menü
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Zwischenablage
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Reines HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Zwischenablage
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Big O Notation ## Pre-exercise Let's supose that we have an array of NAMES These NAMES are not sorted. We want to find if we have in NAMES somebody whose name is "Claudia" Construct an algorithm to find this out. You have to output if there is a "Claudia" in NAMES or not. * If NAMES has 5 names * If NAMES has 50 names * If NAMES has 5000 names Supose that each instruction takes 1 nanosecond to be done. Count how many nanosecons we have to wait for the 3 mentioned cases. ```_= FOUND = FALSE // flag variable loop for I from 0 to (5-1) //length -1 if NAMES[I] = "CLAUDIA" FOUND = TRUE end if end loop if FOUND = TRUE output "We have found a Claudia" else output "We haven't found a Claudia" end if ``` Let's count Line 1: 1 Line 2: 5 Line 3: 5 Line 4: 0-5 // zero if we have 0 Claudias and 5 if all of them are Claudias Line 7: 1 Line 8-10: 1 Total: 13-18 If we have 50 ```_= FOUND = FALSE // flag variable loop for I from 0 to (50-1) //length -1 if NAMES[I] = "CLAUDIA" FOUND = TRUE end if end loop if FOUND = TRUE output "We have found a Claudia" else output "We haven't found a Claudia" end if ``` Let's count how many times are they going to be executed each line (in worst case scenario) Line 1: 1 Line 2: 50 Line 3: 50 Line 4: 0-50 (no claudias or all claudias) Line 7: 1 Line 8-10: 1 Total: 103 -153 If we have 5000 ```_= FOUND = FALSE // flag variable loop for I from 0 to (5000-1) //length -1 if NAMES[I] = "CLAUDIA" FOUND = TRUE end if end loop if FOUND = TRUE output "We have found a Claudia" else output "We haven't found a Claudia" end if ``` Let's count how many times are they going to be executed each line (in worst case scenario) Line 1: 1 Line 2: 5000 Line 3: 5000 Line 4: 0-5000 (no claudias or all claudias) Line 7: 1 Line 8-10: 1 Total: 10003 -15003 Let's say that we want to access the third element of the array NAMES Construct an algorithm to output the third name of the array NAMES in the 3 cases and count how many lines are going to be executed. ``` output NAMES[2] ``` or ``` I = 2 output NAMES[I] ``` If we have 5 names in names This is only 1 line. If we have 50 names in NAMES, this is still 1 line executed. If we have 5000 names in NAMES, this is still 1 line executed. ## Big O Notation So the Big O notation is a way to describe the complexity of an algorithm (or a process) to the upper bound of it when it grows in some variables. ## Change in the O(n) algorithm Let's suposse that we have to change all the names of all the elements on the array in the case that we have found a CLAUDIA (we need to make them all be called Mr. Anderson) ```= FOUND = FALSE // flag variable loop for I from 0 to (5000-1) //length -1 if NAMES[I] = "CLAUDIA" FOUND = TRUE end if end loop if FOUND = TRUE loop for J from to (5000-1) NAMES[J] = "Mr. Anderson" end loop else output "We haven't found a Claudia" end if ``` If we have 5 names in NAMES how many lines are we going to execute? :::spoiler Line 1: 1 Line 2: 5 Line 3: 5 Line 4: 0-5 Line 7: 1 Line 8: 0-5 Line 9: 0-5 Line 12: 1-0 Total 13-27 ::: If we have 50 names how many lines are we going to execute? :::spoiler Line 1: 1 Line 2: 50 Line 3: 50 Line 4: 0-50 Line 7: 1 Line 8: 0-50 Line 9: 0-50 Line 12: 1-0 Total 103-252 ::: If we have 5 000 names how many lines are we going to execute? :::spoiler Line 1: 1 Line 2: 5000 Line 3: 5000 Line 4: 0-5000 Line 7: 1 Line 8: 0-5000 Line 9: 0-5000 Line 12: 1-0 Total 10003-25002 ::: If we have 5 000 000 names how many lines are we going to execute? :::spoiler Line 1: 1 Line 2: 5000000 Line 3: 5000000 Line 4: 0-5000000 Line 7: 1 Line 8: 0-5000000 Line 9: 0-5000000 Line 12: 1-0 Total 10000003-25000002 ::: This is linear complexity and is written as O(n) The previous example of accessing elments of an array is called constant and is written O(k) or O(1)

    Importieren aus der Zwischenablage

    Markdown oder Website hier einfügen

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    Diese Notiz ist gesperrt

    Entschuldigung, nur der Besitzer darf die Notiz bearbeiten.

    Limit erreicht

    Entschuldigung, die maximale Länge der Notiz ist erreicht.
    Bitte reduzieren Sie den Inhalt oder nutzen zwei Notizen, danke.

    Aus GitHub Gist importieren

    Aus Snippet importieren

    oder

    Zu Snippet exportieren

    Sind sie sicher?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    Bitte laden Sie die Seite neu

    Ihre Client Version ist nicht mit dem Server kompatibel
    Neu laden zum Updaten.
    Neue Version verfügbar.
    Versionshinweise
    Neu laden für neue Funktionen
    Ihr Nutzerstatus hat sich geändert.
    Neu laden für neuen Nutzerstatus.

    Sign in

    Forgot password

    oder

    By clicking below, you agree to our terms of service.

    Einloggen über Facebook Einloggen über Twitter Einloggen über GitHub Einloggen über Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Hilfe

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Dokumente

    Help & Tutorial

    How to use Book mode

    Beispiel Präsentation

    API Docs

    Edit in VSCode

    Install browser extension

    Kontakte

    Feedback

    Discord

    Kontakt

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Beispiel Reference
    # Überschrift Überschrift 基本排版
    - Stichpunkte
    • Stichpunkte
    1. Nummeriert
    1. Nummeriert
    - [ ] To Do Liste
    • To Do Liste
    > Zitat
    Zitat
    **Fett** Fett
    *Kursiv* Kursiv
    ~~Durchgestrichen~~ Durchgestrichen
    19^th^ 19th
    H~2~O H2O
    ++Unterstrichen++ Unterstrichen
    ==Markiert== Markiert
    [link text](https:// "title") Link
    ![image alt](https:// "title") Foto
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Extern
    $L^aT_eX$ LaTeX
    :::info
    Hinweisfeld
    :::

    Hinweisfeld

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully