FAQ Database Discussion Community


R Constained Combination generation

r,algorithm,computer-science
Say I have an set of string: x=c("a1","b2","c3","d4") If I have a set of rules that must be met: if "a1" and "b2" are together in group, then "c3" cannot be in that group. if "d4" and "a1" are together in a group, then "b2" cannot be in that group....

Doesn't fragmentation in FAT file system lead to space wastage?

memory-management,operating-system,computer-science,fragmentation,fat
The wikipedia for article for fragmentation states: In many cases, fragmentation leads to storage space being "wasted", and in that case the term also refers to the wasted space itself. For other systems (e.g. the FAT file system) the space used to store given data (e.g. files) is the same...

How can we prove that the running time bound of an algorithm is tight?

algorithm,big-o,computer-science,big-theta
Suppose we can prove that an algorithm, invoked with an input of size n, runs in time O(f(n)). I want to prove that this running time bound is tight. Two questions: Wouldn't it suffice to give a special input and show that the running time is at least f(n)? I've...

sliding window algorithm implementation [closed]

algorithm,networking,data,computer-science
I am having trouble figuring how to derive the numbers to the solution to the question. I am following the steps, however my numbers do not come near that of the solution. Can someone give a concise step by step way to figuring out both problems. Solution ...

Need workaround to treat float values as tuples when updating “list” of float values

python-2.7,matplotlib,computer-science,floating-point-conversion
I am finding errors with the last line of the for loop where I am trying to update the curve value to a list containing the curve value iterations. I get errors like "can only concatenate tuple (not "float) to tuple" and "tuple object has no attribute 'append'". Does anyone...

What are the basic steps from a hardware circuit to a transitionssystem

logic,computer-science,transitions,boolean-logic
What are the basic steps when I want to get a hardware circuit into a transitionssystem? I don't get the arrows between the nodes. The arrows from/to the same node are simple. But How do I get the arrows between node {r} and node {x,r,y} for example? and what can...

Computer architecture - How to find the addresses in a block

computer-science,computer-architecture
A cache memory with 4 KiB, each block is 16 words, there are 64 lines in the cache. Tag = 18 Index = 6 Block offset = 4 Byte Offset = 2 I want to know for block number 448 what is the first address in the block and what...

Why is `nil` discussed as boolean by treehouse?

ruby,boolean,computer-science
Why is nil considered a boolean or represented as a boolean value in the boolean tutorial for ruby? By definition, a boolean in computer science is a: data type, having two values (usually denoted true and false), intended to represent the truth values of logic and Boolean algebra. ...

does Ω(n^5) + o(n^2) + O(logn) = Ω(n^5) [closed]

algorithm,computer-science
Hi I have been given this problem, and I have no idea where to start. So any advice what be great. How to you go about this kind of problem? All the information I was given is: State whether the following statement is true or false, justify your answer? Ω(n^5)...

Keeping Score in python code

computer-science,python-3.4
What do I have to do in order to have a score board for my code because I need a score board. I tried a while statement but got lost there. Can you help me? So lost. import random def main_menu(): option = input("Play the game (P) , View the...

How many stack memories will be allocated to a program

c++,visual-c++,dll,operating-system,computer-science
I have a program which have 4 projects as dependency for that (that means it has to load 4 dlls to run that program) .Does the OS allocates 4 stack memories or only 1 stack memory will be allocated for whole program and how much stack memory size will be...

Big-O Computational Resources

algorithm,sorting,big-o,computer-science,asymptotic-complexity
I know that measuring asymptotic complexity can be based on any resources you have, whether it's time, memory usage, number of comparisons, etc. But when it comes to sorting something, I realize we normally associate the asymptotic notation with the basic operations like number of swaps/steps or number of comparisons....

In a forward search algorithm, what happens if both items are equal? [duplicate]

algorithm,network-programming,computer-science,dijkstra
This question already has an answer here: Dijkstra's algorithm: What to do if there are two or more nodes with minimal weight? 1 answer In a forward search algorithm, what do you do if both items are equal? The forward search algorithm stems off of Dijkstra algorithm Forward Search...

How do people create new programming languages?

c,programming-languages,computer-science,systems-programming,inventions
I'm novice programmer, learning C. Something that's always confused me is how do people create new programming languages? Sub/related questions: What language do they write it in? Does the language have to be one that in between a high level language and machine code? What are the stages/elements of creating...

find element in linked list

algorithm,linked-list,computer-science
There is a data structure providing iterators with the following interface: struct iterator { T value(); void next(); bool isValid(); } How would you design an algorithm which at the end of the loop returns some value from the list with equal probability for each element? The list can be...

Solving a complex recurrence relation for the Traveling Salesman

algorithm,math,time-complexity,computer-science,recurrence-relation
I need to solve the exact time complexity for the brute force version of the Traveling Salesman using a recurrence relation. I've worked out the recurrence relation to be as follows: T(n)=T(n-1)*(n-1)+1 But I'm having trouble reducing that that to a closed form of the function, and thus get the...

Continuation in a mainstream-ish programming language [closed]

programming-languages,computer-science
I need a mainstream language that supports continuations. Java never will (breaks finally), Scala has deprecated it, ruby is silently deprecating it as well... Does any other mainstream, non FP-only language support them and does not plan to deprecate it? I actually need the ability to jump back in the...

Recursion base case fails

python,debugging,recursion,computer-science
I'm looking for an error in the last line of the code, but I can't figure out what it is. Any ideas? def letterScore( let ): let.lower() if let in 'aAnNoOeErRsStTuUiIlL': return 1 elif let in 'dDgG': return 2 elif let in 'bBcCpPmM': return 3 elif let in 'fFhHvVwWyY': return...

Would this function be O(n^2log_2(n))?

big-o,computer-science
So I am given a function like 65536 n2 + 128 n log2n and the only way that this would be O(n2 log2n) is if C = 65664, n0 = 2 for all n ≥ 2 since C1 = 65536 n1 = 2 when 65536 ≤ C1*n2 and C2 =...

Java: 2d array - making it “torus” like

java,computer-science
I am facing following problem: I have a board of size MxN squares. What is the best way to make it in java so that when there are coordinates given which are out of bounds (or with negative values), it will return square from the other side of the board?...

How to properly pass array pointers to function in C

c,pointers,computer-science,user-defined-functions
A different question may have been asked about this program, however in this C code I have three functions: one to print records, one to add a record and one to delete a record. What I don't understand is why the (add) and (delete) do not make changes in the...

How do I output a bubble sorted 2-D string array in C?

c,arrays,computer-science,bubble-sort,c-strings
How do I go about sorting a 2-D string array in C using bubble sort (or any other kind of sorting in that matter) ? What I'm actlly trying to do is as follows : Example: Unsorted 2-D string array : abfg abcd xyzw pqrs orde Sorted 2-D string array:...

Determine all consecutive subsets of the set {1,2,3,…,n}. The subsets should have at least 2 elements

algorithm,computer-science,combinatorics,set-theory
I need to partition a set S={1, 2, 3, … , n} consisting of consecutive numbers such that each subset has has at least 2 elements (rule 1) and it consists of consecutive numbers (rule 2). The rules are: Each subset has at least two elements. All elements of all...

coding help for physical drum machines

encoding,computer-science
Me and some people are making and selling some physical drum machines, where if you press a button on a board, a related sound is played. Now I'm familiar with Microsoft Small basic and visual and html, however I'm not sure on programming the physical button to play an mp3...

Can Fibonacci Heap have more than one nodes with equal rank(or value, or key)?

algorithm,heap,computer-science,fibonacci-heap
I am studying Fibonacci heap alone, and I came across a question. I know any nodes can be inserted into Fibonacci heap, but what if the rank(or value, or key) of that new node is equal to the sibling node? 1) For example, (1) <-minimum root / \ (3) (5)...

Binary Search vs. Linear Search (data structures & algorithms)

algorithm,data-structures,computer-science,binary-search,linear-search
Trying to wrap my head around some basic and common algorithms.. my current understanding of the question is in bold. ( 1 ) Assuming we have a sorted array with n items: at most how many times will a binary search compare elements? I keep seeing ' 0(log(n)) ' pop...

Refactoring logic inside if statement to bare minimum

javascript,math,logic,computer-science,permutation
Sometime ago I wrote an educational JavaScript application with SVG (closed-source for a company). At its most basic form the application consisted of two columns (left and right), and each column contained various geometric shapes (squares, triangles, circles, etc.) Each geometric shape in one column could connect (by drawing a...

Anyone understand external files well?

java,while-loop,external,computer-science
I am supposed to create a program that reads an external file with 3 integers on every line and find the area of a triangle with those three numbers. We haven't learned arrays yet though, so i want to create the program without an array, methods and classes are fine....

Constructing inputs with a given runtime for Insertion Sort

algorithm,computer-science,insertion-sort
Does anyone know of any good ways to go about doing this? It's easy to find families of inputs {I_i} where InsertionSort(I_i) \in \Theta(n) or \Theta(n^{2} What about for values of k where 1 < k < 2? Is it possible to find an input I so that InsertionSort(I) \in...

Using float / double as a loop variable

c++,computer-science
Running on a x64 architecture , Visual Studio 2013 Windows 8.1 I am trying to run a loop which uses a float as its loop variable , the issue is during the increment operation the decimal values are being lost . Eg : float incrementValue = 360 / 14; for...

What is the term used to describe a complete call frame cycle thing in JavaScript?

javascript,computer-science
In JavaScript, there is the concept of the execution pathway beginning at a certain point (such as an event handler), with the control being relinquished back to the browser at some point. Is there a proper name for this process? Originally I thought you could refer to this as the...

Compute the “lower contour” of a set of segments in the plane in `O(n log n)`

c++,algorithm,big-o,computer-science
Suppose you've a set s of horizontal line segments in the plane described by a starting point p, an end point q and a y-value. We can assume that all values of p and qare pairwise distinct and no two segments overlap. I want to compute the "lower contour" of...

first and last terms of a nested loop, sums of arithmetic series starting with non zero index

algorithm,math,big-o,computer-science,integer-arithmetic
I have 2 arithmetic series... (i) for i<- 1 to n do for j<- 1 to 2n-i do //a unit cost operation So the first term is 2n-1, last term is 2n-n = n (ii) for i <- 1 to n do for j <- 2 to (n+i) do //...

Gaps between successive floating point numbers

numbers,computer-science,representation
(all numbers discussed are in decimal) lets say we have a floating point data type that is like : m * 10 ^ e where m is the mantissa . and max mantissa size is 1 ( 0 <= m <= 9); e is the exponent and its size is...

Keyboard events java

java,computer-science,keylistener,keyevent
I have recently started learning java.I want to make a game like https://sites.google.com/site/millseagles/home/Games/multiplayer/tron I have made it in c++ once using a simple graphics lib. I have the graphics part down i plan to use small images and use http://horstmann.com/sjsu/graphics/ this basic graphics lib.I can't figure out keyboard input i...

Summarize different category rankings

algorithm,math,statistics,computer-science
I determine the rankings of i.e. 1000 participants in multiple categories. The results are something like that: Participant/Category/Place (lower is better): A|1|1. A|2|1. A|3|1. A|4|7. B|1|2. B|2|2. B|3|2. B|4|4. [...] Now I want to summarize the rankings. The standard method would be to sum up all places and divide it...

Brick-Breaker in C - incrementing rows of bricks issue

c,function,for-loop,computer-science
I'm trying to re-create brickbreaker using C and the Stanford Portable Library (SPL). The goal of my initBricks function is to add 5 ROWS of bricks with 10 COLUMNS in each row (50 bricks total). When I run this code my window only has 1 ROW of 10 bricks. For...

Find the tightest upper bound for a creation of an array (among few options)

arrays,algorithm,data-structures,time-complexity,computer-science
Let A, an array of numbers. We need to create an array B such that B[i] = min(A[i],...,A[i+sqrt(n)]. Why is the tightest upper bound for the creation of B is O(nlogn)? I was actually given a list of options: O(sqrt(n)*logn) O(n/logn) O(n*logn) O(nlog(n)^2) O(n*sqrt(n)) O(n^2) ...