Current Topic: 1.3.1.4. Decision Making Model and Algorithms
You have a privilege to create a quiz (QnA) related to this subject and obtain creativity score...
Decision Making Model
There are several steps in the decision making process. We often skip one or more steps and pay the price later.
Framing the problem To frame the problem means to:
- Identify the problem
o This might require research and brainstorming.
o Do not hesitate asking questions.
o The most successful people are asking a lot of questions and have great listening skills
- Define the criteria, goals and priorities
o Different groups and individuals can see and prioritize differently
- Evaluate effect of the problem
o If the problem does not cause much troubles, maybe it does not make sense to spend time and efforts to overcome the problem
Making a decision - Find causes of the problem
- Frame alternative decisions
o It is a very important step
o A common mistake is to think of the first decision as the final destination
o Looking for alternatives brings more choices and allows you to select the best option
- Evaluate impact of alternatives and select the optimal based on criteria, goals and priorities
Evaluate the decision - Measure impacts of the decision
- Plan implementation and implement the decision
Let us apply this section material to programming most common algorithms, like finding maximum and minimum.
Let us frame the problem by providing a sample as a set of numbers:
1,2,3,7,5
Making decision in this case is actually finding an algorithm.
We can see that the MAX number is 7. How did we get to this solution.
Apparently by comparing the numbers.
We start from the first number and think of this number as a potential MAX number.
Then moving to the next number and comparing to that potential MAX number, we change the potential MAX to the bigger number.
Doing the same thing consistently (sounds like a for-loop) we achieve our goal.
The sample below finds maximum number in an array of numbers.
/**
* Find MAX in array
* int[] numbers = {1,2,3,7,5};
* @author Jeff.Zhuk@JavaSchool.com
*
*/
public class FindMaxSample {
public static void main(String[] args) {
// prepare for the loop
int[] numbers = {1,2,3,7,5};
// init the target
int max = numbers[0];
// arrange the loop
for(int i=0; i < numbers.length; i++) {
// work with the next element
if(numbers[i] > max) { // if the next element is more than current maximum
max = numbers[i]; // replace max
}
}
// print the results
System.out.println("MAX="+max);
}
}
Was it clear so far?
--------------------------------------------------------------------------------
In a similar way the sample below finds minimum number in an array of numbers.
/**
* Find MIN in array
* int[] numbers = {1,2,3,7,5};
* @author Jeff.Zhuk@JavaSchool.com
*
*/
public class FindMinSample {
public static void main(String[] args) {
// prepare for the loop
int[] numbers = {1,2,3,7,5};
// init the target
int min = numbers[0];
// arrange the loop
for(int i=0; i < numbers.length; i++) {
// work with the next element
if(numbers[i] < min) { // if the next element is less than current minimum
min = numbers[i]; // replace max
}
}
// print the results
System.out.println("MIN="+min);
}
}
Assignments: 1. Do a quick research of the subject on the Internet and write a short essay.
2. In Eclipse create a class named ArrayUtility and place two methods there:
public static int getMinimum(int[] arrayOfInts) and
public static int getMaximum(int[] arrayOfInts)
In the main() test these methods:
Declare an array of ints:
int[] arrayOfInts = {3,2,1,5,4};
int min = getMinimum(arrayOfInts);
int max = getMaximum(arrayOfInts);
and display the results
3. Add to this class another method:
public static int getAverage(int[] arrayOfInts)
and add to the main() the line to test the method
int average = getAverage(arrayOfInts);
4. Create two QnA related to a subject and email with the essay and the source of the class ArrayUtility to dean@ituniversity.us
<br/>/**
<br/> * Find MAX in array
<br/> * int[] numbers = {1,2,3,7,5};
<br/> * @author Jeff.Zhuk@JavaSchool.com
<br/> *
<br/> */
<br/>public class FindMaxSample {
<br/> public static void main(String[] args) {
<br/> // prepare for the loop
<br/> int[] numbers = {1,2,3,7,5};
<br/> // init the target
<br/> int max = numbers[0];
<br/> // arrange the loop
<br/> for(int i=0; i < numbers.length; i++) {
<br/> // work with the next element
<br/> if(numbers[i] > max) { // if the next element is more than current maximum
<br/> max = numbers[i]; // replace max
<br/> }
<br/> }
<br/> // print the results
<br/> System.out.println("MAX="+max);
<br/> }
<br/>}
<br/>
Was it clear so far?
onclick="window.location.href='/BASE/jsp/demo.jsp?checkFlavor=itsp&issueID=370&intro=general&group=aitu&ur=f'">
--------------------------------------------------------------------------------
In a similar way the sample below finds minimum number in an array of numbers.
<br/>/**
<br/> * Find MIN in array
<br/> * int[] numbers = {1,2,3,7,5};
<br/> * @author Jeff.Zhuk@JavaSchool.com
<br/> *
<br/> */
<br/>public class FindMinSample {
<br/> public static void main(String[] args) {
<br/> // prepare for the loop
<br/> int[] numbers = {1,2,3,7,5};
<br/> // init the target
<br/> int min = numbers[0];
<br/> // arrange the loop
<br/> for(int i=0; i < numbers.length; i++) {
<br/> // work with the next element
<br/> if(numbers[i] < min) { // if the next element is less than current minimum
<br/> min = numbers[i]; // replace max
<br/> }
<br/> }
<br/> // print the results
<br/> System.out.println("MIN="+min);
<br/> }
<br/>}
<br/>
Assignments: 1. Do a quick research of the subject on the Internet and write a short essay.
2. In Eclipse create a class named ArrayUtility and place two methods there:
public static int getMinimum(int[] arrayOfInts) and
public static int getMaximum(int[] arrayOfInts)
In the main() test these methods:
Declare an array of ints:
int[] arrayOfInts = {3,2,1,5,4};
int min = getMinimum(arrayOfInts);
int max = getMaximum(arrayOfInts);
and display the results
3. Add to this class another method:
public static int getAverage(int[] arrayOfInts)
and add to the main() the line to test the method
int average = getAverage(arrayOfInts);
4. Create two QnA related to a subject and email with the essay and the source of the class ArrayUtility to dean@ituniversity.us