Merge Sort Data - Time Complexity

Mar 16, 2014

Suppose i have written a method like this

public void myWork(){
mergeSortMyData(); O(nlgn)
....
someProcessing(); O(n^2)
someprocessing2(); O(n^2)
}

then what will be time complexity of my code...according to me it will be O(nlgn + n^2) ...is it correct ?

View Replies


ADVERTISEMENT

Notation Time Complexity

Aug 12, 2014

So recently I began Data Structures as core subject and the tutorials in this forum are great.

Right now, I seem to have trouble with Big Oh Notation algorithm and what is the mathematical side to it. "f(n) <= c.g(n), for n>=0.

The question I am working on is: Suppose we are maintaining a collection C of elements such that, each time we add a new element to the collection, we copy the contents of C into a new array list of just the right size. What is the running time of adding n elements to an initially empty collection C in this case?

View Replies View Related

Time Complexity (theta) For Loops With Special Case?

Sep 9, 2014

I can't able to find the theta for some type of code like.

for(i=1;i<=n;i++){
for(j=i;j>=1;j=j/3){
....
}
}

How to find the theta for the above code.

for(i=1;i<=n;i++){
for(j=i;j>=1;j=j/K){
....
}
}

and How to find number of steps or time complexity for inner loop if k=3 (odd)

View Replies View Related

Most Efficient Algorithm - Concerning Time Complexity For Searching In A Linked List?

Feb 13, 2015

with arrays its binary search which finds a value in O(Logn) time but what about linked lists ? the most effiecient algorithm will be O(n) ? and i know that binary search cannot be implement on a linked list , therefore , the only way to search a linked list is a linear search ?

View Replies View Related

Merge Sort With Random Numbers

Mar 2, 2015

How do i make this merge sort take on random numbers in an array instead of hard coding the numbers

Integer [] a = {8, 2, 6, 7, 5, 4, 3, 1};
mergeSort(a);
System.out.println(Arrays.toString(a));
}
public static void mergeSort (Comparable [] a){

[code]....

View Replies View Related

Java Merge Sort Not Working

Dec 10, 2014

I have been working on getting the merge sort working, I have a complteted code but am not getting the right results... Here is my code and the results are "876323149" ...

public class MergeSort
{
private static int[] local; // for use in copying
private static int[] a;
public static void main(String[] args) {
int[] test = {2,3,1,4,7,8,6,3,9};

[Code] ....

View Replies View Related

Implementing Merge Sort On Given Array

Jun 15, 2014

Merge sort implementation on the given array i listed in the code below. I know Arrays.sort() or Collections.sort() could do the trick but i want to achieve it through merge sort.

import java.util.*;
public class Merge{
public static void main(String[] args){
String[] myStringArray=new String[]{"z","a","z","b","c","e","z","f"
,"g","a","w","d","m" ,"x","a","R"
,"q","r","y","w","j","a","v","z","b"};
}
}

View Replies View Related

Doing Merge Sort - Incompatible Type

Apr 10, 2014

I am new in java.. I am having a problem when doing merge sort. This is my coding...

Java Code:

import java.util.*;
public class Person
{
public static void main(String[] args)
{
String[] list = {"

[Code] ....

the error is incompatible type at 'sorted = merge(left,right);'

View Replies View Related

Merge Sort Java And Linked List?

Dec 11, 2014

I've playing around with linked lists and methods for sorting. So far I've tested the iterative sort, insertion sort, quick sort and they all worked perfectly. Now, I am trying to implement merge sort that would take a linked list of jobs and sort them according to their priority. I found a few solutions on the web, of which I am trying to implemented this one: LeetCode.

My system is a simple one, I do have a linked list of print jobs, each of which has the priority. The following code should sort my print queue and return the link node of the first sorted element. Here's the code.

//defining a job that has priority
public class Job {
private int priority;

[Code]....

The problem I've been trying to solve is that I am getting the stack overflow at line

ListNode<T> h1 = mergeSort(left);

meaning that I am getting into a loop somewhere down through the process of breaking the linked list into half, half or halfs and so on.

View Replies View Related

Creating Merge Sort For String Arrays

Mar 31, 2014

I'm having a problem printing out the descending order of my array. The array order goes like (Title,Studio,Year). I try to create to ints with the compareTo method but when the program is run the I get array out of bounds. Could the answer possibly be that in order not not have the out of bounds error, to create a for loop inside of the while?

public class Movie2
{
// instance variables
private int year;
private String Title;
private String Studio;

[code]...

View Replies View Related

Writing A Recursive Merge Sort Algorithm

Mar 27, 2015

I have this assignment to write a Merge Sort algorithm using recursion. To start I have a very tough time picturing what is happening when it comes to recursion, but I do understand how merge sorting works. At the moment I feel as though a very good portion of my code is correct, but I am having trouble with the recursion in the main method [ mergeSort(Queue<T> queue) ].

I have another 4 or so hours to pass in my assignment finished or not, and at this point I can honestly say I have no clue how to make my code work. I tried working through the problem on paper with a simple queue of size 3, but even that is a struggle. On paper my code works perfectly fine, so there is definitely something I am missing.

Below is what I have along with my JUnit test.

Java Code:

private Queue<T> output = new Queue<T>();
private Queue<T> output1 = new Queue<T>();
private Queue<T> output2 = new Queue<T>();
public Queue<T> mergeSort(Queue<T> queue) {
// TODO 1
if(queue.size() <= 1) {
return queue;

[Code] .....

View Replies View Related

Program Can Accept Multiple Filter And Sort Commands At One Time

Mar 9, 2014

What I'm supposed to be doing is making it so the program can accept multiple filter and sort commands at one time, and each should be separated by a whitespace.I was thinking about parsing the input again, using whitespace as the delimiter, then normally progressing with each token, as though there was only one command.

However, coding this the way I'm doing it will firstly probably take hours, and secondly, it's likely not even right. I don't have any real way to determine which token contains which data from the Song objects.These are the specific requirements for this portion:A sort/filter command consists of one or more of the following options:

-year:<year(s)>

-rank:<rank(s)>

-artist:<artist>

-title:<title>

-sortBy:<field>

Any number of these options may be given, and they may be given in any order. If multiple options are specified, they will be separated by whitespace.

GazillionSongs Class (the main)
Java Code:
import java.util.*;
import java.io.*;

[code]....

View Replies View Related

JSF :: Sort Data Table Using JQuery 1.7

Mar 3, 2015

I'm using JSF1.2 and IBM websphere portal 7 (Core) not prime or rich faces. I would like to know to sort the JSF data table(<h:datatable /> using Jquery 1.7

View Replies View Related

Servlets :: Using HTML Form To Sort Data

May 12, 2014

I have a very simple HTML form with a textField for a name, and add button to add the name to a MySQL database, and a sort button to sort the names in the database and display them. I almost have it working, however when I hit the "sort" button; I get the message that appears after a user clicks the add button along with the sorted list of names. It looks like this:

Please go back and add a name or sort.
Bill Jones
David G
Debbie Downer
Jane Doe
Joe Smith
John Doe
Mike Jones
Paul Smith
Susan Jones

What I have to change on my code to make just the list show up by itself when the user clicks sort?

My servlet code:

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;

[Code] .....

View Replies View Related

Guess Picture Game - How To Sort Picture Random Every Time

May 3, 2014

I will write guess the picture game. I didn't find for example 4*4 picture how to sort picture random everytime ?

For example , when game start random various are 2734856127348561 two times same picture...

View Replies View Related

Swing/AWT/SWT :: Sort JTable Data On Year Between A Range Of Years?

Jan 16, 2014

i have a JTable with data that contains a column with Years.

I want to get the user to be able to sort the data between a range of two years.

Example:

a user sets te filter so he/she can view all the data between the years 1990 and 2000.

I am a beginner in Java and don't know how to code such a filter.

I guess it will be something with an if/Else statement or a loop?

View Replies View Related

Reading From File And Sort Data Based On Person GPA - Catching Error

Dec 9, 2014

I am catching an error in my driver class that reads from a file and sorts the data based on a person's GPA. Here is my code:

import java.io.*;
import java.util.*;
public class Driver {
public static void main(String[] args) {
new Driver(args[0]);

[Code] ....

Why throwing this exception?

View Replies View Related

Computational Complexity (Big O Notation)

Nov 5, 2014

I've been trying to learn more about Big O Notation and I've gotten stuck on a few pieces of code. What is the computational complexity for the following pieces of code?

1:

for(int i = n; i > 0; i /= 2) {
for(int j = 1; j < n; j *= 2) {
for(int k = 0; k < n; k += 2) {
// constant number of operations

[Code] .....

5 : Determine the average processing time of the recursive algorithm. (int n) spends one time unit to return a random integer value uniformly distributed in the range [0,n] whereas all other instructions spend a negligibly small time(e.g., T(0) = 0)

int myTest(int n) {
if(n <= 0) return 0;
else {
int i = random(n - 1);
return myTest(i) + myTest(n - 1 - i);

6 : Assume array a contains n values, the method randomValue takes a constant number c of computational steps to produce each output value, and that the method goodSort takes n log n computational steps to sort the array.

for(i = 0; i < n; i++) {
for(j = 0; j < n; j++)
a[j] = randomValue(i);
goodSort(a);
}

View Replies View Related

Run Time Error In Reading Data From Keyboard

Aug 9, 2014

i tried to run simple program od adding two number by using scanner class but there is run time error here it is code file and error.

View Replies View Related

How To Calculate Remove Method Complexity

Feb 1, 2015

I need to figure out how to calculate the remove method complexity in the worst best and average case same as the insert method

public void insert(String Word)
{
size++;
int pos = myhash(Word);
WordNode nptr = new WordNode(Word,null);
if (table[pos] == null)
table[pos] = nptr;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Replacing Old With New Data When Submit Button Clicked For Second Time

Mar 11, 2014

I have created a gui which accepts username in the text field and once clicking on submit button it fetches user details and throws it on gui via JTable.

But when i click submit for the second time using different username the background process goes well and good the vector that i pass to jtable changes with new data but the values in gui still contain the old data.

View Replies View Related

Compile Time Error - Cannot Invoke Read On Primitive Data Type Int

Jul 10, 2014

I have a code in which I am reading input from System.in and Destination is some where else

Here is my code

File file=new File("D:/output.txt");
OutputStream os=new java.io.FileOutputStream(file);
Scanner scanner=new Scanner(System.in);
System.out.println("Enter Data to write on File");
String text=scanner.nextLine();
int c=Integer.parseInt(text);
int a;
while((a=c.read())!=-1)
os.write(a);
System.out.println("File Written is Successful");

In the line while((a=c.read())!=-1)

a compile time error is shown "cannot invoke read on primitive data type int"

Where I am going wrong?

View Replies View Related

Sort Linked List Through The Nodes Of List - Data Of Calling Object

Feb 14, 2014

I have some class called sorted to sort the linked list through the nodes of the list. and other class to test this ability, i made object of the sort class called "list1" and insert the values to the linked list.

If i make other object called "list2" and want to merge those two lists by using method merge in sort class. And wrote code of

list1.merge(list2);

How can the merge method in sort class know the values of list1 that called it as this object is created in other class.

View Replies View Related

Merge 2 CSV Files Containing Some Values

Feb 4, 2014

Have 2 files File1.csv and file2.csv containing some values. Have to read both files and write unique values in to another file.

In the new the there must be unique rows and not duplicate rows (2 files contain some rows same). What is the best approach for doing this?

View Replies View Related

JSF :: Using Merge Method To Update DB Record

Apr 25, 2014

So I have two related tables - Country (Master) Projects (Detail). Country has a OneToMany relationship with Projects. I put a link on my AllProjects.xhtml page. When tyhe link is clicked it uses a data model class to to display the current (clicked) project record (projectRecord object). After editing all the details, the UPDATE button calls a merge method in the DAO class. On the first attempt to update, nothing happens and the record is returned as it is with no errors. If I try updating again, I get:

Error Code: 1062
Call: INSERT INTO projects_beta2b_projects_beta2b (projects_PROJECTID) VALUES (?)
bind => [1 parameter bound]
Query: DataModifyQuery(name="projects" sql="INSERT INTO projects_beta2b_projects_beta2b (projects_PROJECTID) VALUES (?)")

[Code] .....

My classes are:

projects.java

@Entity
@Table(name = "projects_beta2b")
public class Projects implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int projectid;
private String projectName;
private String client;

[Code] ...

Is the 'new' keyword in the entity class causing the Inser statement in the DAO because the JPA thinks I want to create a new object therefore invokes INSERT instead of UPDATE?

View Replies View Related

How To Merge Cell In DefaultTableModel / JTable

Feb 18, 2014

I searched a lot and got some answers for this Q. but many of them referred to links which give 404 error. I want to make table like this:

Can I make this in Java?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved