< All Topics
Print

BEU Programming for Problem Solving (PPS) Notes: Unit 1 – Introduction to Problem Solving

Course Code: 100111 Beu pps notes pdf
Semester: 1st
Applicable For: CSE, AI, ML, Data Science, IoT, Cyber Security, IT, EEE, ECE, EE
University: Bihar Engineering University (BEU), Patna
Syllabus Session: 2024–2025 & 2025-2026
Unit: 1.0 – Introduction to Programming (Total Hours: 6 hrs)

Welcome, future programmers! This is the first step in your journey to master problem-solving through code. Unit 1 of BEU’s Programming for Problem Solving (PPS) lays the essential foundation. It’s not just about writing code; it’s about learning how to think logically and structure your solutions before you even touch a keyboard.

Understanding this unit is crucial because everything you learn in subsequent units—from C syntax to complex data structures—builds upon these fundamental concepts. Let’s break it down into digestible parts.


Overview of Unit 1: Why Introduction to Programming Matters

Programming is the heart of Computer Science and Engineering. This unit lays the foundation for how computers solve real-world problems using step-by-step logic. From understanding how a computer stores and runs programs to writing your first algorithm and converting it to code — this unit sets the stage for all future development in C, Python, Java, and beyond.


1. Components of a Computer System (Beu pps notes pdf)

Before writing a single line of code, it’s important to understand where a program runs and how it’s processed. The core components of any computer system include:

A labeled diagram showing CPU, Memory (RAM), Hard Disk, I/O Devices, and OS software layers.

a. Hardware Components:

  1. Input Unit: Devices like keyboard, mouse, or scanner that feed data and commands into the computer.
  2. Output Unit: Devices like monitors, printers, or speakers that present the results of processed data.
  3. Central Processing Unit (CPU): The “brain” of the computer. It has two main parts:
    • Arithmetic Logic Unit (ALU): Performs all mathematical calculations (+, -, *, /) and logical comparisons (>, <, ==).
    • Control Unit (CU): Directs the operation of all other components. It fetches instructions from memory, decodes them, and executes them.
  4. Memory Unit: This is where data and instructions are stored.
    • Primary Memory (RAM): Fast, volatile memory used to hold the program and data currently being executed. It is erased when the computer is turned off.
    • Secondary Memory (HDD/SSD): Permanent, non-volatile storage (like your hard drive) used to store programs and data long-term.
Hardware Components of Computer

b. Software Components:

  • Operating System (OS): Interface between hardware and user (Windows, Linux, etc.)
  • Compilers: Convert source code into machine-readable code.
  • Interpreters: Execute code line-by-line (used in Python, not C).
  • Assemblers: Convert assembly language to machine language.

Important Concept:
When you write a program in C:

  • It gets stored in the hard disk (as a .c file),
  • Loaded into RAM when running,
  • Executed by the CPU after being compiled to machine code.

2. Understanding Algorithms

What is an Algorithm?

An algorithm is a finite, step-by-step, unambiguous sequence of instructions to solve a given problem. It’s like a recipe for a cook. A good algorithm must be:

  • Clear and Unambiguous: Each step must be precise.
  • Well-Defined Inputs: It can have zero or more inputs.
  • Well-Defined Outputs: It must produce at least one output.
  • Finiteness: It must terminate after a finite number of steps.
  • Feasible: It must be simple enough to be done with a pencil and paper.

Example: Algorithm to make Maggi noodles.

  1. Start.
  2. Boil a cup of water in a pan.
  3. Add Maggi tastemaker to the water.
  4. Break the Maggi cake and add it to the pan.
  5. Cook for 2 minutes.
  6. Serve it in a bowl.
  7. Stop.

Example: Algorithm to find the largest of 3 numbers

  1. Start
  2. Read numbers A, B, C
  3. If A > B and A > C → A is the largest
  4. Else if B > A and B > C → B is the largest
  5. Else → C is the largest
  6. End

3. Flowchart Representation

A flowchart is a visual representation of an algorithm using diagrams and symbols. It helps beginners visualize the control flow of a program.

Basic Flowchart Symbols:

SymbolMeaning
OvalStart / End
RectangleProcess / Action
DiamondDecision
ArrowFlow Direction

Example: Flowchart to Check Even or Odd

Example: Flowchart to Check Even or Odd

4. Pseudocode (Simple English Logic)

Pseudocode bridges the gap between algorithm and programming language. It uses plain English to describe logic before coding. Pseudocode is a high-level, informal description of an algorithm that uses the structural conventions of a programming language but is intended for human reading. It’s a mix of natural language and programming constructs. It’s often easier and faster to write than a flowchart.

Key Constructs in Pseudocode:

  • Sequence: Steps are executed one after another.textCopyDownloadREAD A READ B SET sum = A + B PRINT sum
  • Selection (IF-THEN-ELSE): For decision making.textCopyDownloadIF temperature > 30 THEN PRINT “It’s hot outside.” ELSE PRINT “The weather is pleasant.” ENDIF
  • Iteration (WHILE, FOR): For loops.textCopyDownloadSET counter = 1 WHILE counter <= 5 DO PRINT counter counter = counter + 1 ENDWHILE

Example: Pseudocode to Print First N Natural Numbers

Input N
Set i = 1
While i <= N
Print i
i = i + 1
End While
End

You can later convert this pseudocode into a C program using loops.


Coming Up in Part 2:

  • From Algorithm to Program: The Journey
  • Variables, Data Types & Memory Locations
  • Understanding Syntax vs Logical Errors
  • Compiling C Code: From Source to Executable

This section deeply explains how an algorithm turns into a program, and dives into core programming concepts like variables, data types, memory locations, and errors.


5. From Algorithm to Program: The Complete Journey

Once you understand how to write an algorithm and represent it using flowcharts or pseudocode, the next step is to translate that logic into a computer program using a programming language like C.

But how does this translation happen?

Let’s break the journey into clear steps:

a. Step 1: Write the Source Code

The first thing a programmer does is write the source code. This is the human-readable form of the program written in a programming language (e.g., C, Python, Java).
In C, the source code file has an extension .c.

Example:

#include <stdio.h>

int main() {
printf("Hello, World!");
return 0;
}

This is your source code.


b. Step 2: Compile the Source Code

Once the code is written, it needs to be converted into machine code (0s and 1s) so that the computer can understand and execute it.

This process is done using a compiler.

The compiler:

  • Translates .c files into .obj (object files),
  • Then links them into an executable file (e.g., .exe in Windows or an out file in Linux).

c. Step 3: Generate Object Code and Executable

The compiler produces:

  • Object code: Machine-level instructions but not complete
  • Executable code: Fully working machine code

So, your flow is:

Source Code (.c) → Object Code (.obj) → Executable Code (.exe)


d. Step 4: Store and Run the Program

When the program is executed:

  • The OS loads the executable into RAM
  • The CPU reads and executes instructions
  • Output is displayed on the screen (if programmed)

6. Variables and Data Types in Programming

In programming, a variable is like a labeled box in memory used to store data. The data type of a variable defines what type of data it can store, how much memory it uses, and what operations can be performed on it.

Let’s understand in depth:


a. What is a Variable?

A variable:

  • Has a name (identifier),
  • Stores a value in a memory location,
  • Has a data type.

Example in C:

int age = 20;

Here:

  • int → data type
  • age → variable name
  • 20 → value stored

b. Memory Allocation

Each data type takes a specific amount of memory:

Data TypeMeaningSize (approx)
intInteger values4 bytes
floatDecimal values4 bytes
charSingle letter1 byte
doubleLong decimal8 bytes

When you write int x = 5;, the compiler reserves 4 bytes in RAM and labels it x.


c. Rules for Naming Variables

  • Must begin with a letter (A–Z or a–z) or underscore _
  • Cannot use special symbols like @, #, %, etc.
  • Cannot be a keyword like int, while, return
  • Should be meaningful (e.g., totalMarks is better than t1)

d. Examples of Declaring Variables

int age;
float height;
char grade;
double pi = 3.14159;

7. Syntax Errors vs Logical Errors

Programmers often encounter two major types of errors when writing code:


a. Syntax Errors

These are grammatical mistakes in your code, just like grammar errors in English.
They are caught during compilation.

Examples:

  • Missing semicolon
  • Using undeclared variable
  • Incorrect brackets

Example Code with Syntax Error:

int main() {
printf("Hello World")
return 0;
}

Error: Missing semicolon after printf() line.


b. Logical Errors

These errors occur when your program compiles and runs, but it doesn’t give the correct output due to flawed logic.

The program runs, but it’s wrong.

Example:

int a = 10, b = 5;
printf("Sum = %d", a - b);

The output will be 5, but you intended to add, not subtract. This is a logical error.


c. How to Identify and Fix Errors?

Error TypeDetected When?Fixed By
Syntax ErrorDuring compilationCompiler error log
Logical ErrorDuring executionManual debugging

Modern IDEs and tools like Code::Blocks, Visual Studio Code, or OnlineGDB help highlight both errors for easy debugging.


d. Best Practices to Avoid Errors

  • Write code step by step and compile frequently.
  • Use comments to explain logic.
  • Practice writing flowcharts before coding.
  • Dry run your code on paper to check logic.

Coming Up in Part 3:

  • What is a Compiler, Linker, Loader (and how they work)?
  • How Programs are Executed in Memory
  • Recap Table: All Concepts of Unit 1
  • Practice Questions and Mini Assignments

This part dives deeper into compilation stages, how programs are loaded and executed in memory, and gives a full recap of all concepts for better understanding and exam preparation.


8. Compilation Process: Compiler, Linker, and Loader Explained

When you write a C program, it does not directly run on the computer. Instead, it goes through a series of steps before you see the output.

Let’s understand the Compilation and Execution Process step by step:


Step 1: Writing the Source Code

  • You write code in a .c file using a text editor or IDE.
  • Example:
int main() {
printf("Hello BEU!");
return 0;
}

Step 2: Compilation (Using Compiler)

  • The compiler reads your .c file.
  • If there are no syntax errors, it converts it into object code (.obj or .o file).
  • This code is in machine language, but it’s still incomplete.

Step 3: Linking (Using Linker)

  • Programs often use functions from external libraries (like printf() from stdio.h).
  • The linker connects your object code with these library files.
  • The result is a complete executable file (.exe or a.out).

Step 4: Loading (Using Loader)

  • When you run the program, the loader in the OS loads the executable into RAM.
  • It assigns memory addresses to variables, functions, etc.

Step 5: Execution (By CPU)

  • The CPU reads the loaded code from RAM.
  • Executes it line by line, performs calculations, and displays output (if any).

Visual Summary:

Compilation Process: Compiler, Linker, and Loader Explained

9. Program Execution in Memory

When a program runs, it occupies various parts of memory.

Memory Segments:

SegmentPurpose
Code SegmentStores the compiled machine code
Data SegmentStores global/static variables
Stack SegmentStores function calls, local variables
Heap SegmentFor dynamic memory (like malloc())

What Happens to a Variable?

When you declare:

int marks = 80;

The compiler:

  • Reserves 4 bytes in RAM.
  • Assigns a memory address (like 0x7ffe).
  • Stores the value 80 at that address.

You can even access this memory using pointers (explained in Unit 4).


10. Recap: Key Concepts from Unit 1

ConceptSummary
Computer SystemHardware (CPU, RAM, Disk) + Software (OS, Compilers)
AlgorithmLogical step-by-step solution
FlowchartDiagrammatic representation of logic
PseudocodeEnglish-like logic for program
Source CodeHuman-readable C code
Compilation ProcessSource → Object → Executable
VariablesNamed memory locations
Data TypesDefine kind and size of data
Syntax ErrorsCompile-time grammar issues
Logical ErrorsWrong logic, runtime issues
ExecutionCPU runs machine code from RAM

11. Practice Questions (Theory + Coding)

Here are some questions you should try before moving to Unit 2:

Theory Questions:

  1. What are the components of a computer system?
  2. Define algorithm. Give one example.
  3. Draw a flowchart to find the largest of three numbers.
  4. Differentiate between syntax and logical errors.
  5. Explain how a C program is compiled and executed.

Coding Practice:

  1. Write pseudocode and C code to check whether a number is even or odd.
  2. Create a flowchart to calculate the sum of N natural numbers.
  3. Write a C program to print “BEU B.Tech 2024”.

Coming Up in Final Part (Part 4):

  • Short notes and definitions (for viva + quick revision)
  • Unit 1 MCQs (for internal/semester exam)
  • Free PDF Download
  • How Unit 1 connects to future units (loops, arrays, functions)

This part includes short notes for quick revision, MCQs for practice, a PDF download section, and a preview of next units.


12. Short Notes & Definitions for Quick Revision

To make your revision faster, here are the key concepts explained in 1–2 lines:

TermDefinition
AlgorithmA step-by-step logical process to solve a specific problem.
FlowchartA graphical representation of the algorithm using standardized symbols.
PseudocodeA human-readable, English-like way of representing programming logic.
Source CodeThe actual program written in a high-level language like C.
Object CodeThe compiled version of source code, still incomplete for execution.
Executable CodeFinal machine code file created after linking with libraries.
VariableA named memory location used to store data during program execution.
Data TypeSpecifies the kind of data a variable can hold (int, float, char, etc.).
Syntax ErrorProgramming rule violation that prevents compilation.
Logical ErrorA mistake in logic; program runs but produces incorrect output.
CompilerA tool that converts source code into object code.
LinkerCombines object code with libraries to generate an executable.
LoaderLoads the executable into memory so the CPU can run it.

13. Multiple Choice Questions (MCQs) – Unit 1

These MCQs will help you prepare for BEU internals and semester exams.

  1. Which of the following is responsible for converting source code into object code?
    a) Interpreter
    b) Linker
    c) Compiler
    d) Loader
    Answer: c) Compiler
  2. What is a syntax error?
    a) An error during program execution
    b) A logical mistake
    c) A grammatical mistake in code
    d) None of the above
    Answer: c) A grammatical mistake in code
  3. What does a flowchart use to represent a decision-making step?
    a) Rectangle
    b) Circle
    c) Diamond
    d) Triangle
    Answer: c) Diamond
  4. Which of the following is not a data type in C?
    a) int
    b) float
    c) string
    d) char
    Answer: c) string
  5. The variable int age = 20; reserves how much memory (approximately)?
    a) 2 bytes
    b) 4 bytes
    c) 8 bytes
    d) 1 byte
    Answer: b) 4 bytes

14. Download Section

To make learning easier, here are free downloadable resources:

Download PDF:

Download Practice Pack:

Note: If links are not yet live, they will be updated soon on www.PrabhakarGuru.com


15. Why Unit 1 Is Important for Future Topics

Unit 1 sets the logical and technical base for the rest of the semester:

Future UnitHow Unit 1 Helps
Unit 2 – Operators and LoopsYou’ll use variables, syntax rules, and flowcharts learned here to write loops.
Unit 3 – Arrays and StringsDeclaring and accessing variables directly relates to array structure.
Unit 4 – Functions and RecursionLogical structure and flow of algorithms guide recursive function writing.
Unit 5 – File HandlingVariables and memory concepts connect to file data structures.
Unit 6 – AlgorithmsThe logic-building in Unit 1 directly transfers to writing sorting/searching code.

Final Thoughts

Unit 1 – “Introduction to Programming” – is more than just a set of definitions. It introduces the thinking patterns and foundational skills you’ll use throughout your B.Tech journey. Whether you’re aiming to become a software developer, a data scientist, or an AI engineer — understanding how programming works at the core will always be your first step.

Make sure to:

  • Understand each concept before memorizing
  • Practice by drawing your own flowcharts and writing pseudocode
  • Start small C programs even if they’re basic
Table of Contents