Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
11 views

Why do you think we don’t use dummy nodes for the buckets? [on hold]

When writing an iterator for hash tables with chaining, many people find it awkward to implement remove since we didn’t have dummy nodes. Why do you think we don’t use dummy nodes for the buckets?
0
votes
1answer
25 views

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

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 ...
0
votes
0answers
5 views

How to create a 2D Linked List similar to a 2D array? Each node having a right and down pointer [on hold]

I want to use java.util.LinkedList<> but couldn't find a way to make the nodes have a right and down pointer. Implementing the 2D linked list from scratch is okay but i want to know how to use the ...
0
votes
0answers
18 views

Superclasses, subclasses, and constructors [on hold]

I'm looking for some assistance with setting up this program. Is anyone able to assist? Create a superclass precipitation that takes in the parameter temperature. It should have the method toString()*...
0
votes
0answers
20 views

Write a static method called split [on hold]

Write a static method called split that takes an array of integers as a parameter and that returns a new array double the size of the original array, where every element in the original array is ...
-5
votes
0answers
35 views

Test if code contains sequence in Array (IM DESPERATE PLEEEEAAASE!!) [closed]

Directions: Write a code that determines whether A, B, and C appear consecutively and in order exactly once in the numbers array and return the result. Example: Suppose A is 1, B is 2, C is 6 Sample ...
1
vote
1answer
42 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
58 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
42 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
15 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 ...
1
vote
2answers
434 views

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

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
25 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
24 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
27 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
208 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
0answers
30 views

Length of longest increasing sequence of not necessarily adjacent elements

Input: Up to 50 numbers between -50 to 50 delimited by space. Output: Length of longest increasing sequence of elements. The subsequence of elements doesn't have to be continuous, in other words they ...
0
votes
1answer
192 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
26 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 ...
0
votes
0answers
18 views

How do I write a regular expression of my own defined language?

I have been working on the designing lexical analyzer.I made two classes for tokenization and lexical analyzer (Tokenization.java ...
0
votes
0answers
125 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
129 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
108 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
94 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" ...
-3
votes
4answers
119 views

what is the complexity of this program? [duplicate]

// assume 'n' is given. What is the time complexity of this code ? ...
1
vote
0answers
115 views

Is the Java 8 Grammar still a LALR(1) grammar?

As I found out here: http://www.eclipse.org/jdt/core/howto/generate%20parser/generateParser.html , the Java Version of 2005 (might be Java 6, I'm not sure) is a LALR(1) grammar. However, I couldn't ...
6
votes
1answer
335 views

What fragment of Martin-Löf dependent type theory can be expressed using generic types in Java?

I have recently come to realize that a number of problems I had a few years ago trying to implement various mathematical theories in Java came down to the fact that the typing system in Java is not ...
-1
votes
1answer
790 views
0
votes
0answers
17 views

Without sound synthesis, what is a good way of making a program that plays guitar notes from an array of stored sounds?

Without sound synthesis, what is a good way of making a program that plays guitar notes from an array of stored sounds? What I have in mind is to make note as a function of vibration speed such as N (...
0
votes
1answer
165 views

What is the O time complexity for this algorithm?

is the Big-O for this O(1) or some asymptotic like 1/n? Saying that because if it defaults, the time limits at about 1000000 ns, but if it returns while in the loop, it is about a fraction of that. ...
0
votes
1answer
157 views

How to calculate the average of x numbers? [closed]

I just started a college course and I'm being asked for a flowchart where I explain how to calculate the average of x quantity of numbers. For this assignment I'm asked to follow the problem solving ...
5
votes
2answers
338 views

Version of knap sack problem

The are cuisenaire rods with N differnt lengthes $x_1,x_2,...,x_n$ (each length is a natural number), the number of the Cuisenaire rods is unlimited. Given a natural number B. you should tell if you ...
-1
votes
1answer
64 views

Can local variables be instance variables? [closed]

I know that variables can be categorized in two ways:- The first way is to classify them into global and local variables based on their scope. When the variable is accessible by all the functions of ...
1
vote
2answers
4k views

Find out duplicate number between 1 to N numbers

I first saw this question on this website where I was trying on Java puzzles. Here is the Question:- ...
0
votes
1answer
554 views

Which is the best data structure for searching under these conditions

I have a system with some factors, say A, B, C, and D. There can be different values of all these factors. Let us consider few values to have a better understanding. Let's say A has 4 different ...
2
votes
2answers
350 views

Binary Search Tree Traversals

I have a clue as to how this code/traversals work but I'm still confused. For example, in the first traversal (Preorder), it prints 31, 12, 25 but then it backtracks all the way to 68? How does it ...
1
vote
1answer
35 views

Is there a general pattern/structure/format to most (if not all) computer functions?

First time posting. I know this is a very generalized question, sorry for that, I don't know how to more appropriately word this. I've noticed a tread, a pattern in methods, it seems in almost all ...
0
votes
1answer
48 views

Inheritance problem (JAVA) [closed]

Here I have created 2 classes , $A$ is the super class of $B$ , i.e , $B$ inherits the features of class $A$. Now I don't know exactly what statement (1) does but I am speculating as follows ,kindly ...
0
votes
0answers
247 views

Normal Distribution pattern in Java Array of doubles

Given ordered array of float numbers, Check if array represents Normal Distribution. I wrote algo to find triangular distribution as follows: ...
7
votes
0answers
181 views

Are type constructors always injectives even in presence of quantified type variables (subtyping)?

Are type constructors, in a language that feature subtyping and quantification of type variables, like scala or Java, always injective? That is, is an equivalent of haskell ...
2
votes
1answer
2k views

improving java 8's implement to hash map using avl tree

Java 8 got a new implement to hashmap (using a tree). I have understand that in the worst case, it may be O(n) for lookup. Will changing this implement to an avl tree change this O(n) case to ...
-1
votes
1answer
48 views

Why does this statement evaluate to 176? [closed]

int y = 10; int z; z = (++y * (y++ + 5)); // Evaluates to 176 According to me this should evaluate to 180. Please provide an explanation as well which relates to ...
2
votes
0answers
77 views

Byte Code/IL Code execution [closed]

I understand that Byte/ IL Codes are interpreted/executed by their corresponding run times. Do those run time converts the Byte/IL codes directly to machine code which processor can execute or the ...
0
votes
1answer
773 views

How to write an EBNF grammar for Java float literals?

I've got this question on my study guide: "Write an EBNF grammar description for Java float literals and one for Java double literals." I've browsed the Oracle site and found the grammar for java ...
-1
votes
1answer
38 views

Methods in Java with/without return? Simple but new to coding [closed]

I want to make this program below but I'm not sure how i would start them. Would i use methods with or without return? I have this due tomorrow and cannot figure it out. I've wrote the code multiple ...
1
vote
0answers
25 views

Implementing TCP request and answer [closed]

I'm creating an application where client connects to server, retrieves some data and after that connection is closed. He spends some time changing that data and then connects again to the server ...
-1
votes
1answer
206 views

What do you mean by minimum height of a Binary Search Tree? [duplicate]

I came across the term "minimum height of a Binary Search Tree" (in Java) in class, but I don't fully understand. Could someone please elaborate on: (a) What it is ? (b) How to determine/...
-1
votes
1answer
51 views

Is it possible to make excluded search with for loop in Java? [closed]

I am trying to calculate all pure strategy Nash equilibrium in a mxn game. It requires to check all pure strategy pairs (m.n pairs). Suppose player 1 has m strategies. Algorithm should start with the ...
-1
votes
2answers
138 views

Analysing Algorithms Big Oh/Complexity theory [duplicate]

I'm revising for my finals and from looking at previous exam papers I have a found a popular question that has came up almost every year, worth a lot of marks. Each year the question is written very ...
1
vote
2answers
456 views

Break and Continue in Structured Programming?

One of the ways to ensure following the structured programming paradigm is by having all control flows having only one entry and one exit point. Does skipping iterations by using break and continue in ...
0
votes
2answers
264 views

How to learn computer science the right way [closed]

I looked through the sites and this seems to be the best place to ask this question. I am sure it has been asked 10000 times but I am looking for a tailored answer to me and my situation. I currently ...