distinct-values

How to count distinct values in a list in linear time?

社会主义新天地 提交于 2019-12-18 07:51:02
问题 I can think of sorting them and then going over each element one by one but this is nlogn. Is there a linear method to count distinct elements in a list? 回答1: Update: - distinct vs. unique If you are looking for "unique" values (As in if you see an element "JASON" more than once, than it is no longer unique and should not be counted) You can do that in linear time by using a HashMap ;) (The generalized / language-agnostic idea is Hash table) Each entry of a HashMap / Hash table is <KEY, VALUE

How to create a HashSet<List<Int>> with distinct elements?

不问归期 提交于 2019-12-17 16:39:47
问题 I have a HashSet that contains multiple lists of integers - i.e. HashSet<List<int>> In order to maintain uniqueness I am currently having to do two things: 1. Manually loop though existing lists, looking for duplicates using SequenceEquals . 2. Sorting the individual lists so that SequenceEquals works currently. Is there a better way to do this? Is there an existing IEqualityComparer that I can provide to the HashSet so that HashSet.Add() can automatically handle uniqueness? var hashSet = new

Given a number, produce another random number that is the same every time and distinct from all other results

拈花ヽ惹草 提交于 2019-12-17 10:05:41
问题 Basically, I would like help designing an algorithm that takes a given number, and returns a random number that is unrelated to the first number. The stipulations being that a) the given output number will always be the same for a similar input number, and b) within a certain range (ex. 1-100), all output numbers are distinct. ie., no two different input numbers under 100 will give the same output number. I know it's easy to do by creating an ordered list of numbers, shuffling them randomly,

Getting a distinct value across 2 union sql server tables

烂漫一生 提交于 2019-12-13 12:24:49
问题 I'm trying to get all distinct values across 2 tables using a union. The idea is to get a count of all unique values in the columnA column without repeats so that I can get a summation of all columns that contain a unique columnA. This is what I tried (sql server express 2008) select count(Distinct ColumnA) from ( select Distinct ColumnA as ColumnA from tableX where x = y union select Distinct ColumnA as ColumnA from tableY where y=z ) 回答1: SELECT COUNT(distinct tmp.ColumnA) FROM ( (SELECT

Joining two MSSQL tables (unique values)

久未见 提交于 2019-12-13 12:23:12
问题 I have two tables in my SQL Server db that I want to join: Person table: PersonId Name DeviceId 001 John 11111 002 Eric 22222 003 Steve 33333 Device Table: DeviceId Date 11111 2013-02-01 11111 2013-02-02 11111 2013-02-03 22222 2013-02-03 22222 2013-02-01 The result I want is the following PersonId Name DeviceId Date IsRegistered 001 John 11111 2013-02-03 1 002 Eric 22222 2013-02-03 1 003 Steve 33333 null 0 So as you see I want a join between the tables and I only want unique values. The data

How to get the distinct element from mediastore by java

落爺英雄遲暮 提交于 2019-12-13 05:43:36
问题 I am trying to get the file names of all the audio files but I am getting same file names for multiple songs 1.I cannot use DISTINCT key word as I am getting the file names from DATA . 2.I am using the Mediastore.Files So the select it takes MEDIA_TYPE so this way is also not possible . 3 .I want to get the Parent value as distinct not the repeating value . So the only way is by doing in java .I followed the method given here but I am not able to set Here is a piece of my code if (audioCursor

How to find consecutive unique values in a column ordered in the same way as the original table?

穿精又带淫゛_ 提交于 2019-12-13 03:26:14
问题 So I have a table with name ID , Time and Values . Values column has multiple same values. Time is of datetime2 datatype and is in ascending order of unique values. ID is also a primary key with int values. I want the result as continuous unique values of Values column in the same order as it appears in the original table. I have tried using window function Lead to find next values from a given value of Values column, but I am not sure how to find unique next values. Original table "TableTest

Excel VBA: Output Distinct Values and Subtotals

回眸只為那壹抹淺笑 提交于 2019-12-12 21:10:21
问题 I have data of this form: Category Source Amount Dues FTW $100 Donations ODP $20 Donations IOI $33 Dues MMK $124 There is no sort order. The categories are unknown at compile time. I want a VBA macro to cycle through the range, output a list of distinct values, with the subtotals for each. For the above data, it would look like this: Category Total Amount Dues $224 Donations $55 How can I do this? Also, is there a way to make the macro run every time the table above is updated, or is it

Counting distinct items in XSLT

我是研究僧i 提交于 2019-12-12 20:13:50
问题 I have XML like this: <assessment> <variables> <variable> <attributes> <variable_name value="FRED"/> </attributes> </variable> </variables> <variables> <variable> <attributes> <variable_name value="MORTIMER"/> </attributes> </variable> </variables> <variables> <variable> <attributes> <variable_name value="FRED"/> </attributes> </variable> </variables> </assessment> I know that with this XSLT: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method=

Unique Count Formula for large dataset

让人想犯罪 __ 提交于 2019-12-12 06:00:40
问题 I am having trouble determining a way to enter a 1 or 0 into an adjacent cell to indicate whether or not a value is unique when working with a large dataset. I have read of multiple methods for accomplishing this, however none of them seem efficient for my purposes: I am using an instance of Excel 2010 (so I do not have the Distinct Count feature in PivotTables, and when I try to use PowerPivot it crashes my file due to processing limitations. In this StackOverflow question: Simple Pivot