🖥️

Introduction to Programming with Striver

Jul 17, 2024

Lecture Notes: Introduction to Programming with Striver

Introduction

  • Presenter: Striver
  • Platform: Interview preparation website and YouTube channel
  • Target Audience: Programmers preparing for interviews (3-6 months left)
  • Main Resources: Striver's SD Sheet (191 curated problems)
  • New Resource: Striver's A to Z DSA course/sheet
    • 455 steps with problem links and videos for hard topics

Recommended Initial Steps for Beginners

  • Basics of DS Algo: Ensure understanding before starting
  • Choose a programming language: C++, Java, Python, JavaScript
    • Master one language
      • Previous video covers C++ vs Java

Starting with C++ Basics

  • Skeleton of C++ code: #include, int main, {}, return 0;
  • Input/Output Libraries: #include<iostream> for input/output
    • Other libraries: math.h for math functions, string for string functions

C++ Code Example

#include <iostream> using namespace std; int main() { cout << "Hello, world!" << endl; return 0; }

Detailed C++ Concepts

Basic Structure

  • Input/Output: cin, cout
  • Escaping Characters: \n, endl
  • Using Namespaces: using namespace std;

Data Types

  • Integer: int, long, long long
  • Floating Point: float, double
  • String: string, getline
  • Character: char
  • Universal Library Inclusion: #include<bits/stdc++.h>

Conditional Statements

  • If-Else: Basic decision-making
  • Nested If-Else: For complex conditions
  • Examples: Age check, grading system

Switch Statements

  • Purpose: Alternative to multiple if-else
  • Syntax: switch (variable) { case 1: ... break; case 2: ... break; ... default: ... }

Arrays and Strings

  • 1D Arrays: Used for storing similar data types
  • 2D Arrays: For Matrix-like structures
  • Strings: Sequence of characters
  • Accessing Elements: Using indices

Loops

For Loop

  • Syntax: for (initialization; condition; increment/decrement) { ... }
  • Nested For Loops: Often used in pattern problems

While Loop

  • Syntax: while (condition) { ... }
  • Do-While Loop: Guaranteed to execute at least once, do { ... } while (condition);

Functions

Introduction

  • Purpose: Modularize code, improve readability, reuse code
  • Types:
    • Void Functions (no return value)
    • Functions with return values
    • Parameterized Functions
    • Non-Parameterized Functions

Detailed Example

  • Void Function:
void printName() { cout << "Striver" << endl; } int main() { printName(); return 0; }
  • Parameterized Function:
void printName(string name) { cout << name << endl; } int main() { string name = "Striver"; printName(name); return 0; }
  • Return Function:
int sum(int num1, int num2) { return num1 + num2; } int main() { int result = sum(5, 10); cout << result << endl; return 0; }

Pass by Value vs Pass by Reference

  • Pass by Value: Original data is not modified
    • Copies of values are passed to functions
  • Pass by Reference: Original data is modified
    • Actual memory address is passed to functions
  • Example of Pass by Reference:
void doSomething(int &num) { num += 5; } int main() { int number = 10; doSomething(number); cout << number << endl; // Output will be 15 return 0; }

Arrays and Functions

  • Arrays are passed by reference: Modifications in functions reflect outside
  • Example:
void modifyArray(int arr[], int size) { for(int i = 0; i < size; i++) { arr[i] += 100; } } int main() { int arr[5] = {1, 2, 3, 4, 5}; modifyArray(arr, 5); for(int i = 0; i < 5; i++) { cout << arr[i] << " "; // Outputs: 101 102 103 104 105 } return 0; }

Conclusion

  • Upcoming Topics: In-depth time complexity
  • Next Steps: Watch C++ STL video for more insights
  • Action Items: Like, subscribe, and follow Striver on social media for updates on the DSA playlist.