sorted

C# Datatype for large sorted collection with position?

I am trying to compare two large datasets from a SQL query. Right now the SQL query is done externally and the results from each dataset is saved into its own csv file. My little C# console application loads up the two text/csv files and compares them for differences and saves the differences to a text file. Its a very simple applicatio...

The Most Efficient Algorithm to Find First Prefix-Match From a Sorted String Array?

Input: 1) A huge sorted array of string SA; 2) A prefix string P; Output: The index of the first string matching the input prefix if any. If there is no such match, then output will be -1. Example: SA = {"ab", "abd", "abdf", "abz"} P = "abd" The output should be 1 (index starting from 0). What's the most algorithm way to do this ki...

Java: What is the best way to find elements in a sorted List?

I have a List<Cat> sorted by the cats' birthdays. Is there an efficient Java Collections way of finding all the cats that were born on January 24th, 1983? Or, what is a good approach in general? ...

What does python3 do with the methods passed to the "key" argument of sorted()?

I have a question about how python treats the methods passed to sorted(). Consider the following small script: #!/usr/bin/env python3 import random class SortClass: def __init__(self): self.x = random.choice(range(10)) self.y = random.choice(range(10)) def getX(self): return self.x def getY(self): ...

Efficient ways of inserting a new cell into a sorted UITableView?

I am trying to insert a new cell into a table view where the data is sorted. Is there an easy & efficient way to do this using the API? The easiest way seems to be insert the new data into an NSMutableArray, sort using a sort descriptor, and call reloadData. This should only redisplay the visible rows, so it doesn't look too bad. Would...

C# alternative for the C++ STL set<T>

Hi I'm looking for a sorted data structure, that will be similar to the STL set(T). I found SortedList, but it requires (key, val), I'm looking for something like List(string) - only sorted. I found on the web Spring.Collections, but my framework does not recognize it. Is there a simple SortedSet I could use in the regular basic fra...

dictionary of object

hi all, I have a sorted dict { 1L: '<'New_Config (type: 'String') (id: 1L) (value: 4L) (name: 'account_receivable')'>', 2L: '<'New_Config (type: 'string') (id: 2L) (value: 5L) (name: 'account_payable')'>', 3L: '<'New_Config (type: 'String') (id: 3L) (value: 8L) (name: 'account_cogs ')'>', 4L: '<'New_Config (type: 'String') (id: 4L)(...

How to force refresh the DataGridView's content?

I want to make a sorted datagridview input. The following code snippet doesn't quite cut it; even if i put a grd.Refresh, the datagridview doesn't show its updated values. If i press arrow down key and go up again, the grid is refreshing. Is there any other way i can force refresh to datagridview's content? using System; using System....

Sorted array Big o notation

Hello I just have a simple question, why is the big O notation of a sorted array O(log N)? It will be a sorted array. ...

Java Code Review: Merge sorted lists into a single sorted list

I want to merge sorted lists into a single list. How is this solution? I believe it runs in O(n) time. Any glaring flaws, inefficiencies, or stylistic issues? I don't really like the idiom of setting a flag for "this is the first iteration" and using it to make sure "lowest" has a default value. Is there a better way around that? publi...

Is python's sorted() function guaranteed to be stable?

The documentation doesn't guarantee that. Is there any other place that it is documented? I'm guessing it might be stable since the sort method on lists is guaranteed to be stable (Notes 9th point: "Starting with Python 2.3, the sort() method is guaranteed to be stable"), and sorted is functionally similar. However, I'm not able to fin...

Sorted hash table (map, dictionary) data structure design

Here's a description of the data structure: It operates like a regular map with get, put, and remove methods, but has a sort method that can be called to sorts the map. However, the map remembers its sorted structure, so subsequent calls to sort can be much quicker (if the structure doesn't change too much between calls to sort). For e...

Data structure for efficiently returning the top-K entries of a hash table (map, dictionary)

Here's a description: It operates like a regular map with get, put, and remove methods, but has a getTopKEntries(int k) method to get the top-K elements, sorted by the key: For my specific use case, I'm adding, removing, and adjusting a lot of values in the structure, but at any one time there's approximately 500-1000 elements; I want ...

Heap class in .NET

Possible Duplicate: Fibonacci, Binary, or Binomial heap in c#? Is there any class like heap in .NET? I need some kind of collection from which I can retrieve min. element. I just want 3 methods: -add -removeMinElement -getMinElement I can't use sorted list because there keys has to be unique, and I might have several identica...

SQL Query - one column must be distinct, restricted column must be most recent

Hey there, I have a CATEGORIES table that links to an ITEMS table (one to many). Each item table could have multiple barcodes in the BARCODES table (one to many). The idea is that a new barcode may be added against an item at some point, but the old data is stored in the BARCODES table so that if a search is done with an order with las...

Java - sorted stack

Hello, I need a sorted stack. I mean, the element removed from the stack must be the one with great priority. Stack dimension varies a lot (becomes bigger very fast). I need also to search elements in that stack. Does Java give some good implementation for this? What class or algorithm do you suggest for this? I'm using a PriorityQue...

How to store sorted records in csv file ?

I sort the records of the datatable datewise with the column TradingDate which is type of datetime. TableWithOnlyFixedColumns.DefaultView.Sort = "TradingDate asc"; Now I want to store these sorted records into csv file but stored records are not sorted by date. TableWithOnlyFixedColumns.DefaultView.Sort = "TradingDate asc"; DataTab...

Interpolation search on strings

For those of you not familiar with interpolation search, it is method to search for a value in a sorted array that is potentially faster than binary search. You look at the first and last element and (assuming that the contents of the array are uniformly distributed) linearly interpolate to predict the location. For example: we have an ...

insert to sorted position linked list

Hello, I have question quite much related to this one I asked a while ago http://stackoverflow.com/questions/3743764/place-a-value-in-the-sorted-position-immediately I wonder if you can use the same approach in that you step backward in a linked list to find the position it should be inserted into. If it is possible how do you loop a ...

Sorted array list in Java

I'm baffled that I can't find a quick answer to this. I'm essentially looking for a datastructure in Java which implements the java.util.List interface, but which stores its members in a sorted order. I know that you can use a normal ArrayList and use Collections.sort() on it, but I have a scenario where I am occasionally adding and of...