1 of 37

Programming Fundamentals

Day-01: Introduction

National Institute of Electronics & Information Technology

Ministry of Electronics & Information Technology (MeitY), Government of India

Gorakhpur Center

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

2 of 37

Contents to be covered

  • Introduction of Programming
  • Algorithms
  • Flow-charts
  • Functionality and Implementation
  • Right Abstraction
  • Code documentation
  • Language-Specific Considerations:
  • Run time error and logical bug
  • Black Box and White Box testing
  • Debugging techniques

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

3 of 37

Programming Fundamentals

  • Programming fundamentals are the foundational concepts, skills, and principles for writing instructions in a programming language that tell a computer how to solve a problem. 
  • Key fundamentals include variables and data types to store information, control structures (like if statements and loops) to manage the program's flow, algorithms to define step-by-step solutions, and functions to organize code into reusable blocks. .

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

4 of 37

How to Learn Programming Fundamentals�

  • Start with a problem: Understand the problem you want to solve. 
  • Plan the solution: Develop a logical, step-by-step algorithm, often using pseudocode or flowcharts. 
  • Code the program: Implement your algorithm in a programming language. 
  • Test the program: Verify that the program works correctly and handles different inputs. 
  • Practice: Consistent practice is essential to develop the intuition needed to devise and implement solutions effectively. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

5 of 37

Program vs Algorithm

  • An algorithm is a well-defined, step-by-step procedure or set of rules for solving a specific problem or accomplishing a task. It is a conceptual blueprint, independent of any particular programming language or hardware. Algorithms are concerned with the logic and sequence of operations required to achieve a desired outcome.
  • A program, on the other hand, is the concrete implementation of an algorithm in a specific programming language. It is a set of instructions written in a language that a computer can understand and execute. A program takes the abstract steps defined by an algorithm and translates them into executable code, allowing a computer to perform the intended actions. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

6 of 37

Summary of the key differences:

  • Nature:

An algorithm is an abstract concept, a logical plan. A program is a concrete, executable

entity.

  • Language:

Algorithms can be described in natural language, pseudocode, or flowcharts. Programs

must be written in a specific programming language (e.g., Python, Java, C++).

  • Execution:

Algorithms are not directly executable by a computer. Programs are designed

to be executed by a computer.

  • Dependency:

Algorithms are independent of hardware and operating systems. Programs

depend on the hardware and operating system they run on.

  • Purpose:

An algorithm provides the theoretical solution to a problem. A program brings

that solution to life, making it functional on a computer.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

7 of 37

Implementing Algorithm

  • Implementing an algorithm involves clearly defining the problem, selecting an appropriate algorithm, and then translating its logic into a working program using a programming language, followed by rigorous testing to ensure correctness and performance. This process typically begins with conceptualizing the algorithm through pseudocode or flowcharts and then progressively coding, testing, and refining it to solve the problem efficiently and accurately. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

8 of 37

Steps to Implement an Algorithm

  • 1. Define the Problem:
  • Clearly state the problem you are trying to solve and identify any constraints, inputs, and expected outputs. 
  • 2. Analyze and Select an Algorithm:
  • Choose an algorithm that is the best fit for the problem and its constraints. This might involve selecting from different algorithmic techniques, such as brute force, divide and conquer, or greedy algorithms. 
  • 3. Design the Algorithm:
  • Outline the algorithm's logic using pseudocode or flowcharts. This step involves breaking the problem into smaller, manageable sub-problems. 
  • 4. Choose a Programming Language:
  • Select a programming language that aligns with the algorithm's requirements and your team's expertise. 
  • 5. Translate to Code:
  • Write the algorithm's steps in the chosen programming language, ensuring it adheres to coding best practices. 
  • 6. Test and Refine:
  • Use various test cases to validate the algorithm's correctness, identify any bugs, and evaluate its performance. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

9 of 37

Algorithm: Calculate the square of a number

  • Start.
  • Input the number (N) whose square you want to find.
  • Multiply the number (N) by itself.
  • Store the result of the multiplication in a variable (result).
  • Output the value of the variable (result), which represents the square of the input number.
  • End.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

10 of 37

An algorithm for the addition of two numbers

  • Start: Begin the process.
  • Declare Variables: Create storage locations (variables) to hold the two numbers and their sum.
  •  For example, num1, num2, and sum.
  • Input Numbers: Obtain the values of the two numbers to be added. These values will be assigned to num1 and num2.
  • Calculate Sum: Add the values stored in num1 and num2, and store the result in the sum variable.
  • Display Sum: Present the calculated sum as the output.
  • Stop: End the process.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

11 of 37

Language idependent algorithm representation using flowchart and pseudo-codes

  • Flowcharts and pseudocode are two common methods for representing algorithms in a language-independent manner. This allows developers to plan and describe the logic of a program without being tied to the syntax of a specific programming language.
  •  Pseudocode:

Pseudocode is a high-level, informal description of an algorithm that uses a combination of natural language

and programming-like constructs.

  • Key Features:
  • Structured Constructs: Often uses keywords like IF-THEN-ELSE, WHILE, FOR, BEGIN, END, similar to programming languages, but without strict syntax rules.
  • Readability: Emphasizes clarity and readability over strict syntax, making it easy to understand for anyone with basic programming knowledge.
  • Language Independence:
  • It avoids the specific syntax of any single programming language, allowing it to be easily translated into various languages.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

12 of 37

Example (Finding the larger of two numbers):

  • BEGIN
  • READ A, B
  • IF A > B THEN
  • PRINT A
  • ELSE
  • PRINT B
  • END IF
  • END

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

13 of 37

Flow Chart

A flowchart is a graphical representation of decisions and their results mapped out in individual shapes that were first developed by Herman Goldstine and John von Neumann in the 1940’s. Flowcharts can provide a step-by-step diagram for mapping out complex situations, such as programming code or troubleshooting problems with a Computer.

  • A diagrammatic representation that illustrates the sequence of operations to be performed to get the solution of a problem.
  • Generally drawn in the early stages of formulating computer solutions.
  • Facilitate communication between programmers and business people/end users.
  • Once the flowchart is drawn, it becomes easy to write the program in any high level language.
  • Must for the better documentation of a complex program.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

14 of 37

Flow Chart

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

15 of 37

Flow Chart

Example 1: Draw a flow chart to show the addition of two no.

START

STOP

Accept no1 & no2

Sum=no1+no2

Display the sum

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

16 of 37

Flow Chart

Example 2: Draw a flowchart to find the sum of first 50 natural numbers

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

17 of 37

Flow Chart

Example 3: Draw a flowchart to find the largest of three numbers A,B & C.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

18 of 37

Flow Chart

Example 4: Draw a flowchart to find the factorial value of given number.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

19 of 37

Functionality and Implementation

  • "Functionality" in programming refers to how a program or language behaves and what tasks it performs.

While "implementation" is the process of building that functionality into a working software using specific languages, tools, and processes, such as compilation or interpretation. Functional languages, a specific type of programming language, implement functionality through the use of mathematical functions and compositions, treating functions as first-class citizens rather than using imperative control structures like loops and variables. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

20 of 37

Functionality�

  • Program behavior

Describes the actions a program takes and the results it produces. 

  • Language features

Refers to the core characteristics of a programming language, such as its support for specific paradigms (e.g., functional, imperative). 

  • Data transformation

In functional programming, functionality is centered on transforming data through the application of functions

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

21 of 37

Implementation�

  • Code translation: The process of converting human-readable code into machine-executable instructions. 
  • Tools and methods: Uses programming languages, design patterns, compilers, and interpreters to bring a program to life. 
  • Integration: Involves combining different components and testing them to ensure a fully functional software product. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

22 of 37

Right Abstraction

  • Abstraction is used in language to hide complexity, allowing for simpler communication and understanding of intricate systems.
  • In computer programming, abstraction hides implementation details, enabling developers to create and use complex software by focusing on high-level functionality and promoting code reusability.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

23 of 37

Usages of right abstraction

  • Hiding Complexity:Abstraction masks intricate implementation details, allowing programmers to work with higher-level operations without needing to understand the underlying mechanics. 
  • Simplifying Systems:By presenting only necessary information, abstractions make complex systems easier to understand, use, and maintain. 
  • Enhancing Reusability:Abstraction promotes code reusability by defining common functionalities in a simple, understandable way, so they can be used in various parts of a program or even across different programs. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

24 of 37

usages of right abstraction

  • Improving Security:

Hiding internal details of a system through abstraction can increase security by preventing users from accessing or modifying sensitive information they are not meant to. 

  • Language Evolution:

The historical development of programming languages from machine code to high-level languages is an example of increasing levels of abstraction, building upon previous stages to create more expressive and manageable languages. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

25 of 37

Code documentation

  • Code documentation varies across programming languages, often leveraging language-specific features and conventions for clarity and automation.
  • Common Documentation Approaches:
  • Inline Comments:
  • Most languages support single-line and multi-line comments (e.g., // and /* */ in C++/Java, # in Python, <!-- --> in HTML) for explaining specific code sections.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

26 of 37

  • Docstrings/Doc Comments:
  • Many languages have dedicated constructs for documenting functions, classes, and modules, which can be extracted by documentation generators.Python: Uses docstrings (multi-line strings) immediately after a function, class, or module definition.
  • Java: Employs Javadoc comments (/** ... */) before declarations.
  • C#: Utilizes XML documentation comments (/// <summary>...</summary>) for similar purposes.
  • JavaScript: JSDoc comments (/** ... */) are widely used.
  • External Documentation Generators:
  • Tools like Doxygen (for C++, Java, Python, etc.), Sphinx (primarily Python), and Javadoc (for Java) parse source code and doc comments to generate comprehensive documentation in various formats (HTML, PDF).
  • Markup Languages:
  • Lightweight markup languages like reStructuredText (used with Sphinx) and Markdown are frequently used for creating external documentation files, especially in version control systems like Git.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

27 of 37

Language-Specific Considerations:�

  • Type Hinting:
  • Languages like Python and TypeScript allow for type hints, which inherently contribute to code understanding and can be leveraged by documentation tools.
  • Annotations/Decorators:
  • Java annotations and Python decorators can be used to add metadata that documentation tools can interpret.
  • Module Systems:
  • The structure of module systems in languages like Python and JavaScript influences how documentation is organized and linked.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

28 of 37

Run time error and logical bug

  • A runtime error is a program crash or violation of a system rule that occurs while the program is executing, often due to unexpected input, memory issues, or improper resource use. In contrast, a logical bug is when the program runs to completion without crashing but produces an incorrect or unintended result due to flaws in the programmer's logic or algorithm. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

29 of 37

Runtime Error

  • When it occurs: During the execution of the program. 
  • Cause: Something unexpected happens during runtime, such as trying to divide by zero, accessing an invalid memory location, encountering a network error, or providing invalid data to a function. 
  • Outcome: The program typically stops executing or crashes. 
  • Example: Trying to assign a string to an integer variable where it's not allowed, or a program running out of memory. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

30 of 37

Logical Bug�

  • When it occurs:

The program may compile and execute without any obvious errors. 

  • Cause:

The underlying logic or algorithm in the code is incorrect, leading to the program producing the wrong output. 

  • Outcome:

The program runs successfully but does not behave as intended. 

  • Example:

A mathematical formula is incorrectly implemented, causing an inaccurate calculation, or an if-then statement uses the wrong condition, leading to an incorrect decision. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

31 of 37

Black Box and White Box testing

  • Black box testing treats the software as a "black box" with no knowledge of its internal workings, focusing on functionality based on inputs and outputs from an end-user perspective. 
  • White box testing treats software as a "white box," requiring knowledge of the internal code and structure to test for logical errors and internal functionality, often performed by developers. Combining both is crucial for high-quality, robust software, as black box testing ensures external features work as expected, while white box testing verifies the internal code is sound. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

32 of 37

Key Differences of Black and White Box Testing�

  • Black Box Testing focuses only on what the software does from the outside, without looking at how it works internally.
  • In contrast, White Box Testing examines the internal workings and structure of the software.
  • You do not need to understand how the system is built to do Black Box Testing, but for White Box Testing, you need to know the code.
  • Because of this, Black Box Testing is usually quicker to perform than White Box Testing

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

33 of 37

Debugging techniques

  • Effective debugging techniques include a systematic process of identifying, reproducing, and isolating a bug, followed by implementing a fix and verifying the solution. 
  • Key techniques involve using debuggers with breakpoints, adding log statements or print statements to track execution, and applying logic like backtracking, binary search, and elimination to narrow down the problem. 
  • Techniques such as rubber ducking, collaborative debugging, and taking breaks can also offer fresh perspectives and improve efficiency. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

34 of 37

Systematic Debugging Process

  • Understand the Problem: Fully grasp the expected behavior and how it differs from the observed error. 
  • Reproduce the Problem: Find the conditions and inputs that consistently trigger the issue. 
  • Isolate the Problem: Narrow down the specific section of code or conditions causing the bug. 
  • Implement a Fix: Correct the faulty logic, data, or environmental factors identified. 
  • Verify the Fix: Test the corrected code to ensure the problem is resolved and no new issues were introduced. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

35 of 37

Key Debugging Techniques

  • Debuggers and Breakpoints:
  • Use a debugging tool to set breakpoints at specific points in your code, pausing execution to inspect variables and step through the code line by line. 
  • Logging:
  • Add log statements to your code to record the flow of execution and the values of variables, which helps in analyzing the problem after the fact. 
  • Print Statements (Brute Force):
  • A simple method where you "print" the values of variables or messages at various points to understand the program's state. 

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

36 of 37

  • Backtracking (Backward Debugging):
  • Start from the point of the error and work backward through the code to trace the sequence of events that led to the failure. 
  • Binary Search:
  • Divide your code into halves and systematically eliminate the half that doesn't contain the bug, narrowing the search area efficiently. 
  • Cause Elimination:
  • Make a list of potential causes for the bug and systematically test each one to rule it out. 
  • Rubber Ducking:
  • Explain the problem and the code to an inanimate object (like a rubber duck), which can help you clarify your thoughts and find the solution. 
  • Collaborative Debugging:
  • Get a fresh pair of eyes by having a colleague look at the code or work with you on the debugging task. 
  • Static Analysis:
  • Use tools to analyze your code without executing it to identify potential issues and bugs.

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia

37 of 37

Thank You

Any Query

/GKP.NIELIT

http://www.nielit.gov.in/gorakhpur

@GKP_NIELIT

/NIELITIndia

/school/NIELITIndia