Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to find the average, worst complexity of a code

How to find the average, worst complexity of a code

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmshelptutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janani13
    wrote on last edited by
    #1

    How to find the average, worst complexity of a code?? say for ex,

    for i= 1 to n
    {

    }
    for j= 1 to i
    {
    x=x+1

        }
    

    Please help me ..

    D R 2 Replies Last reply
    0
    • J janani13

      How to find the average, worst complexity of a code?? say for ex,

      for i= 1 to n
      {

      }
      for j= 1 to i
      {
      x=x+1

          }
      

      Please help me ..

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Huh? :confused: Did you bother looking at your post? Notice anything "strange" about it? :doh:

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Man who follows car will be exhausted." - Confucius

      1 Reply Last reply
      0
      • J janani13

        How to find the average, worst complexity of a code?? say for ex,

        for i= 1 to n
        {

        }
        for j= 1 to i
        {
        x=x+1

            }
        

        Please help me ..

        R Offline
        R Offline
        Radhakrishnan G
        wrote on last edited by
        #3

        You have to claculate from your program; for this example first for loop execute "n" times and second loo execute n times because value of "i" is "n" suppose "T1" time need to execute one iteration in the first for loop and "T2" time needs for one iteration in second loop so it take T1*n + T2*n that is an order of n, ie it depend on input variable "n" This is the time complexity

        J 1 Reply Last reply
        0
        • R Radhakrishnan G

          You have to claculate from your program; for this example first for loop execute "n" times and second loo execute n times because value of "i" is "n" suppose "T1" time need to execute one iteration in the first for loop and "T2" time needs for one iteration in second loop so it take T1*n + T2*n that is an order of n, ie it depend on input variable "n" This is the time complexity

          J Offline
          J Offline
          janani13
          wrote on last edited by
          #4

          Hai Radhakrishnan, Thanks for your responce. Can you come again to tell me how it can be represented in Big O notation...

          M 1 Reply Last reply
          0
          • J janani13

            Hai Radhakrishnan, Thanks for your responce. Can you come again to tell me how it can be represented in Big O notation...

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #5

            O(n) ?

            Watched code never compiles.

            R 1 Reply Last reply
            0
            • M Maximilien

              O(n) ?

              Watched code never compiles.

              R Offline
              R Offline
              Radhakrishnan G
              wrote on last edited by
              #6

              Yes it is the order of n O(n)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups