You are on page 1of 5

QUEZON CITY UNIVERSITY

COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY

AL101 – ALGORITHMS AND COMPLEXITY


ACTIVITY WEEK#11

NAME: Vida, John Paul S.


STUDENT NO: 20-2167
YEAR/SECTION: 3rd Year /SBIT-3L
DATE: March 31, 2023

INSTANCE SIMPLIFICATION

Instance simplification refers to reducing complexity in code by simplifying object instances. Here's an example
of how you might do this using a simple class named Car.

PSEUDOCODE :

Define the Car class


a. Declare private attributes: make, model, and year
b. Define a constructor for the Car class that accepts the make, model, and year as parameters and initializes
the corresponding attributes
1. c. Override the toString() method to return a formatted string with make, model, and year
Define the Main class with the main method
a. Create a new Car object, car1, with the make "Toyota", model "Corolla", and year 2020
b. Create another Car object, car2, with the make "Honda", model "Civic", and year 2021
c. Print the details of car1 using the toString() method
2. d. Print the details of car2 using the toString() method

SCREENSHOT :
QUEZON CITY UNIVERSITY
COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY

FLOWCHART :

REPRESENTATION CHANGE :

This program demonstrates representation change using the Integer class's methods: toBinaryString,
toOctalString, and toHexString. These methods convert the given integer to its binary, octal, and hexadecimal
representations, respectively.

PSEUDOCODE :

1. Initialize a variable 'number' with an integer value


2. Convert 'number' to its binary representation and store it in a variable 'binaryRepresentation'
3. Convert 'number' to its octal representation and store it in a variable 'octalRepresentation'
4. Convert 'number' to its hexadecimal representation and store it in a variable 'hexadecimalRepresentation'
5. Print the original number and its binary, octal, and hexadecimal representations
QUEZON CITY UNIVERSITY
COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY

SCREENSHOT :

FLOWCHART :
QUEZON CITY UNIVERSITY
COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY

PROBLEM REDUCTION :

Problem reduction refers to breaking down a complex problem into simpler, smaller subproblems that can be
solved individually. This approach is often used in artificial intelligence, and it can be applied to various types
of problems. Here is a simple example of problem reduction in Java, using the "Tower of Hanoi" problem:

In this example, the Tower of Hanoi problem is solved using problem reduction. The problem is reduced to
solving the same problem with one less disk, and the base case is when there's only one disk to move. The
function towerOfHanoi is called recursively, breaking the problem down into smaller subproblems, and then
combining the solutions to form the overall solution.

PSEUDOCODE :

FUNCTION towerOfHanoi(n, fromPeg, toPeg, auxPeg)


IF n == 1 THEN
PRINT "Move disk 1 from peg " + fromPeg + " to peg " + toPeg
RETURN
END IF

CALL towerOfHanoi(n-1, fromPeg, auxPeg, toPeg)

PRINT "Move disk " + n + " from peg " + fromPeg + " to peg " + toPeg

CALL towerOfHanoi(n-1, auxPeg, toPeg, fromPeg)


END FUNCTION

MAIN
SET numberOfDisks = 4
CALL towerOfHanoi(numberOfDisks, 'A', 'C', 'B')
END MAIN
QUEZON CITY UNIVERSITY
COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY

SCREENSHOT :

FLOWCHART :

You might also like