Free Online Flashcard Deck

Java Iteration and Algorithmic Patterns Free Online FlashCards

Study Java Iteration and Algorithmic Patterns with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What four parts commonly make up an iterative algorithm?

Back

Initialization sets starting values, the condition decides whether to continue, the body performs each iteration’s work, and the update moves the loop toward termination.

02
Front

Why can a while loop execute zero times?

Back

A while loop tests its Boolean condition before each possible body execution, so a false condition initially causes zero iterations.

03
Front

What is the execution order of a basic for loop?

Back

A for loop initializes once, tests its condition, executes the body, performs its update, and then repeats the test.

04
Front

What guarantees one execution of a do-while loop?

Back

A do-while loop is a posttest loop: it runs the body first and checks the condition afterward, so the body executes at least once.

05
Front

What is total after the loop adds x from 1 through 4?

Back

The final value is 10. The loop adds 1, 2, 3, and 4 to total, then stops when x becomes 5.

06
Front

How should a sentinel be handled in a sentinel-controlled loop?

Back

A sentinel is a special value that ends processing. Test it before processing so it is not accidentally included in the calculation.

07
Front

How do i < 5 and i <= 5 differ when i starts at 0?

Back

The loop with i < 5 processes 0 through 4, for five iterations. Changing the condition to i <= 5 includes 5, making six iterations.

08
Front

Why is while (x < 5) infinite when only y is decremented?

Back

It is infinite because x controls the condition but never changes inside the loop; therefore x < 5 remains true.

09
Front

How should a maximum search be initialized?

Back

Initialize maximum with the first array element, then compare the remaining elements. Starting at 0 fails when every element is negative.

10
Front

What does the digit-reversal loop produce from 472?

Back

The algorithm extracts 2, then 7, then 4 from 472 and appends each digit to reversed, producing 274.

11
Front

How many times does a 3-by-4 nested loop execute its inner statement?

Back

The printing statement executes 12 times: the outer loop runs 3 times and the inner loop runs 4 times for each outer iteration.

12
Front

How many times does the inner loop run in the four-row triangular pattern?

Back

The inner loop runs 1 + 2 + 3 + 4 = 10 times because its bound depends on the current row.