Questions tagged [computer-science]

Computer science (CS) is the science behind programming. Use for questions related to the more theoretical questions involving programming. Questions of a purely theoretical nature may be off-topic. All CS questions can be asked on https://cs.stackexchange.com/

Computer science (also called computing science, and often abbreviated CS) is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems. Computer scientists invent algorithmic processes that create, describe, and transform information and formulate suitable abstractions to model complex systems.

As a discipline, computer science spans a range of topics from theoretical studies of algorithms and the limits of computation to the practical issues of implementing computing systems in hardware and software.

While some computer science questions are on-topic for Stack Overflow, many of the more theoretical questions or questions that do not apply to programming are off-topic. You can ask these types of questions on the Computer Science Stack Exchange.

4449 questions
1
vote
1 answer

How to find the number of operations in a nested loop with dependent variable?

I am having difficulty trying to find the total number of operations in the following code block: for(int i = 1; i <= n; i *= 2) { for(int j = 1; j <= i; j *= 2) { // What is the number of operations here, with respect to n? } } My…
great_20r
  • 25
  • 5
1
vote
0 answers

prove the greedy algorithm for Gas Station is valid

I'm trying to prove the solution for the problem Gas Station (LeetCode 134) Let's define d_i to be the difference g_i - c_i. Basically it's a greedy solution where you look for the first k s.t. \sum_{i=k}^n d_i >= 0 Let's denote the following: A =…
Elimination
  • 2,619
  • 4
  • 22
  • 38
1
vote
1 answer

Is Number.MAX_SAFE_INTEGER has value of (2^53 - 1) in 32-bit computer

The MDN Web Docs refers that the Number.MAX_SAFE_INTEGER constant represents the maximum safe integer in JavaScript which has value of 2^53 - 1. my question: is Number.MAX_SAFE_INTEGER has also value of (2^53 - 1) in 32-bit computer? and if yes it…
Amjed Omar
  • 853
  • 2
  • 14
  • 30
1
vote
2 answers

What do some of these lines of code mean in python (Matrix Addition)?

I'm trying to understand what some Python keywords and functions do by reviewing this code that takes in matrices and adds the numbers within the said matrices, but I'm having some troubles understanding what some of these lines of code mean. An…
0329
  • 13
  • 3
1
vote
1 answer

How can a never-ending recursive function have a time complexity?

In the book "Introduction to Algorithms" by CLRS we are asked to find the time complexity of a recursive function: 4.4-8 Use a recursion tree to give an asymptotically tight solution to the recurrence T(n) = T(n - a) + T(a) + cn where a ≥ 1 and c >…
Viktor Skarve
  • 129
  • 1
  • 8
1
vote
0 answers

How to perform Arithmetic on Ones Complement Numbers and correct overflow?

For some backstory, I'm making a program that can do arithmetic on ones complement numbers. To do this I'm converting a binary string into a BigInteger and then performing the math using said BigIntegers, and then converting that back into a binary…
1
vote
1 answer

longest common subsequence in 3 strings in this way LCS(LCS(string ,string),string)

suppose we want to find LCS for 3 strings. Does finding the LCS (LCS(string,x, string y), string z) give the right solution?
someMan
  • 13
  • 2
1
vote
1 answer

A question about performing the next step in Boruvka's Algorithm

I have a question about implementing Boruvka's algorithm for Minimum-Spanning-Trees. Assume we have the following graph: It is fairly simple and clear to me how to find the smallest connection/edge of each node/vertex. My question is about how you…
1
vote
2 answers

itertools.groupby() values disappear

I have a nested list [['A','B'],['A','C'],['D'],['C','A']] import itertools d = {} for key, group in itertools.groupby([['A','B'],['A','C'],['D'],['C','A']], lambda x: x[0]): d[key] = list(group) print(d) Now I will have {'A': [['A', 'B'],…
Troy Bear
  • 55
  • 5
1
vote
3 answers

O(v + e) Time Complexity Breadth First Search

I've looked at other answers on here, but everything is either is messily written, or the code doesn't operate the same as mine does. All I am looking for is a crystal clear explanation as to why the time complexity of this breadth first search…
Dan Zuzevich
  • 3,651
  • 3
  • 26
  • 39
1
vote
0 answers

Can a graph with negative edges exist, for which Dijkstra's algorithm will work properly?

I know,that "normal" Dijkstra's algorithm won't work for graph with negative edge's since once it visits the edge and processes it,it's weight will not be revised.However,I have hard time proving this formally.I don't even know where to start.
Tabris
  • 37
  • 1
  • 5
1
vote
1 answer

Can a method return different data types depending on the action?

I want to create a method that can return different data types depending on the action. I, unfortunately, cannot include the real code snippet but with the below one hopefully, you can have an understanding. Basically, I call this method many types…
chicka
  • 61
  • 1
  • 5
1
vote
1 answer

What's the term for a value that is not a function?

Or does the term "value" already exclude functions? I'm trying to explain why (in JavaScript, for instance) calling foo(2 + 2) is different from calling foo(() => 2 + 2), (assuming foo can handle a function as argument for the purpose of lazily…
Ty Mick
  • 75
  • 1
  • 7
1
vote
2 answers

Algorithm to throw an element across screen

I have an application where I want a user to be able to throw/flick an object across the screen. Essentially they would drag the element across the screen quickly and let go, then it would keep moving in the direction they dragged it in at the same…
Rich
  • 21
  • 1
1
vote
1 answer

Why does sp point to start of RAM on 6502 assembler?

I'm using the ca65 assembler (https://cc65.github.io/doc/ca65) to run my project. I know 6502 has SP register points to low byte of stack position ($01SP). But I don't know how actually (sp) works in code. In ca65's runtime it has func to push A…
Andy
  • 21
  • 3
1 2 3
99
100