Professional Documents
Culture Documents
H. L. Mencken
Algorithms
Any computable problem can be solved by executing a series of actions
in a specific order.
A procedure for solving a problem in terms of
is called an algorithm.
Algorithms
Correctly specifying the order in which the actions are to execute
is important—this is called program control.
Algorithms Complexity
Algorithmic complexity is a measure of how long an algorithm would
take to complete given an input of size n. If an algorithm has to scale, it
should compute the result within a finite and practical time bound even
for large values of n.
Algorithm Complexity
Complexity is calculated asymptotically as n approaches infinity.
While complexity is usually in terms of time, sometimes complexity is
also analyzed in terms of space.
The Imitation Game
Sorting
Searching
Too bored to search for a relevant image, imagine one…
Pseudocode
Pseudocode is an informal language that helps you develop algorithms.
The pseudocode
Pseudocode is similar to everyday English; it’s convenient user friendly,
although it’s not an actual computer programming language.
document.writeln( "Passed" );
else
document.writeln( "Failed" );
Conditional Operator (?:)
• JavaScript provides an operator, called the conditional operator (?:),
that is closely related to the if…else statement.
• The operator ?: is JavaScript’s only ternary operator— it takes three
operands.
Conditional Operator (?:)
• The operands together with the ?: form a conditional expression.
• The first operand is a boolean expression, the second is the value for
the conditional expression if the expression evaluates to true and the
third is the value for the conditional expression if the expression
evaluates to false.
Conditional Operator (?:)
document.writeln( studentGrade >= 60 ? "Passed" : "Failed" );
if…else Selection Statement
Nested if…else statements
Nested if…else statements test for multiple cases by placing if…else
statements inside if…else statements
Nested if…else statements
if ( studentGrade >= 90 )
document.writeln( "A" );
else
if ( studentGrade >= 80 )
document.writeln( "B" );
else
if ( studentGrade >= 70 )
document.writeln( "C" );
else
if ( studentGrade >= 60 )
document.writeln( "D" );
else
document.writeln( "F" );
Nested if…else statements
if ( grade >= 90 )
document.writeln( "A" );
else if ( grade >= 80 )
document.writeln( "B" );
else if ( grade >= 70 )
document.writeln( "C" );
else if ( grade >= 60 )
document.writeln( "D" );
else
document.writeln( "F" );
dangling-else problem
if ( x > 5 )
if ( y > 5 )
document.writeln( "x and y are > 5" );
else
document.writeln( "x is <= 5" );
https://www.onlinegdb.com/