Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 11th, 2004, 09:40 PM
7th.com 7th.com is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Long Island, New York
Posts: 4 7th.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Engineering question

Assume we have direct access to both front and rear ends of a linear list L.

Consider the following five operations on such a list:
- PushFront(x, L): insert item x on the front end of list L.
- PopFront(L): remove the front item from list L and return it.
- PushRear(x, L): insert item x on the rear end of list L.
- PopRear(L): remove the rear item from list L and return it.
- FindMin(L): return the smallest item on list L.

How to support these operations in O(1) amortized time? and how to support these operations in O(1) worst-case time?

thanks

Reply With Quote
  #2  
Old November 12th, 2004, 09:05 AM
MBirchmeier's Avatar
MBirchmeier MBirchmeier is offline
I <3 ASCII
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Wishing i was still at... The Ohio State University
Posts: 2,272 MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 h 15 m 17 sec
Reputation Power: 838
Send a message via AIM to MBirchmeier Send a message via Yahoo to MBirchmeier
Findmin() would need to run in T(L) time...

plus there's actually a similar thread open at

http://http://forums.devshed.com/t155141/s.html

(a few threads down)

-MBirchmeier
__________________
My blog on programming related things. Hopefully I won't bog it down with details on my life

Apparently even computers have freudian slips.

0x4279 7465 204D 6521

Reply With Quote
  #3  
Old November 12th, 2004, 09:50 AM
7th.com 7th.com is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Location: Long Island, New York
Posts: 4 7th.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I think the first 4 methods can be done at O(1) with no problem, because these 4 methods doesn't have to search for anything before they perform pop/push, they are just simply insert and delete front/back.

For findmin(), it's hard to get O(1) in real time, usually we have to set a pointer point to the min value in the current linear list when we do insert, then we can compare the current min value in the list to the new input value. However, if we pop the min value, then we have to go through the list once again to find the current. That where I get confuse.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Engineering question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT