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. Algorithms
  4. ask for a algorithm about visit array

ask for a algorithm about visit array

Scheduled Pinned Locked Moved Algorithms
designalgorithmsdata-structures
8 Posts 5 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.
  • R Offline
    R Offline
    richardye
    wrote on last edited by
    #1

    There is a int array consists of 1001 elements. Inside it, only two element's values are equal. I mean that there are two items have the same value, and the other items are different. Design a algorithm according to the following commands: 1 every item of the array can only be visited once 2 find out the same value many thanks

    CPalliniC M M 3 Replies Last reply
    0
    • R richardye

      There is a int array consists of 1001 elements. Inside it, only two element's values are equal. I mean that there are two items have the same value, and the other items are different. Design a algorithm according to the following commands: 1 every item of the array can only be visited once 2 find out the same value many thanks

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Good luck. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • R richardye

        There is a int array consists of 1001 elements. Inside it, only two element's values are equal. I mean that there are two items have the same value, and the other items are different. Design a algorithm according to the following commands: 1 every item of the array can only be visited once 2 find out the same value many thanks

        M Offline
        M Offline
        MarkB777
        wrote on last edited by
        #3

        "every item of the array can only be visited once" I'll be interested to see if anyone comes up with something.

        Mark Brock Click here to view my blog

        D 1 Reply Last reply
        0
        • M MarkB777

          "every item of the array can only be visited once" I'll be interested to see if anyone comes up with something.

          Mark Brock Click here to view my blog

          D Offline
          D Offline
          Dexterus
          wrote on last edited by
          #4

          There is an easy way from the pov of the algorithm but depending on what they mean by integer it may be quite painful. Think tagging bits.

          CPalliniC 1 Reply Last reply
          0
          • D Dexterus

            There is an easy way from the pov of the algorithm but depending on what they mean by integer it may be quite painful. Think tagging bits.

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            I agree: it strongly depends on their integer size.

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            In testa che avete, signor di Ceprano?

            R 1 Reply Last reply
            0
            • CPalliniC CPallini

              I agree: it strongly depends on their integer size.

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

              R Offline
              R Offline
              richardye
              wrote on last edited by
              #6

              What does it mean? Can you explain it in more details or make a simple example? many thanks

              CPalliniC 1 Reply Last reply
              0
              • R richardye

                There is a int array consists of 1001 elements. Inside it, only two element's values are equal. I mean that there are two items have the same value, and the other items are different. Design a algorithm according to the following commands: 1 every item of the array can only be visited once 2 find out the same value many thanks

                M Offline
                M Offline
                Member 4194593
                wrote on last edited by
                #7

                Build a linked list (or tree, but for 1001 elements it would be overkill), visit the array one time for each element (or at least until you find the matching elements), build an entry containing the index of the value and the value at that index, link it in the linked list at the tail of the list (because you need to traverse the entire existing list checking for a match) and stop when you find a match. You then have the index of both values (one in the list and the last entry built) and the value, and have only accessed the list one time for each element.

                1 Reply Last reply
                0
                • R richardye

                  What does it mean? Can you explain it in more details or make a simple example? many thanks

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  What is the range of your integers?

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                  In testa che avete, signor di Ceprano?

                  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