0% found this document useful (0 votes)
16 views

CS Notes

Computers can only solve problems that are explicitly defined through a series of unambiguous instructions. There are various stages to solving a problem, including identification, development, selection, and implementation. Programming involves breaking down a problem into a series of steps through algorithms, which must define input, output, and have a finite number of steps.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

CS Notes

Computers can only solve problems that are explicitly defined through a series of unambiguous instructions. There are various stages to solving a problem, including identification, development, selection, and implementation. Programming involves breaking down a problem into a series of steps through algorithms, which must define input, output, and have a finite number of steps.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

- Computers can only solve problems that are solvable by humans

- Problem-solving steps - Identification, Development, Selection, and Implementation

- Identification: Identify and understand the problem

- Development:Explore other alternatives

- Selection : Choose the best alternative

- Implementation : Implement the selected solution

- Programming : includes the creation of a series of steps that will solve a problem or
problems/ Is a process of solving a problem in phases.
-
- Definitions:
- Runtime: the amount of time it takes for a program or operation
- Compilation :
- Execution : the act of running a program or code, causing the computer to perform the
specified tasks.
- Computers can only solve problems solvable by humans except ai obv
- The client doesn’t know what they want a lot of the time cuz they misdiagnose the
problem
- Decomposition :
- Data presentation :
- Generalization :
- Algorithms : series of unambiguous instructions designed to solve a problem and achieve
a certain goal in a finite number of steps

Stages of Solving a Problem:

1. Identification
● explicitly pinpoint where the problem is
● Describe the problem
1. Development
● Make plans B and C etc
1. Selection
2. Implementation
● Executing solution
Programming: series of steps to solve a problem; a sequence of instructions that explain to a
computer how to solve a problem
-

Computational Thinking: A problem with more than one solution.

Algorithm - Must posses Finiteness, Definiteness,Effectiveness, Input, and output


Finiteness : finite number of steps
Definiteness : Each step must be precisely different
Effectiveness : All the operations must be sufficiently basic that they can be done exactly
and in a finite length of time by a man using paper and a pen
Input :
Output :
- The simpler the problem the simpler the algorithm. The harder the algorithm the more
complicated and complex the algorithm will be
- An algorithm can be expressed in many ways like simple english, flow charts,
pseudocode, and programming language.
- Flow chart is a graphic representation method. A flowchart is a diagram that depicts the
flow of a program
- Pseudocode
- Programming language
- For = loop
- While = loop
- If = Conditional statement

Flow chart structure


- Sequence :A series of actions are performed in a sequence
- Decision structure :Expressed as a if statement in java code and is only one action to
perform.
- Repetition structure: expressed in java as a while loop
- Case :

Increment- ex: x++ which is basically x+1 and this is a shorthand


Alia

● Computers can only solve problems solvable by humans except ai obv


● The client doesn’t know what they want a lot of the time cuz they misdiagnose the
problem
● Computers don’t interpret/have intuition, steps need to be explicit

Stages of Solving a Problem:

1. Identification
● explicitly pinpoint where the problem is
● Describe the problem
1. Development
● Make plans B and C etc
1. Selection
2. Implementation
● Executing solution

Programming: series of steps to solve a problem; a sequence of instructions that explain


to a computer how to solve a problem
Computational thinking: finding the best-fit solution for a problem with endless solutions
The best-fit solution is found through a series of variables:

● Decomposition
● Data representation
● Generalization
● Modeling
● Algorithms

Series of unambiguous instructions designed to solve a problem in a finite number of


steps
They must have:

1. Finiteness
2. Definiteness
3. Effectiveness
4. Input
5. Output
Ways to Express an Algorithm

1. Simple spoken English


2. A flow chart

Oval: start/end terminal


Parallelogram: input/output
Rectangle: declaration of variable (giving it a name), assignment (giving it a value),
process
Diamond: if (conditional statement) while & for: loop
A with a circle: if u run out of space
Square with bars: a process/function
Sequence structure:
Things in order
Decision structure:
Conditional statement that have two options (if)
Repetition structure:
Loop (while/for)
Case structure:
Conditional statement where there are more than two options
Make sure conditions can end so it doesn’t crash

3. Pseudocode

Generic artificial language that doesn’t use syntax of any particular programming
language

4. Programming language

Incrementing: short-hands e.g= x++; instead of x=x+1;

Syntax: order of words in a sentence (comes from almost)


Modular programming: when procedure is divided into a series of sub-procedures
Identifier: name of variable / sub-procedure
Initial expression: declaring a variable and executes in only once, initial state of variable
Update expression: updates the value of the initial expression
** only statements end in semicolons, loops don’t
LOOP JAVA CODE:
for(initialization; condition; increment/decrement)
{
Statement;
}
for(int x = 0; x < 5; x++)
{
Statement;
}
Iteration: process of repeating a series of instructions

Prefetching: getting data or instructions from memory into the cache before they are
actually needed, instead of waiting for the data from RAM
Gantt chart:
List of jobs & how long it takes

● Pace & scheduling

Sequential:
Concurrent:
Pre-condition/input: indicates what must be true before the sub-procedure is called. It
describes the starting state before the execution of an algorithm

Post-condition/output: indicates what will be true when the sub-procedure completes its
task

Exception: an act or event that disrupts the anticipated flow of the program’s execution

Sequential processing: the execution of all sub-procedures one after the other by a single
processor

Concurrent: tasks implemented simultaneously (ex: a user inputting a password while


listening to music)

Concurrent processing: the execution of different instructions simultaneously by multiple


processors so as to achieve the best performance, requires better planning & coordination
of resources

Programs are broken down into procedures, and procedures are broken down into
sub-procedure.
Input: Something you put into the programing
Process: Something happens to your input
Output: Your changed input appears

Pseudocode -

- Main purpose is to help programmers develop computer programs


- Computers can't interpret a solution in pseudocode form thus it should be converted to
any computer language with ease

Rules for Pseudocode -

- Write only on statement per line


- Capitalize variables
- Keywords in lowercase
- Indent to show hierarchy
- End multi line structures
- Keep statements language independent
- Method names are mixed case, for example, getRecord
- Methods are invoked using the “dot notation” used in Java , C++, C#, and similar
languages , for example ,BIGARRY.binarySearch(27)
- These will be provided and comments // used , for example : N=5// the number of items
in the array .

Keywords in lower case :


If,else,while,loop,etc.

Memory location- memory locations are identified by their addresses we give them names

Rules for variable names -


- Capitalize the names
- Contain no spaces

Iteration :
- Iteration is the process of repeating a series of instructions .
- Iteration is expressed using the “ from to loop” and the “while loop” statements .
- The diamond shape performs a boolean test , evaluates and expression and returns a
boolean value (true or false )
Pre-planning: Process of planning something in advance
Pre-planning is set up or preparation required before a solution is implemented
Prefetching on broad terms: Getting data into the cache before they are actually used

Gantt Chart: A bar graph that shows when a process will start and end. Shows what is
being worked on at which times. On the left are tasks, at the top there is time.

Pre-Condition: What must be true before a procedure is called. The starting state

Post-Condition: What must be true when the procedure completes the task.

Exception is an act that disrupts the flow of the code’s execution.

You must write code to handle exceptions.

Sequential processing - is the execution of all sub-procedures one after the other by a single
processor

Concurrent - Means something that happens at the same time as something else. Imagine a
situation where a user replies to his emails while listening to his favorite song. Tasks are
implemented concurrently.

Concurrent processing - In computer science it means the execution of different instructions


simultaneously by multiple processors as to achieve the best performance

Programs are broken down into procedures and procedures are broken down into sub-procedures

Concurrent processing takes times and requires planning and coordination

Abstract thinking means ignoring unnecessary information to accomplish a goal

Object Oriented Programming: It uses abstraction. It is based on the principle that all everyday
tasks and things can be considered as entities. They are called objects (nouns) or events (verbs.

You can use Methods to change the values of data in an object. (Note: It is like functions from
Python)

A class produces objects/instances


Other words for variables: Properties, attributes,

General Principle of a Queue: First in, First out (FIFO)

General principle of a Stack: Last in, First out (LIFO)

A class has 3 components: Constructor, Attributes, Methods

Collection: An abstract class. It is used to add, store, manage, retrieve, manipulate, and
communicate the data using predefined methods

Modular Programs: Uses abstraction

Arrays: An ordered list of fixed length

Array code

public class Main


{
public static void main(String[] args)
{
int[] arr = new int[5];
arr[0]=4;
arr[2]=7;
for(int x = 0;x<5;x++)
{
System.out.println(arr[x]);
}
}

Bubble Sort: A simple algorithm that repeatedly steps through an array to sort it. It compares
adjacent terms and switches them if they are not in correct order.

Binary Search: Going to the middle term and checking if the target number is greater or less
than.
What affects Algorithm Runtime:

Your computer speed


If other programs are running
Complexity of the underlying algorithm
Efficiency of the compiler
Size of the input

Fundamental operations of a CPU:


● ADD
● COMPARE
● STORE
● RETRIEVE

A compiler translates high level code to low-level instructions. Compilers translate once. It
issues errors if it finds syntax errors.

A programming language is described as the combination of semantics, which refers to the


meaning of every construction that is possible in the language and its syntax, which relates to its
structure.

A grammar is a meta-language that is used to define the syntax of a language, while the rules of
statement construction are called syntax.

Each high level language has a unique syntax and a specific limited vocabulary.

The word import, class, int, etc. in Java are reserved keywords with special meaning in the Java
language.

Machine language is a very low level language that is the only thing a computer can
comprehend.

We use high level language because they are closer to spoken languages.

Modular programming is breaking down a complex program into smaller simpler components.
Advantages of modular programming:
● Distributed development
● Code reusability
● Program readability

A subprogram (sub procedure) is a unit that contains a sequence of computer instructions that
perform a specific and predefined task. It is defined and called within the program.

You might also like