Posted on 2001-09-14
Last Modified: 2008-03-06
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
Question by:quietstorm
LVL 30

Expert Comment

ID: 6483387
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.

Expert Comment

ID: 6485614
Just go thru some Data Structures Book, may be Horowitz & Sahani will help. You have all the answers you want there.


Accepted Solution

kirsh earned 50 total points
ID: 6486908

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.

Expert Comment

ID: 6487074
>How can I give an example of an algorithm that is

Yes, you can. Give us some...

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now