Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

Algorithms

How can I give an example of an algorithm that is

O(1) - bounded (by a constant)time

O(N)- linear time

O(N2) - quadratic time
0
quietstorm
Asked:
quietstorm
1 Solution
 
AxterCommented:
Is this homework?

It is against EE policy for experts to do homework questions.
We can help you with code that you have already done, but we can not give you full answers.

Please attempt to do part of the work, and then ask a specific question when you get stuck.
0
 
sateesh_babuCommented:
Just go thru some Data Structures Book, may be Horowitz & Sahani will help. You have all the answers you want there.

Babu
0
 
kirshCommented:
Hi,

O(1) : Constant = PRINT "A"
                  PRINT "B"

O(N) : A loop = READ N
                FOR I=1 TO N DO
                     PRINT "N"

O(N2) : A loop inside a loop = READ N
                               READ L
                               FOR I=1 TO N DO
                                   FOR I=1 TO L DO
                                       PRINT "L"

This is pseudo-code of course.

Naftali Kirsh.
0
 
proskigCommented:
>How can I give an example of an algorithm that is

Yes, you can. Give us some...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now