What four parts commonly make up an iterative algorithm?
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.
Study Java Iteration and Algorithmic Patterns with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What four parts commonly make up an iterative algorithm?
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.
Why can a while loop execute zero times?
A while loop tests its Boolean condition before each possible body execution, so a false condition initially causes zero iterations.
What is the execution order of a basic for loop?
A for loop initializes once, tests its condition, executes the body, performs its update, and then repeats the test.
What guarantees one execution of a do-while loop?
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.
What is total after the loop adds x from 1 through 4?
The final value is 10. The loop adds 1, 2, 3, and 4 to total, then stops when x becomes 5.
How should a sentinel be handled in a sentinel-controlled loop?
A sentinel is a special value that ends processing. Test it before processing so it is not accidentally included in the calculation.
How do i < 5 and i <= 5 differ when i starts at 0?
The loop with i < 5 processes 0 through 4, for five iterations. Changing the condition to i <= 5 includes 5, making six iterations.
Why is while (x < 5) infinite when only y is decremented?
It is infinite because x controls the condition but never changes inside the loop; therefore x < 5 remains true.
How should a maximum search be initialized?
Initialize maximum with the first array element, then compare the remaining elements. Starting at 0 fails when every element is negative.
What does the digit-reversal loop produce from 472?
The algorithm extracts 2, then 7, then 4 from 472 and appends each digit to reversed, producing 274.
How many times does a 3-by-4 nested loop execute its inner statement?
The printing statement executes 12 times: the outer loop runs 3 times and the inner loop runs 4 times for each outer iteration.
How many times does the inner loop run in the four-row triangular pattern?
The inner loop runs 1 + 2 + 3 + 4 = 10 times because its bound depends on the current row.
A progressive guide to how computing reshapes culture, economic life, public institutions, and individual opportunities, with frameworks for evaluating digital equity, bias, cybersecurity, encryption, and collective participation.
A medium-difficulty assessment of programming fundamentals, algorithmic problem solving, control flow, data structures, testing, debugging, complexity, and decidability. Questions progress from foundational understanding to applied reasoning.
A 14-question quiz on the social, economic, privacy, informational, health, and environmental risks of computing innovations, including strategies for responsible design and oversight.
A practical guide to recognizing cybersecurity threats, protecting accounts and devices, and responding safely when information or systems may be compromised.
A guided introduction to how encryption, authentication, hashing, secure protocols, and key management establish confidentiality, integrity, privacy, and trust while creating practical and legal trade-offs.
A focused review of propositional logic, quantifiers, sets, relations, functions, and foundational proof methods in discrete mathematics for computer science.
A practical guide to evaluating computing innovations by examining their benefits, risks, equity, security, participation, and long-term effects on people and communities.
A medium-difficulty quiz on integrating problem definition, representation, algorithms, complexity analysis, testing, correctness, ethical evaluation, and documentation in a computer science capstone.
A progressive guide to designing, operating, and testing systems that continue useful service despite component faults, overload, data loss, and recovery challenges.
A medium-difficulty quiz on how independently operated networks, protocols, addresses, naming systems, transport services, and routing mechanisms work together to form the Internet.
A progressive guide to how packet-switched networks encapsulate data, move it across links, and manage delay, throughput, queues, and congestion.
A structured guide to designing parallel and distributed systems through decomposition, communication, coordination, state management, scalability, and fault tolerance.