Lost Password?


Go Back   CodeCall Programming Forum > Software Development > General Programming > Programming Theory

Programming Theory Discuss programming theory, algorithm efficiency, logic, and other any other category where math and computer science overlap.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-07-2008, 09:25 PM
Pillager Pillager is offline
Newbie
 
Join Date: Sep 2008
Posts: 1
Rep Power: 0
Pillager is on a distinguished road
Default Homework help - Algorithm complexity

Hi guys, I was wondering if anyone could give me any tips on these exercises I am trying.

I'm trying to make an algorithm that runs proportional to O(log(nČ)).

The attempt I've coded (in java) looks something like this:

Code:
int count = 0;

for(int i=1; i<n; i*=2) {

  for(int j=0; j<n; j++) {

    for(int k=0; k<n; k++) {

     count++; }}}

Now from my understanding I thought that the two inner loops would give an NČ complexity, which would then be multiplied by the outer loop which has a log complexity. I assume something fairly fundamental is tripping me up, I suspect either the order of my loops or a math error based on the log part.

Anyway thanks for any advice you can give, feel free to give any general tips on algorithm analysis if you want as I think I only have a vague grasp on the topic.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-07-2008, 10:42 PM
morefood2001's Avatar   
morefood2001 morefood2001 is offline
Guru
 
Join Date: Jan 2008
Location: Western New York
Posts: 1,420
Last Blog:
VPS Hosting with Revie...
Rep Power: 16
morefood2001 is just really nicemorefood2001 is just really nicemorefood2001 is just really nicemorefood2001 is just really nice
Send a message via AIM to morefood2001 Send a message via MSN to morefood2001 Send a message via Yahoo to morefood2001 Send a message via Skype™ to morefood2001
Default Re: Homework help - Algorithm complexity

This algorithm is an N^3 algorithm.

To get logarithm time, you need recursion so that you only hit a fraction of the total number of values. Tree data structures are good at getting logarithmic time.

For example, if you have 5 elements, you will only touch through 4 of them.
__________________
Phil Matuskiewicz
My Personal Website My Other Website
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-08-2008, 12:33 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: Homework help - Algorithm complexity

O(log(n^2)) is actually O(2*log(n)) or O(log(n)). A typical algorithm of this complexity is a binary search.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-08-2008, 05:06 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,478
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default Re: Homework help - Algorithm complexity

The "number guessing game" is generally a good example of an O(log(n)) algorithm.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
best algorithm for given problem artartart General Programming 1 05-14-2008 11:53 AM
Peterson's Algorithm zm1723 C# Programming 1 12-13-2007 11:47 AM
Help : days algorithm rivci Java Help 4 12-13-2007 05:57 AM
New Algorithm Matches Any Tumor Cells To Best Possible Anticancer Treatments Kernel Programming News 0 07-29-2007 08:52 PM
efficient algorithm sovixi Python 3 04-19-2007 02:47 PM


All times are GMT -5. The time now is 09:00 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads