Review day1 Flashcards
(23 cards)
Pseudocode
A way to plan a program’s logic before writing actual code.
if statement
IF condition THEN
sequence 1
ELSE
sequence 2
ENDIF
while loop
WHILE condition
sequence
ENDWHILE
for loop
FOR iteration bounds
sequence
ENDFOR
Pseudocode Example 1:
Find the Maximum Number
START
SET max to first element of the list
FOR each element in the list
IF the element is greater than max
SET max to the element
END IF
END FOR
RETURN max
END
Pseudocode Example 2:
Find the sum
START
SET sum to 0
FOR each number in the list
ADD number to sum
END FOR
RETURN sum
END
Computational thinking Principles
Decomposition, pattern recognition, abstraction and algorithmic thinking.
Decomposition
Breaking down complex problems into smaller parts.
Pattern Recognition
Identifying similarities and differences between problems and solutions, and using this knowledge to generalize solutions.
Abstraction
Focusing on the important details and ignoring irrelevant information, creating a simplified model of the problem.
Algorithms
Developing a step-by-step set of instructions to solve the problem .
Analyzing code
Examine the code to identify issues such as bugs. Fix the problem, then test it again
Nature of programming languages (Java)
Java is a high-level, object-oriented, class-based, general-purpose, and platform-independent programming language
Object-Oriented
Java is built around the concept of objects, which encapsulate both data and behavior. This promotes code reusability, modularity, and maintainability.
Class-Based
Java uses classes as blueprints for creating objects.
General-Purpose
Java can be used to develop a wide variety of applications, from simple scripts to complex enterprise systems.
Platform-Independent
Java code can run on any platform that supports the Java Virtual Machine (JVM).
Recursion
A function calls itself
Three main parts of Recursion
1.Base case
2. Recursive case
3. A change of state that moves the function closer to the base case
Base case
This is the condition that stops the recursion
Recursive Case
The function calls itself with a slightly modified version of the input
Change of State
This ensures that each recursive call brings the function closer to the base case.
Recursion Example 1:
Calculate the sum from 1 to n
public static int sum(int n)
{
if (n == 1)
{
return 1;
}
return n + sum(n - 1);
}