wu :: forums
« wu :: forums - count the valid blocks »

Welcome, Guest. Please Login or Register.
Nov 24th, 2024, 6:59am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Icarus, SMQ, william wu, towr, Eigenray, ThudnBlunder, Grimbal)
   count the valid blocks
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: count the valid blocks  (Read 1039 times)
inexorable
Full Member
***





   


Posts: 211
count the valid blocks  
« on: Jun 10th, 2010, 3:13pm »
Quote Quote Modify Modify

Given an array A which holds a permutation of 1,2,...,n. A sub-block A[i..j]  
of an array A is called a valid block if all the numbers appearing in A[i..j]  
are consecutive numbers (may not be in order).  
 
Given an array A= [ 7 3 4 1 2 6 5 8] the valid blocks are [3 4], [1,2], [6,5],  
[3 4 1 2], [3 4 1 2 6 5], [7 3 4 1 2 6 5], [7 3 4 1 2 6 5 8]  
 
Give an O( n log n) algorithm to count the number of valid blocks.  
IP Logged
Hippo
Uberpuzzler
*****





   


Gender: male
Posts: 919
Re: count the valid blocks  
« Reply #1 on: Jun 11th, 2010, 6:01am »
Quote Quote Modify Modify

You cannot in O(n log n) find result of size \Omega(n^2).
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: count the valid blocks  
« Reply #2 on: Jun 11th, 2010, 7:42am »
Quote Quote Modify Modify

on Jun 11th, 2010, 6:01am, Hippo wrote:
You cannot in O(n log n) find result of size \Omega(n^2).
You only have to give the count, not the blocks.
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
inexorable
Full Member
***





   


Posts: 211
Re: count the valid blocks  
« Reply #3 on: Jul 28th, 2010, 1:13pm »
Quote Quote Modify Modify

A solution is posted at  
http://stackoverflow.com/questions/1824388/finding-sorted-sub-sequences- in-a-permutation
Shocked
 
could someone please explain it?
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board