Questions tagged [java]

Programming questions are off-topic here. Do not ask questions about how to write code in Java. However, conceptual questions about computer science are more appropriate. See our help center for the scope of this site.

Filter by
Sorted by
Tagged with
-1
votes
0answers
15 views

Recurrence equation [duplicate]

What is the recurrence equation of this function and how to calculate it ...
0
votes
0answers
6 views

Blueprint for class and objects in Java

Good morning everybody. I would like to know if there is a blueprint I could refer to when creating classes and objects in Java? For instance, I was told for classes. You start VARIABLES DECLARATIONS ...
-1
votes
1answer
34 views

Java programming object terminology

Say there is a class called Person. Then in the following expression : Person human = new Person() Which is the "reference&...
1
vote
1answer
49 views

What is loop invariant for this loop?

As far as i understand all loops have a loop invariants. My understanding is that loop invariant is an argument that is true at the beginning of the loop block as well as at the end of the loop. For ...
0
votes
0answers
11 views

How to remove filaments from a planar graph?

I have a planar graph and I'm trying to implement this algorithm (https://geometrictools.com/Documentation/MinimalCycleBasis.pdf Chapter 4, page 3). For the filament F0(V4, V3, V2), that has one ...
0
votes
1answer
40 views

How to draw the heap for an array in Java?

I have an assignment to draw the heap after an ArrayList and a LinkedList is created. ...
0
votes
1answer
41 views

How to calculate the runtime of a following code?

Could someone explain how to calculate the Big O notation for a runtime of a snippet of a code? ...
0
votes
0answers
15 views

Interval scheduling problem implementation

I am learning the Interval scheduling problem, and I came up after some reading with an implementation. I'll list my steps and the code, please let me know if this is correct or there is a more ...
0
votes
2answers
111 views

Intelligent use of XOR operator to find missing number

I've come across the following problem on leetcode & tried to solve it with the following code however there seems to be an even better solution that takes advantage of XOR. Leetcode has a ...
0
votes
1answer
41 views

Elements of Programming Interviews - 16.4 Generate Power Set - solution 1 time complexity question

hope you all are doing well. I have a question about the time complexity of solution 1 for question 16.4 - Generate Power Set from the book Elements of Programming Interviews by Adnan and Tsung-Hsien....
1
vote
2answers
33 views

Can Yacc be used to generate three address code for Java 1?

I have read that yacc generates bottom up parser for LALR(1) grammars. I have a grammar for Java 1 that can be used for generating three address code and is strictly LALR(1), but the translation ...
0
votes
0answers
21 views

How to get synonyms from definitions using Bayes algorithm

I work on a project: an online dictionary where the user can find definitions of a word he's looking for. My supervisor asked us to add synonyms using machine learning. He recommend us to use Bayes ...
0
votes
0answers
26 views

Please explain the algorithm for finding bridges in graph?

let, low[] and disc[] be two 1D arrays disc[i] stores the discovery time of node[I] low[i] stores the lowest value between disc[i] and discovery time of children of node[i] I'm curious that what is ...
0
votes
2answers
57 views

Numerical Approximation in Java

I am trying to solve an equation which I believe cannot be done analytically, but can use a numerical approximation to get a result. The equation is: $$\frac{2*\sqrt{\pi}*h*s*e^{m^{2}/(2*s^2)}}{\sqrt{...
1
vote
1answer
53 views

Difficulty in understanding this summations to analyze time complexity

I wanna know if what this link https://stackabuse.com/shell-sort-in-java/'s calculation of the complexity of shell sort is true. Here's the shell sort algorithm: ...
1
vote
0answers
444 views

Time Complexity of Subset Problem

The Subset Exercise taken from LeetCode: ...
1
vote
0answers
669 views

How to visualize complex algorithm, like Split Array Largest Sum

I am trying to do the leetcode question I got the answer and trying to understand a systematical way to come up with the answer using the DP bottom-up approach, and I am having a hard time to ...
2
votes
2answers
44 views

Minimum words in a string given a dictionary

The question is: Given a dictionary consisting of a set of words and a string: find the minimum number of words the string can be split into. If the string can not be decomposed into a list of words ...
0
votes
1answer
42 views

Creating sum of all numbers within a sequence [duplicate]

Write an algorithm that, given sequence seq of n numbers where 3 <= n <= 1000 and each number k in seq 1 <= k <= 200, finds maximum sum by repeatedly removing one number from seq, except ...
0
votes
2answers
57 views

Why does a RNN network output different based on the training sequence

I've set up an RNN LSTM network in Java using DL4J as the library. I currently have 500 examples of positive text, and 500 examples of negative text. When I fitness the training data by first ...
0
votes
0answers
105 views

Converting Turing machine into the source code in industrial programming language?

Are there methods how to convert Turing machine (e.g. neural Turing machine or other rigorous Turing machine) into the source code/program that is written in some industrial programming language like ...
2
votes
1answer
62 views

In what sense if any does java have multiple dispatch?

I'm trying to get my head around the difference between message passing (with which we are all familiar as by far the most common form of object orientation today) vs generic functions as implemented ...
3
votes
1answer
61 views

Sum of unique integers to cnf constraint

As a study project I try to solve the kakuro puzzle problem using SAT SOLVER. I can't really find an efficient way to convert the sum of k unique integers (1...9) to a CNF constraint. What I had in ...
0
votes
1answer
55 views

What is a constructor in java? [closed]

I have checked many websites but did not get the right answer. what is the meaning of constructor in java?
4
votes
1answer
148 views

Linked list: advantages of preventing movement of nodes and invalidating iterators on add/remove

C++ and Java include native classes for linked lists, C++ std::list and Java LinkedList For C++ std::list, nodes can be "moved" within a list, or from list to list (if the lists are compatible), via ...
1
vote
0answers
45 views

What is the difference between self-rewriting program and program-with-updates-and-restart

I am reading about Goedel machine http://people.idsia.ch/~juergen/goedelmachine.html and especially the article about possible implementation (in the Scheme language) of this machine http://people....
0
votes
0answers
101 views

Given n strings, how to output their order after k phases of the radix sort (huge constraints)?

Disclaimer This is not from an ongoing contest, this is from my course of ITMO on edx.org, which is a paid code so I cannot give you a direct link to the course. Problem You are given $\...
-1
votes
1answer
412 views

Is there any way to find the nodes in the each subtree of each node having distance equal to height of the subtree?

We are given a tree of N nodes from 1 to N where node 1 is the root of the tree. For each node i from 1 to N, you have to find the numbers of nodes which are in the subtree of i and are at distance ...
0
votes
1answer
30 views

Count of (x,y) pairs that satisfy the equation x^2+y^2 = n^2

Given (n) , what is the Count of (x,y) pairs that satisfy the equation x^2+y^2 = n^2. Is there any way I can re-write this code just without using nested loop? ...
1
vote
0answers
28 views

Java configuration for int-amqp [closed]

I am trying to convert a XML based configuration to JAVA based configuration. Can someone please let me know the java annotation based configuration for the following ...
2
votes
1answer
136 views

Find path from node

I have a question where I need to find a path from node 1 to node N in an undirected graph given weights in O(A Log^2 A). The total cost of each path must not ...
-1
votes
1answer
32 views

How does the instanceof operator work in the context of downcasting in java? [closed]

I am trying to understand the purpose of using the instanceof operator as a way to properly downcast an object in java. I really hope someone can help. Below is more code: ...
1
vote
0answers
35 views
1
vote
3answers
53 views

Write a routine to print the numbers 1 to 6 and back to 1 again without using any loops [closed]

Can anyone help with this question? I currently have this solution that prints 1 2 3 4 5 6 but I'm having trouble going back down to 1. ...
0
votes
1answer
55 views

Why whenever a caller or client modifies a library collection class, all iterators are made invalid? [closed]

Whenever a caller or client modifies a library collection class, all iterators are made invalid (with the exception of the iterator through which the change was made, in the case of remove). Give a ...
3
votes
1answer
845 views

algorithm to find all values that occur more than n/10 times

I took an algorhytm course on coursera and there some optional questions for student enrichment. I can't solve the following task: Decimal dominants. Given an array with n keys, design an algorithm ...
0
votes
1answer
309 views

Which Data Structure should I use to store words from a novel?

So, I was learning Data Structures in Java on my own. And there was a "challenge question" in the book. The question basically asked me to make a data structure that could store all the words in a ...
-3
votes
1answer
45 views

Please help, I have been attempting to understand Quicksort for 9 hours now with little luck!

I have done absolutely everything that i could to try to understand this algorithm. I did NOT want to go on without understanding it completely even though I know it might only be a single problem in ...
1
vote
0answers
26 views

Nested Function stuck on iteration update

I want to solve the Sparse Extended Information Filter Slam described by Dr. Sebestian Thrun in Probabilistic Robotics.I stuck in some nested function. The algorithm is described in page 309 in this ...
2
votes
2answers
28k views

How is the formula for calculation in row/column major obtained?

In my book, this formula is given for calculation of address of row major order's element $[I,J]$: Address of $[I,J]$th element in row major order $= B + W[n(I-L_r)+ [J-L_c]]$ where B denotes base ...
-4
votes
1answer
187 views

Construct an array from a binary tree

I am looking for a suggestion. I know it is possible to construct a binary tree from an array. I want to know that vice verse is true? Is it possible to construct an array from a binary tree? If yes ...
0
votes
1answer
56 views

Linked List fundamental concepts [closed]

I am trying to understand the basics of Linked List. The definition of my LinkedList class is as follows: ...
-1
votes
1answer
50 views

Beginner question in Java [closed]

I am just starting to study Java and was wondering why the following code if(x>2) x*=2; if(x>4)x=0; System.out.println(x); returns 0 for any value of x greater than 2. For example, when x=3, why ...
-1
votes
1answer
657 views

Knapsack progblem with two conditions

I want to create an algorighm (with dynamic programing) similar to 1/0 knapsack problem but, I have one extra condition isVegetable or isFruit. Assume we have N food items where we know ...
0
votes
1answer
561 views

What is the time complexity of this Factorization program?

input: n-bit integer X output: list of prime factors and their multiplicity acc = X ...
1
vote
1answer
34 views

Algorithm to select sets of objects while maximizing number of objects covered

If we have different objects, [A1, A2, A3, B1, B2, B3, B4, B5] Some calculations will be performed to find compatible objects. For example, lets assume following ...
1
vote
0answers
415 views

I'm looking for best algorithms to compare two Circular Linked List?

I'm looking for best algorithms to compare two Circular Linked List? For example : List 1 = 1-3-5 List 2 = 3-5-1 I want to compare "same" or "not same" but need fast algorithm.
7
votes
2answers
173 views

Formal model of execution for Java (or general imperative language)

I'm trying to prove some statements about execution in Java programs under some heavy restrictions (basically I have a conjecture that if two methods satisfy a set of constraints for a given input ...
2
votes
0answers
159 views

Novel escape analysis algorithm for Java

Today I read a very interesting article about escape analysis in Java called Escape Analysis for Object Oriented Languages: Application to Java I think I have some grasp on how escape analysis works ...
1
vote
2answers
109 views

How do compilers implement symbolic (rather than textual) insertion?

From a programming language designer's point of view, how is "symbolic" insertion implemented as opposed to "textual" insertion using pre-processor macros? I understand the basics of how "textual" ...