The Artima Developer Community
Sponsored Link

Java Answers Forum
urgent help needed

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
nasser

Posts: 1
Nickname: lonely
Registered: Oct, 2003

urgent help needed Posted: Oct 25, 2003 2:20 PM
Reply to this message Reply
Advertisement
may you please help me in solving any one of these three questions?
the three are related to Data Structures and Algorithms
with object-oriented design patterns in java


Q1)Devise a scheme using a stack to convert an infix expression to a postfix expression.Hint: in a postfix expression operators appear after their operands, whereas in an infix expression they appear between their operands.Process the symbols in the prefix one by one.Output operands immediately, but save the operators in a stack until they are needed.Pay special attention to the precedence of the poerators.The program must
catch appropriate exceptions and display informative error messages when the input is in error.


Q2. Write the following recursive methods to be as general as possible.
(a) Write a recursive method
public int countGreaterThan(int n)
that returns the number of integers in a given one-D array that are greater than the
integer n. Use this method to write another recursive method
public int countGreaterThan2D(int n)
that returns the number integers in a two-dimensional array that are greater than the
integer n.
(b) Write a complete program to test your method using the following array:
int twoD[][]={{-11,-10,-9},{-8,-7,-6,-5,-4,-3,-2},{-1,0},{1,2,3,4,5,6,7},
{8,9,10,1 1},{}};
Your program should behave as exemplified below:
Please enter an integer: -1
There are 12 numbers greater than -1 in the array.


Q3. Study the following methods carefully. Determine the big-O running time of
the method, myMethod() by forming and solving recurrence relations.
class Hw3Q3{
int helperArray[];
// ... assume space has been allocated for this array as needed
public static void myMethod(int array[], int i, int n){
if(n>1){
myMethod(array, i, n/2);
myMethod(array, i + n/2, n-n/2);
helperMethod(array, i, n/2, n-n/2);
}
public static void helperMethod(int []a, int left, int mid, int right){
int i = left;
int j = left;
int k = mid + 1;
while(j<=mid && k<=right){
if(array[j]<array[k])
helperArray[i++]=array[j++];
else
helper Array[i++]=array[k++];
}
while(j<=mid)
helperArray[i++]=array[j++];
for(i=lef t; i<k; ++i)
array=helperArray;
}
}
}

Topic: Reading Text Files from JAR Previous Topic   Next Topic Topic: guessingamehelp

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use