DATA
STRUCTURES
AND ALGORITHM
Prepared by: Maxil S. Urocay MSCS ongoing
“Prayer to the Holy Spirit by St. Augustine”
Breathe in me, O Holy Spirit,
That my thoughts may all be holy.
Act in me, O Holy Spirit,
That my work, too may be holy.
Draw my heart, O Holy Spirit.
That I love but what is holy.
Strengthen me, O Holy Spirit,
Prepared by: Maxil S. Urocay MSCS ongoing
EXPECTED
TOPIC TO
LEARN
WITHIN THE SEMESTER
Prepared by: Maxil S. Urocay MSCS ongoing
• Java Programming Basics
• Data Structures and Algorithm Basics
• Arrays
• Stacks
• Queues
• Recursion and Backtracking
• Hashing and Hash Tables
• Trees
• Graphs
Prepared by: Maxil S. Urocay MSCS ongoing
• Sorting
• Searching
• Heaps
• Divide and Conquer Algorithm
• Greedy Algorithm
• Dynamic Programming
Prepared by: Maxil S. Urocay MSCS ongoing
PRELIMINARY
CHALLENGE!
Prepared by: Maxil S. Urocay MSCS ongoing
ACTIVITY:
Open your pc and create a Java program that will enable
users to add employee information(name and Id
number) and show/display all of the added employee
details. The user can choose an option from a menu to
either add employee, display employee and exit.
**No cellphone allowed during the activity
**only java IDE will be utilized during activity
**once cheating or utilizing any browser will
automatically gain no score and will be marked as
absent.
**Do it in 30 minutes.
Prepared by: Maxil S. Urocay MSCS ongoing
JAVA
PROGRAMMING
BASICS REVIEW
Prepared by: Maxil S. Urocay MSCS ongoing
What is Java?
- is a popular high level, class-based object oriented
programming language that is designed to be platform-
independent.
- originally developed by Sun Microsystems and is
released in 1995.
- currently owned by Oracle and more than three
billion devices run by Java.
- some aspects of Java are Platform independence,
object-oriented, syntax, automatic memory
management, multithreading, rich standard library, and
security.
Prepared by: Maxil S. Urocay MSCS ongoing
*Platform Independence – java code is compiled into
bytecode which executed on any platform with a
compatible Java Virtual Machine (JVM) | “write once, run
everywhere.
*Object-Oriented – built around the principle of OOP
which uses objects and classes to organize code.
*Syntax – is similar to C++, which makes it easier for
developers to learn and has more simplified aspects of
C++ to avoid common errors.
*Automatic Memory Management – includes a garbage
collector that automatically manages memory allocation
and deallocation, which helps to prevent memory leaks.
Prepared by: Maxil S. Urocay MSCS ongoing
*Multithreading – allows developers to write program
that can perform multiple tasks simultaneously, which
can improve performance and responsiveness.
*Rich Standard Library – comes with comprehensive set
of standard libraries that provide functionality for data
structures, networking, file handling and more.
*Security – has built-in security features like Java
sandbox and bytecode verification that helps to protect
against malicious code.
Prepared by: Maxil S. Urocay MSCS ongoing
public class Universe{
public static void main (String[] args){
System.out.println(“Hello World!”;
}
}
Explain the functions of the code.
Prepared by: Maxil S. Urocay MSCS ongoing
This says
all code in a This method
anyone can run The name of the
java program does not return
this class
must belong to anything
program/metho
a class
d
The name of the
This method method
belongs the
public class Universe{
class, not an public static void main (String[] args){
Arguments on
object System.out.println(“Hello World!”); the command
} line as an array
} of strings
Open and The method for Indicating the
printing strings The string we
closing the end of the
on the screen want to print
class/method statement
Prepared by: Maxil S. Urocay MSCS ongoing
Identify and Explain the difference between the following
// and /* */?
Comments – which are annotations provided for human
readers that are not processed by the Java compiler.
// - inline comment, limited to one line.
/* */ - multiline comments, in the form of block
comments.
Prepared by: Maxil S. Urocay MSCS ongoing
Data Types
-are classifications that specify which type of value a
variable can hold.
-each data types determines what kind of operations
can be performed on the data, how much memory is
allocated, and how the data is represented.
-are divided into two groups (Primitive data types
and Non-primitive data types).
Prepared by: Maxil S. Urocay MSCS ongoing
Data Types
Primitive data types – these are basic types provided by
a programming languages which usually represent single
values and have a fixed size.
-It includes the Boolean, character, byte, short,
integer, long, float and double.
Non-primitive data types – also known as reference
types which are more complex and represent collections
of values or more structures.
-it includes the arrays, string, classes, objects, lists,
queues, stacks, graph, trees and more.
Prepared by: Maxil S. Urocay MSCS ongoing
What is Object and classes in Java?
Class – blueprint or template for creating objects, it is a
set of objects which shares common characteristics or
behavior and common properties or attributes.
Objects – is an instance of a class , which serves as the
type of the object and as blueprint, defining the data
which the object stores and the methods for accessing
and modifying that data.
Prepared by: Maxil S. Urocay MSCS ongoing
Instance variables – which are also called fields,
represents the data associated with an object of a class.
It is usually have a type (base type like int, float, double
and more) (reference type which are the data structures
topic)
Methods – are blocks of code that can be called to
perform actions and can accept parameters as
arguments and their behavior may depend on the object
upon which they are invoked and the values of any
parameter that are passed.
Prepared by: Maxil S. Urocay MSCS ongoing
Modifiers– can be placed to convey additional
stipulations and are the keywords that you use to define
the characteristic of classes, methods, variables and
other elements in your code. Types includes access
modifiers, static modifiers, abstract modifiers and final
modifiers.
Access modifiers – they control the level of access and
also known as visibility that the defining class grants to
other classes in the context of a larger program. Public
(accessible from any other class) Protected (accessible
within the same package and by subclasses) default (no
modifier which is accessible only within the same
Prepared by: Maxil S. Urocay MSCS ongoing
Static modifier– can be declared for any variable or
method of a class and indicates that a member belongs
to the class rather than to any instance of the class.
Abstract modifier – are and advanced feature of object-
oriented programming to be combined with inheritance.
Uses to declare abstract classes and methods.
Final modifier – can be initialized as part of that
declaration, but can never again be assigned a new
value. Used to declare constants, prevent method
overriding, and inheritance of classes.
Prepared by: Maxil S. Urocay MSCS ongoing
Java Operators
Arithmetic Operator – used to perform common
mathematical operations like Addition (+),
Subtraction(-), Multiplication(*), Division(/), Modulus(%),
Increment(++) and Decrement(--).
Relational Operator - a symbol used in computer
programming to compare two values and determine if a
specific relationship between them is true or false like
equal to(==), not equal to(!=), greater than(>), less
than(<), greater than or equal to(>=), and less than or
equal to(<=).
Prepared by: Maxil S. Urocay MSCS ongoing
Java Operators
Bitwise Operator – characters that represents actions to
be performed on single bits like Bitwise AND (&), Bitwise
OR (|), Bitwise XOR (^), Bitwise NOT (~), Left shift(<<),
Right shift (>>) and Unsigned right shift(>>>).
Logical Operator – a symbol or word used to
connect/combine two or more Boolean expression like
Logical AND (&&), Logical OR(||), and Logical NOT (!).
Prepared by: Maxil S. Urocay MSCS ongoing
Java Operators
Assignment Operator – store a value in the object
specified by the left operand or used to assign values to
variables like assignment (=), addition assignment (+=),
subtraction assignment (-=), multiplication assignment
(*=), division assignment (/=) and modulus assignment
(%=).
Miscellaneous Operator – are unique kinds of operators
like ternary, member access, comma, array index, new,
instanceof, and typecast.
Prepared by: Maxil S. Urocay MSCS ongoing
Control flow
- is the order function calls, instructions, and
statement are executed or evaluated when a program is
running.
IF STATEMENTS (conditional statement)
- to specify a block of Java code to be executed if a
condition is true.
if (condition) {
// Code to execute if condition is true
} Prepared by: Maxil S. Urocay MSCS ongoing
Control flow
IF ELSE STATEMENT (conditional statement)
- executes one block of code if a condition is true, and
another block if the condition is false.
if (condition) {
// Code to execute if condition is true
} else {
// Code to execute if condition is false
}
Prepared by: Maxil S. Urocay MSCS ongoing
Control flow
ELSE IF STATEMENT (conditional statement)
- specify a new condition if the first condition is false.
if (condition1) {
// Code to execute if condition1 is true
} else if (condition2) {
// Code to execute if condition2 is true
} else {
// Code to execute if none of the conditions are true
}
Prepared by: Maxil S. Urocay MSCS ongoing
Control flow
SWITCH STATEMENT (conditional statement)
- allows you to choose from multiple options based on
the value of an expression.
switch (expression) {
case value1:
// Code to execute if expression equals value1
break;
case value2:
// Code to execute if expression equals value2
break;
default:
// Code to execute if expression doesn't match any case
} Prepared by: Maxil S. Urocay MSCS ongoing
Control flow
FOR LOOP (Looping statement)
- repeats a block of code a specified number of times.
for (initialization; condition; update) {
// Code to execute in each iteration
}
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
Prepared by: Maxil S. Urocay MSCS ongoing
Control flow
WHILE LOOP (looping statement)
- repeats block of code as long as a specified condition is
true.
while (condition) {
// Code to execute while condition is true
}
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}
Prepared by: Maxil S. Urocay MSCS ongoing
Control flow
DO-WHILE LOOP (looping statement)
- repeats a block of code at least once and continues to
repeat it as long as a specified condition is true.
do {
// Code to execute
} while (condition);
int i = 0;
do {
System.out.println(i);
i++;
} while (i < 5);
Prepared by: Maxil S. Urocay MSCS ongoing
Control flow
BREAK STATEMENT (jump statement)
- exits the current loop .
while (true) {
if (condition) {
break;
}
}
Prepared by: Maxil S. Urocay MSCS ongoing
Control flow
CONTINUE STATEMENT (jump statement)
- skips the current iteration of a loop and proceeds with
the next iteration.
for (int i = 0; i < 5; i++) {
if (i == 2) {
continue;
}
System.out.println(i);
}
Prepared by: Maxil S. Urocay MSCS ongoing
Control flow
RETURN STATEMENT (jump statement)
- exits from the current method and optionally returns a
value.
int sum(int a, int b) {
return a + b;
}
Prepared by: Maxil S. Urocay MSCS ongoing
THANK YOU
PRODUCT
OFFERS
Prepared by: Maxil S. Urocay MSCS ongoing