This document provides information about functions in C programming. It defines a function as a block of code that performs a specific task and can be reused. The general form of a function definition includes the return type, function name, parameters, and function body. Functions allow breaking a large, complex program into smaller, modular sub-programs. Parameters are used to pass values between the calling function and the called function. Variables have local scope and are only accessible within the function they are defined, so parameters must be explicitly passed between functions. Functions can return values to the calling function using the return statement.
Functions in C allow programmers to package blocks of code that perform tasks. Functions make code reusable and easier to understand by separating code into modular units. A function has a name, list of arguments it takes, and code that is executed when the function is called. Functions can communicate between each other via parameters passed by value or by reference. Parameters passed by value are copied, so changes inside the function don't affect the original variable, while parameters passed by reference allow the function to modify the original variable. Functions can also call themselves recursively.
The document discusses functions in C programming. It defines functions as self-contained blocks of code that perform a specific task. Functions make a program more modular and easier to debug by dividing a large program into smaller, simpler tasks. Functions can take arguments as input and return values. Functions are called from within a program to execute their code.
A large program can be divided into smaller subprograms or functions. Functions make a program easier to write, read, update and debug by dividing it into self-contained tasks. Functions allow code to be reused and are called by the main program. Functions may accept arguments from the main program and return values to the main program. This allows two-way communication between functions and the main program.
The document discusses functions in C programming. It defines functions as self-contained blocks of code that perform a specific task. Functions make a program modular and easier to debug. There are four main types of functions: functions with no arguments and no return value, functions with no arguments but a return value, functions with arguments but no return value, and functions with both arguments and a return value. Functions are called by their name and can pass data between the calling and called functions using arguments.
This document discusses functions in C programming. It defines what a function is and explains why we use functions. There are two types of functions - predefined and user-defined. User-defined functions have elements like function declaration, definition, and call. Functions can pass parameters by value or reference. The document also discusses recursion, library functions, and provides examples of calculating sine series using functions.
The document discusses functions in C++. It defines a function as a self-contained program that performs a specific task. Functions help break large programs into smaller, modular pieces. The key parts of a function include the prototype, definition, arguments, return statement, and calling a function. Functions make programs easier to understand, maintain and debug.
The document discusses functions in C programming. It defines what a function is, how functions are declared and defined, how to pass arguments to functions, and different ways to call functions. It provides examples of using functions to calculate factorials, Fibonacci series, find the highest common factor and lowest common multiple of two numbers, and sum the digits of a number recursively. Various ways of implementing functions using loops, recursion, and by passing arguments are demonstrated through code examples.
Functions in C allow programmers to package blocks of code that perform tasks. Functions make code reusable and easier to understand by separating code into modular units. A function has a name, list of arguments it takes, and code that is executed when the function is called. Functions can communicate between each other via parameters passed by value or by reference. Parameters passed by value are copied, so changes inside the function don't affect the original variable, while parameters passed by reference allow the function to modify the original variable. Functions can also call themselves recursively.
The document discusses functions in C programming. It defines functions as self-contained blocks of code that perform a specific task. Functions make a program more modular and easier to debug by dividing a large program into smaller, simpler tasks. Functions can take arguments as input and return values. Functions are called from within a program to execute their code.
A large program can be divided into smaller subprograms or functions. Functions make a program easier to write, read, update and debug by dividing it into self-contained tasks. Functions allow code to be reused and are called by the main program. Functions may accept arguments from the main program and return values to the main program. This allows two-way communication between functions and the main program.
The document discusses functions in C programming. It defines functions as self-contained blocks of code that perform a specific task. Functions make a program modular and easier to debug. There are four main types of functions: functions with no arguments and no return value, functions with no arguments but a return value, functions with arguments but no return value, and functions with both arguments and a return value. Functions are called by their name and can pass data between the calling and called functions using arguments.
This document discusses functions in C programming. It defines what a function is and explains why we use functions. There are two types of functions - predefined and user-defined. User-defined functions have elements like function declaration, definition, and call. Functions can pass parameters by value or reference. The document also discusses recursion, library functions, and provides examples of calculating sine series using functions.
The document discusses functions in C++. It defines a function as a self-contained program that performs a specific task. Functions help break large programs into smaller, modular pieces. The key parts of a function include the prototype, definition, arguments, return statement, and calling a function. Functions make programs easier to understand, maintain and debug.
The document discusses functions in C programming. It defines what a function is, how functions are declared and defined, how to pass arguments to functions, and different ways to call functions. It provides examples of using functions to calculate factorials, Fibonacci series, find the highest common factor and lowest common multiple of two numbers, and sum the digits of a number recursively. Various ways of implementing functions using loops, recursion, and by passing arguments are demonstrated through code examples.
The document discusses C programming functions. It provides examples of defining, calling, and using functions to calculate factorials, Fibonacci sequences, HCF and LCM recursively and iteratively. Functions allow breaking programs into smaller, reusable blocks of code. They take in parameters, can return values, and have local scope. Function prototypes declare their interface so they can be called from other code locations.
This document provides an introduction to C++ programming. It covers basic concepts like variables, data types, input/output statements, conditional statements, loops, arrays, functions, and classes. Some key points:
- A C++ program consists of variable declarations, input/output statements, computations, and printing output. Comments begin with //.
- Variables are declared with a data type like int or double followed by the name. Input is done with cin and output with cout.
- Conditional statements like if-else and loops like while are used to control program flow. Boolean conditions use comparison and logical operators.
- Arrays allow storing multiple values of a type. Functions can be predefined or programmer-
The document discusses passing objects as arguments to functions in C++. It can be done in two ways - by value using a copy of the object or by reference passing the address. The sample program demonstrates passing two height objects to a sum function that adds their feet and inches values. The function receives the objects by value, performs the calculation, and outputs the total height.
A pointer is a variable that stores the memory address of another variable. Pointers allow access and manipulation of other variables indirectly. There are two pointer operators - the address-of operator (&) which returns the memory address of a variable, and the dereference operator (*) which accesses the value of the variable at the memory address stored in the pointer. Pointers can be initialized by assigning the address of a variable to the pointer variable. Pointers can be used to pass arguments by reference, allowing changes made to parameters within a function to be reflected in the calling function.
1. A function is a block of code that performs a specific task. Functions allow programmers to split a large program into smaller sub-tasks and call them multiple times.
2. There are two main types of functions - library functions provided by the standard library, and user-defined functions created by the programmer.
3. Functions make programs easier to write, read, update and debug by splitting them into smaller, well-defined tasks.
Pointers allow a variable to hold the memory address of another variable. A pointer variable contains the address of the variable it points to. Pointers can be used to pass arguments to functions by reference instead of by value, allowing the function to modify the original variables. Pointers also allow a function to return multiple values by having the function modify pointer variables passed to it by the calling function. Understanding pointers involves grasping that a pointer variable contains an address rather than a value, and that pointers enable indirect access to the value at a specific memory address.
Pointers and call by value, reference, address in CSyed Mustafa
The document discusses various C programming concepts including:
1. It provides an example program to calculate the area of a circle using #define and shows how to conditionally compile code blocks using #if, #elif, #else and #endif.
2. It explains that the C preprocessor transforms code before compilation by allowing users to define macros and includes several built-in preprocessor directives like #include, #define, and #if.
3. It discusses static and dynamic memory allocation in C, listing functions like malloc(), calloc(), free(), and realloc() for dynamic allocation and provides examples of their use.
The document discusses functions in C programming. It defines a function as a block of code that performs a specific task. There are two types of functions: predefined standard library functions and user-defined functions. The key aspects of a function are its declaration, definition, and call. Functions can be used to break a large program into smaller, reusable components. Parameters can be passed to functions by value or by reference. Recursion is when a function calls itself, and is used in algorithms like calculating factorials. Dynamic memory allocation allows programs to request memory at runtime using functions like malloc(), calloc(), realloc(), and free().
The document discusses functions in C programming. It defines what a function is and explains why functions are used to avoid duplicating code and make programs easier to design, understand and maintain. It describes the different types of functions like pre-defined and user-defined functions. It also covers function prototypes, parameters, return values, recursion, library functions and pointers.
Pointers,virtual functions and polymorphism cpprajshreemuthiah
This document discusses key concepts in object-oriented programming in C++ including polymorphism, pointers, pointers to objects and derived classes, virtual functions, and pure virtual functions. Polymorphism allows one name to have multiple forms through function and operator overloading as well as virtual functions. Pointers store the memory address of a variable rather than the data. Pointers can be used with objects, arrays, strings, and functions. Virtual functions allow calling a derived class version of a function through a base class pointer. Pure virtual functions define an abstract base class that cannot be instantiated.
The document discusses functions in C programming. It defines functions and explains their various parts like declaration, definition, and invocation. It also differentiates between function declaration and definition. Various types of functions are classified based on their inputs and outputs. The key differences between call by value and call by reference are explained with examples. Advantages of pass by reference are also mentioned.
There are two ways to initialize a structure:
1. Initialize structure members individually when declaring structure variables:
struct point {
int x;
int y;
} p1 = {1, 2};
2. Initialize an anonymous structure and assign it to a variable:
struct point p2 = {3, 4};
Structures allow grouping of related data types together under one name. They are useful for representing records, objects, and other data aggregates. Structures can contain nested structures as members. Arrays of structures are also possible. Structures provide data abstraction by allowing access to their members using dot operator.
Pointer is a variable that stores the address of another variable. Pointers allow indirect referencing of values and are useful for returning multiple values from functions, dynamic memory allocation, and building complex data structures like linked lists. Pointers are declared with a data type followed by an asterisk and are initialized with the address of another variable. The address-of operator & returns the address of its operand, while the indirection operator * accesses the value at the address stored in the pointer. Pointers can reference values indirectly, be passed by reference to functions to modify caller's variables, and implement call by reference parameter passing in C.
It tells about functions in C++,Types,Use,prototype,declaration,Arguments etc
function with
A function with no parameter and no return value
A function with parameter and no return value
A function with parameter and return value
A function without parameter and return value
Call by value and address
The document discusses C functions. Some key points:
1. Functions allow breaking code into reusable chunks that perform specific tasks. The main() function is required in every C program.
2. Functions are declared with a return type, name, and parameters. Definitions include the function body.
3. Standard library functions like strcat() and memcpy() are pre-defined for common tasks.
4. Functions are called by name and pass arguments by value or reference. Parameters allow customizing a function's behavior.
5. Recursion allows a function to call itself, enabling solutions to problems like factorials and Fibonacci sequences.
The document discusses functions in C programming. It defines what a function is and explains that functions can be used to break a large program into smaller modular pieces of code that can be reused. The key points covered include: defining functions with return types, parameters, and bodies; declaring functions; calling functions by passing arguments; and passing arguments by value vs reference. Examples are provided to demonstrate creating, calling, and passing arguments to functions. Recursion is also discussed as a special case where a function calls itself.
The document discusses functions in C programming. It covers:
- Functions allow dividing programs into reusable blocks of code. They can be called multiple times.
- Advantages include avoiding duplicating code, calling functions from anywhere, and improving readability. However, function calls require overhead.
- There are three aspects of a function: declaration, call, and definition. Declaration specifies the name, parameters, and return type. Definition contains the code.
- Functions can return values or not. They can accept arguments or not. Library functions are predefined, while user-defined functions are created by the programmer.
Functions allow programmers to organize and reuse code. There are two types of functions: library functions provided by C++ and user-defined functions created by the programmer. Functions communicate by passing arguments and returning values. Key concepts for functions include declaration, definition, call, pass by value, pass by reference, and pointers. Virtual functions allow for runtime polymorphism by calling the correct overridden function based on the object's type.
Functions allow programmers to organize C++ code into reusable blocks of statements. There are two types of functions: library functions provided in header files and user-defined functions created by the programmer. Functions communicate by passing arguments, which requires function declaration, definition, and calls. Pointers and references allow functions to modify argument values or share data. Virtual functions enable runtime polymorphism in inheritance hierarchies.
Hand Rolled Applicative User ValidationCode KataPhilip Schwarz
Could you use a simple piece of Scala validation code (granted, a very simplistic one too!) that you can rewrite, now and again, to refresh your basic understanding of Applicative operators <*>, <*, *>?
The goal is not to write perfect code showcasing validation, but rather, to provide a small, rough-and ready exercise to reinforce your muscle-memory.
Despite its grandiose-sounding title, this deck consists of just three slides showing the Scala 3 code to be rewritten whenever the details of the operators begin to fade away.
The code is my rough and ready translation of a Haskell user-validation program found in a book called Finding Success (and Failure) in Haskell - Fall in love with applicative functors.
What is Augmented Reality Image Trackingpavan998932
Augmented Reality (AR) Image Tracking is a technology that enables AR applications to recognize and track images in the real world, overlaying digital content onto them. This enhances the user's interaction with their environment by providing additional information and interactive elements directly tied to physical images.
The document discusses C programming functions. It provides examples of defining, calling, and using functions to calculate factorials, Fibonacci sequences, HCF and LCM recursively and iteratively. Functions allow breaking programs into smaller, reusable blocks of code. They take in parameters, can return values, and have local scope. Function prototypes declare their interface so they can be called from other code locations.
This document provides an introduction to C++ programming. It covers basic concepts like variables, data types, input/output statements, conditional statements, loops, arrays, functions, and classes. Some key points:
- A C++ program consists of variable declarations, input/output statements, computations, and printing output. Comments begin with //.
- Variables are declared with a data type like int or double followed by the name. Input is done with cin and output with cout.
- Conditional statements like if-else and loops like while are used to control program flow. Boolean conditions use comparison and logical operators.
- Arrays allow storing multiple values of a type. Functions can be predefined or programmer-
The document discusses passing objects as arguments to functions in C++. It can be done in two ways - by value using a copy of the object or by reference passing the address. The sample program demonstrates passing two height objects to a sum function that adds their feet and inches values. The function receives the objects by value, performs the calculation, and outputs the total height.
A pointer is a variable that stores the memory address of another variable. Pointers allow access and manipulation of other variables indirectly. There are two pointer operators - the address-of operator (&) which returns the memory address of a variable, and the dereference operator (*) which accesses the value of the variable at the memory address stored in the pointer. Pointers can be initialized by assigning the address of a variable to the pointer variable. Pointers can be used to pass arguments by reference, allowing changes made to parameters within a function to be reflected in the calling function.
1. A function is a block of code that performs a specific task. Functions allow programmers to split a large program into smaller sub-tasks and call them multiple times.
2. There are two main types of functions - library functions provided by the standard library, and user-defined functions created by the programmer.
3. Functions make programs easier to write, read, update and debug by splitting them into smaller, well-defined tasks.
Pointers allow a variable to hold the memory address of another variable. A pointer variable contains the address of the variable it points to. Pointers can be used to pass arguments to functions by reference instead of by value, allowing the function to modify the original variables. Pointers also allow a function to return multiple values by having the function modify pointer variables passed to it by the calling function. Understanding pointers involves grasping that a pointer variable contains an address rather than a value, and that pointers enable indirect access to the value at a specific memory address.
Pointers and call by value, reference, address in CSyed Mustafa
The document discusses various C programming concepts including:
1. It provides an example program to calculate the area of a circle using #define and shows how to conditionally compile code blocks using #if, #elif, #else and #endif.
2. It explains that the C preprocessor transforms code before compilation by allowing users to define macros and includes several built-in preprocessor directives like #include, #define, and #if.
3. It discusses static and dynamic memory allocation in C, listing functions like malloc(), calloc(), free(), and realloc() for dynamic allocation and provides examples of their use.
The document discusses functions in C programming. It defines a function as a block of code that performs a specific task. There are two types of functions: predefined standard library functions and user-defined functions. The key aspects of a function are its declaration, definition, and call. Functions can be used to break a large program into smaller, reusable components. Parameters can be passed to functions by value or by reference. Recursion is when a function calls itself, and is used in algorithms like calculating factorials. Dynamic memory allocation allows programs to request memory at runtime using functions like malloc(), calloc(), realloc(), and free().
The document discusses functions in C programming. It defines what a function is and explains why functions are used to avoid duplicating code and make programs easier to design, understand and maintain. It describes the different types of functions like pre-defined and user-defined functions. It also covers function prototypes, parameters, return values, recursion, library functions and pointers.
Pointers,virtual functions and polymorphism cpprajshreemuthiah
This document discusses key concepts in object-oriented programming in C++ including polymorphism, pointers, pointers to objects and derived classes, virtual functions, and pure virtual functions. Polymorphism allows one name to have multiple forms through function and operator overloading as well as virtual functions. Pointers store the memory address of a variable rather than the data. Pointers can be used with objects, arrays, strings, and functions. Virtual functions allow calling a derived class version of a function through a base class pointer. Pure virtual functions define an abstract base class that cannot be instantiated.
The document discusses functions in C programming. It defines functions and explains their various parts like declaration, definition, and invocation. It also differentiates between function declaration and definition. Various types of functions are classified based on their inputs and outputs. The key differences between call by value and call by reference are explained with examples. Advantages of pass by reference are also mentioned.
There are two ways to initialize a structure:
1. Initialize structure members individually when declaring structure variables:
struct point {
int x;
int y;
} p1 = {1, 2};
2. Initialize an anonymous structure and assign it to a variable:
struct point p2 = {3, 4};
Structures allow grouping of related data types together under one name. They are useful for representing records, objects, and other data aggregates. Structures can contain nested structures as members. Arrays of structures are also possible. Structures provide data abstraction by allowing access to their members using dot operator.
Pointer is a variable that stores the address of another variable. Pointers allow indirect referencing of values and are useful for returning multiple values from functions, dynamic memory allocation, and building complex data structures like linked lists. Pointers are declared with a data type followed by an asterisk and are initialized with the address of another variable. The address-of operator & returns the address of its operand, while the indirection operator * accesses the value at the address stored in the pointer. Pointers can reference values indirectly, be passed by reference to functions to modify caller's variables, and implement call by reference parameter passing in C.
It tells about functions in C++,Types,Use,prototype,declaration,Arguments etc
function with
A function with no parameter and no return value
A function with parameter and no return value
A function with parameter and return value
A function without parameter and return value
Call by value and address
The document discusses C functions. Some key points:
1. Functions allow breaking code into reusable chunks that perform specific tasks. The main() function is required in every C program.
2. Functions are declared with a return type, name, and parameters. Definitions include the function body.
3. Standard library functions like strcat() and memcpy() are pre-defined for common tasks.
4. Functions are called by name and pass arguments by value or reference. Parameters allow customizing a function's behavior.
5. Recursion allows a function to call itself, enabling solutions to problems like factorials and Fibonacci sequences.
The document discusses functions in C programming. It defines what a function is and explains that functions can be used to break a large program into smaller modular pieces of code that can be reused. The key points covered include: defining functions with return types, parameters, and bodies; declaring functions; calling functions by passing arguments; and passing arguments by value vs reference. Examples are provided to demonstrate creating, calling, and passing arguments to functions. Recursion is also discussed as a special case where a function calls itself.
The document discusses functions in C programming. It covers:
- Functions allow dividing programs into reusable blocks of code. They can be called multiple times.
- Advantages include avoiding duplicating code, calling functions from anywhere, and improving readability. However, function calls require overhead.
- There are three aspects of a function: declaration, call, and definition. Declaration specifies the name, parameters, and return type. Definition contains the code.
- Functions can return values or not. They can accept arguments or not. Library functions are predefined, while user-defined functions are created by the programmer.
Functions allow programmers to organize and reuse code. There are two types of functions: library functions provided by C++ and user-defined functions created by the programmer. Functions communicate by passing arguments and returning values. Key concepts for functions include declaration, definition, call, pass by value, pass by reference, and pointers. Virtual functions allow for runtime polymorphism by calling the correct overridden function based on the object's type.
Functions allow programmers to organize C++ code into reusable blocks of statements. There are two types of functions: library functions provided in header files and user-defined functions created by the programmer. Functions communicate by passing arguments, which requires function declaration, definition, and calls. Pointers and references allow functions to modify argument values or share data. Virtual functions enable runtime polymorphism in inheritance hierarchies.
Hand Rolled Applicative User ValidationCode KataPhilip Schwarz
Could you use a simple piece of Scala validation code (granted, a very simplistic one too!) that you can rewrite, now and again, to refresh your basic understanding of Applicative operators <*>, <*, *>?
The goal is not to write perfect code showcasing validation, but rather, to provide a small, rough-and ready exercise to reinforce your muscle-memory.
Despite its grandiose-sounding title, this deck consists of just three slides showing the Scala 3 code to be rewritten whenever the details of the operators begin to fade away.
The code is my rough and ready translation of a Haskell user-validation program found in a book called Finding Success (and Failure) in Haskell - Fall in love with applicative functors.
What is Augmented Reality Image Trackingpavan998932
Augmented Reality (AR) Image Tracking is a technology that enables AR applications to recognize and track images in the real world, overlaying digital content onto them. This enhances the user's interaction with their environment by providing additional information and interactive elements directly tied to physical images.
SMS API Integration in Saudi Arabia| Best SMS API ServiceYara Milbes
Discover the benefits and implementation of SMS API integration in the UAE and Middle East. This comprehensive guide covers the importance of SMS messaging APIs, the advantages of bulk SMS APIs, and real-world case studies. Learn how CEQUENS, a leader in communication solutions, can help your business enhance customer engagement and streamline operations with innovative CPaaS, reliable SMS APIs, and omnichannel solutions, including WhatsApp Business. Perfect for businesses seeking to optimize their communication strategies in the digital age.
8 Best Automated Android App Testing Tool and Framework in 2024.pdfkalichargn70th171
Regarding mobile operating systems, two major players dominate our thoughts: Android and iPhone. With Android leading the market, software development companies are focused on delivering apps compatible with this OS. Ensuring an app's functionality across various Android devices, OS versions, and hardware specifications is critical, making Android app testing essential.
Using Query Store in Azure PostgreSQL to Understand Query PerformanceGrant Fritchey
Microsoft has added an excellent new extension in PostgreSQL on their Azure Platform. This session, presented at Posette 2024, covers what Query Store is and the types of information you can get out of it.
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemPeter Muessig
Learn about the latest innovations in and around OpenUI5/SAPUI5: UI5 Tooling, UI5 linter, UI5 Web Components, Web Components Integration, UI5 2.x, UI5 GenAI.
Recording:
https://www.youtube.com/live/MSdGLG2zLy8?si=INxBHTqkwHhxV5Ta&t=0
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeAftab Hussain
Understanding variable roles in code has been found to be helpful by students
in learning programming -- could variable roles help deep neural models in
performing coding tasks? We do an exploratory study.
- These are slides of the talk given at InteNSE'23: The 1st International Workshop on Interpretability and Robustness in Neural Software Engineering, co-located with the 45th International Conference on Software Engineering, ICSE 2023, Melbourne Australia
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesQuickdice ERP
Explore the seamless transition to e-invoicing with this comprehensive guide tailored for Saudi Arabian businesses. Navigate the process effortlessly with step-by-step instructions designed to streamline implementation and enhance efficiency.
Atelier - Innover avec l’IA Générative et les graphes de connaissancesNeo4j
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Allez au-delà du battage médiatique autour de l’IA et découvrez des techniques pratiques pour utiliser l’IA de manière responsable à travers les données de votre organisation. Explorez comment utiliser les graphes de connaissances pour augmenter la précision, la transparence et la capacité d’explication dans les systèmes d’IA générative. Vous partirez avec une expérience pratique combinant les relations entre les données et les LLM pour apporter du contexte spécifique à votre domaine et améliorer votre raisonnement.
Amenez votre ordinateur portable et nous vous guiderons sur la mise en place de votre propre pile d’IA générative, en vous fournissant des exemples pratiques et codés pour démarrer en quelques minutes.
Unveiling the Advantages of Agile Software Development.pdfbrainerhub1
Learn about Agile Software Development's advantages. Simplify your workflow to spur quicker innovation. Jump right in! We have also discussed the advantages.
Takashi Kobayashi and Hironori Washizaki, "SWEBOK Guide and Future of SE Education," First International Symposium on the Future of Software Engineering (FUSE), June 3-6, 2024, Okinawa, Japan
SOCRadar's Aviation Industry Q1 Incident Report is out now!
The aviation industry has always been a prime target for cybercriminals due to its critical infrastructure and high stakes. In the first quarter of 2024, the sector faced an alarming surge in cybersecurity threats, revealing its vulnerabilities and the relentless sophistication of cyber attackers.
SOCRadar’s Aviation Industry, Quarterly Incident Report, provides an in-depth analysis of these threats, detected and examined through our extensive monitoring of hacker forums, Telegram channels, and dark web platforms.
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppGoogle
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-fusion-buddy-review
AI Fusion Buddy Review: Key Features
✅Create Stunning AI App Suite Fully Powered By Google's Latest AI technology, Gemini
✅Use Gemini to Build high-converting Converting Sales Video Scripts, ad copies, Trending Articles, blogs, etc.100% unique!
✅Create Ultra-HD graphics with a single keyword or phrase that commands 10x eyeballs!
✅Fully automated AI articles bulk generation!
✅Auto-post or schedule stunning AI content across all your accounts at once—WordPress, Facebook, LinkedIn, Blogger, and more.
✅With one keyword or URL, generate complete websites, landing pages, and more…
✅Automatically create & sell AI content, graphics, websites, landing pages, & all that gets you paid non-stop 24*7.
✅Pre-built High-Converting 100+ website Templates and 2000+ graphic templates logos, banners, and thumbnail images in Trending Niches.
✅Say goodbye to wasting time logging into multiple Chat GPT & AI Apps once & for all!
✅Save over $5000 per year and kick out dependency on third parties completely!
✅Brand New App: Not available anywhere else!
✅ Beginner-friendly!
✅ZERO upfront cost or any extra expenses
✅Risk-Free: 30-Day Money-Back Guarantee!
✅Commercial License included!
See My Other Reviews Article:
(1) AI Genie Review: https://sumonreview.com/ai-genie-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
#AIFusionBuddyReview,
#AIFusionBuddyFeatures,
#AIFusionBuddyPricing,
#AIFusionBuddyProsandCons,
#AIFusionBuddyTutorial,
#AIFusionBuddyUserExperience
#AIFusionBuddyforBeginners,
#AIFusionBuddyBenefits,
#AIFusionBuddyComparison,
#AIFusionBuddyInstallation,
#AIFusionBuddyRefundPolicy,
#AIFusionBuddyDemo,
#AIFusionBuddyMaintenanceFees,
#AIFusionBuddyNewbieFriendly,
#WhatIsAIFusionBuddy?,
#HowDoesAIFusionBuddyWorks
Zoom is a comprehensive platform designed to connect individuals and teams efficiently. With its user-friendly interface and powerful features, Zoom has become a go-to solution for virtual communication and collaboration. It offers a range of tools, including virtual meetings, team chat, VoIP phone systems, online whiteboards, and AI companions, to streamline workflows and enhance productivity.
OpenMetadata Community Meeting - 5th June 2024OpenMetadata
The OpenMetadata Community Meeting was held on June 5th, 2024. In this meeting, we discussed about the data quality capabilities that are integrated with the Incident Manager, providing a complete solution to handle your data observability needs. Watch the end-to-end demo of the data quality features.
* How to run your own data quality framework
* What is the performance impact of running data quality frameworks
* How to run the test cases in your own ETL pipelines
* How the Incident Manager is integrated
* Get notified with alerts when test cases fail
Watch the meeting recording here - https://www.youtube.com/watch?v=UbNOje0kf6E
Software Engineering, Software Consulting, Tech Lead, Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Transaction, Spring MVC, OpenShift Cloud Platform, Kafka, REST, SOAP, LLD & HLD.
2. Function
10
School of ComputerEngineering
• The program becomes large and complex
• A lengthy program can be coded separately into
sub-programs called as Functions
• For repetition of certain part of code
3. FunctionDefinition
10
The general form of function definition statement in Cis as follows:
return_data_type function_name(data_type variable1,...) Function header
{
declarations;
statements;
return(expression);
}
function_name:
This is the name given to the function
it follows the same naming rules as that for any valid variable in C.
return_data_type:
This specifies the type of data given back to the calling construct by the function
after it executes its specific task.
Function Body
School of ComputerEngineering
4. calsum ( int x, int y,int z )
{
int d ;
d = x + y + z ;
return d ;
}
PassingValuesbetween Function
11
int main()
{
int a, b, c, sum;
printf ( "nEnter any three numbers " ) ;
scanf ( "%d %d %d", &a, &b, &c ) ;
sum = calsum ( a, b, c ) ;
printf ( "nSum = %d", sum ) ;
return 0;
}
School of ComputerEngineering
5. int calsum ( int x, int y,int z )
{
int d ;
d = x + y + z ;
return d ;
}
PassingValuesbetween Function
11
int main()
{
int a, b, c, sum;
printf ( "nEnter any three numbers " ) ;
scanf ( "%d %d %d", &a, &b, &c ) ;
sum = calsum ( a, b, c ) ;
printf ( "nSum = %d", sum ) ;
return 0;
}
School of ComputerEngineering
a, b, c are calledactual arguments
x, y and z are called formal
arguments
main is the calling function and
calsumis the calledfunction
7. Functionreturn statement
12
There is no restriction on the number of return statements that may be present in a
function. Also, the return statement need not always be present at the end of the called
function. The following program illustrates these facts.
int fun( )
{
char ch ;
printf ( "n Enter any alphabet " ) ;
scanf ( "%c", &ch ) ;
if ( ch >= 65 &&ch <= 90 )
return ( ch ) ;
else
return ( ch + 32 ) ;
}
School of ComputerEngineering
8. ScopeRuleof Functions
13
School of ComputerEngineering
display ( int j )
{
int k = 35 ;
printf ( "n%d", j ) ;
printf ( "n%d", k ) ;
}
int main( )
{
int i = 20 ;
display ( i ) ;
return 0;
}
In this program is it necessary to pass the value of
the variable i to the function display( )? Will it not
become automatically available to the function
display( )? No.Because by default the scope of a
variable is local to the function in which it is defined.
The presence of i is known only to the function
main( ) and not to any other function. Similarly, the
variable k is local to the function display( ) and
hence it is not available to main( ). That is why to
make the value of i available to display( ) we have to
explicitly pass it to display( ). Likewise, if we want k
to be available to main( ) we will have to return it to
main( ) using the return statement. In general we
can say that the scope of a variable is local to the
function in which it is defined.
9. FunctionCallby ValueandCallby Reference
14
Whenever we called a function and passed something to it we have always
passed the ‘values’ of variables to the called function. Such function calls are
called ‘calls by value’. By this what we mean is, on calling a function we are
passing values of variables to it. The examples of call by value are shown below:
sum=calsum( a,b,c) ;
We have also learnt that variables are stored somewhere in memory. So instead
of passing the value of a variable, can we not pass the location number (also
called address) of the variable to a function? If we were able to do so it would
become a ‘callbyreference’.
Arguments can generally be passed to functions in one of the two ways:
sending the values of the arguments
sending the addresses of the arguments
School of ComputerEngineering
10. FunctionCallby ValueandCallby Reference
15
swapByValue ( int x, int y )
{
int t ;
t = x ;
x = y ;
y = t ;
printf ( "nx = %d y = %d", x, y ) ;
}
int main( )
{
int a = 10, b = 20 ;
swapByValue( a, b );
printf ( "na = %d b = %d", a, b ) ;
return 0;
}
School of ComputerEngineering
Call by Value
}
swapByRef ( int *x,int*y )
{
int t ;
t = *x;
*x = *y ;
*y = t ;
printf ( "nx = %d y = %d", *x, *y ) ;
int main( )
{
int a = 10, b = 20 ;
swapByRef( &a, &b ) ;
printf ( "na = %d b = %d", a, b ) ;
return 0;
}
Call by Reference
11. Pointers
Storing Variable in Memory
School of ComputerEngineering
16
The value inside a box indicates
the value in that memory location.
The value under a box is the
memory address of that box.
12. Pointers
School of ComputerEngineering
16
When we declare a variable and initialize it,
int quantity = 179 ;
quantity variable
179 value
5000 address
Since memory address are simple
numbers they can be assigned to
some other variables
Pointers
13. Pointers
School of ComputerEngineering
16
• Pointer is an entity which contains memory address
• Pointers can be used to access data stored in memory
• There are two operators for pointers
• address operator ‘&’
• Dereference operator ‘*’ (value of operator)
15. Accessing Address of a Variable
School of ComputerEngineering
16
main( )
{
int i=3;
printf(“n Address of i = %u”,&i);
printf(“n Value of i = %d”,i);
}
OUTPUT :
Address of i = 6485
Value of i =3
16. Declaring pointer Variables
School of ComputerEngineering
16
The declaration is done as follows
data_type *pt_name;
* tells that pt_name is a pointer variable
pt_name needs memory location
pt_name points to a variable of type data_type
Remember data_type tells the type of data pointer will point to and not the
value of pt_name
Example
int *p;
float *x;
17. Initialization of pointer variables
School of ComputerEngineering
16
int quantity;
int *p; //declaration
p=&quantity; //initialization
int x, *p=&x; // all steps in one
// Assignment of NULL or 0 (zero)
int *p=NULL;
int *p=0;
// this is invalid, absolute address
int *p=5360;
18. Accessing Variable Through its
Pointer
School of ComputerEngineering
16
* operator known as
Indirection operator
Dereference operator
Example
int a,*p, n; //declaration
a=179; // variable assignment
p=&a; // pointer initialization
n=*p; //value at address operator
When * is placed at declaration it is used creating a pointer
* placed on right hand side of expression it returns the value at a
address. In this case it will return 179
19. Accessing Variable Through its
Pointer
School of ComputerEngineering
16
#include<stdio.h>
main()
{
int a=10;
int *ptr;
printf("a before = %d",a);
ptr=&a;
printf("nvalue of ptr = %u", ptr);
*ptr=85;
printf("nnew a is = %d",a);
getch();
}
22. Pointer Expression
School of ComputerEngineering
16
Following statements are valid
y=*p1 * *p2;
sum=sum+*p1;
z=5*(-(*p2))/ *p1;
Two pointers cannot be used for division or
multiplication
23. Pointer Increments and Scale Factors
School of ComputerEngineering
16
Pointers can be incremented like
p1=p1+2;
p1=p1+1;
Expression like
p1++
will cause pointer to next value of its type
24. Structure
Arrays allow to define type of variables that can hold several data items of the same kind. Similarly
structure is another user defined data type available in C that allows to combine data items of
different kinds.
Structuresare used to represent a record.Suppose you want to keep track of your books in a
library. You might want to track the following attributes about each book −
Title
Author
Subject
Book ID
School of ComputerEngineering
Defining the Structure:
struct [structuretag]
{
member definition;
member definition;
...
member definition;
}[one or more structure variables];
struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
}book;
Book Structure
/* Declare Book1 of type Book */
struct BooksBook1;
/* Declare Book2 of type Book */
struct BooksBook2;
Book1.title =“DSA”;
Book2.book_id =6495700;
AccessStructureElements
16
25. Union
Unions are quite similar to the structures in C. Union is also a derived type as
structure. Union can be defined in same manner as structures just the keyword
used in defining union in union where keyword used in defining structure was
struct.
You can define a union with many members, but only one member can contain a
value at any given time. Unions provide an efficient way of using the same
memorylocation for multiple-purpose.
School of ComputerEngineering
Defining the Union:
union [uniontag]
{
member definition;
member definition;
...
member definition;
}[one or more union variables];
union Data
{
int i;
float f;
char str[20];
}data;
Data Union
/* Declare Book1 of type Book */
struct Data data;
data.i =10;
data.f =34.72;
data.str =“CProgramming”
AccessUnionElements
17
26. Differenceb/w Structure& Union
Structure Union
Instructureeachmemberget separate spacein
memory.Takebelow example.
struct student
{
int rollno;
char
gender;
float marks;
} s1;
Thetotal memoryrequired to store a structure
variable isequal to the sumof sizeof all the
members.Inabove case7 bytes (2+1+4) will
be required to store structurevariable s1.
Inunion,the total memoryspaceallocated is
equal to the memberwith largest size.All other
memberssharethe samememoryspace.Thisis
the biggest difference between structureand
union.
union student
{
int rollno;
char
gender;
float marks;
}s1;
Inabove example variable marksisof float type
and have largest size(4 bytes). Sothe total
memoryrequired to store unionvariable s1is4
bytes.
School of ComputerEngineering
18
28. Differenceb/w Structure&Union cont…
Structure Union
We canaccessany memberin any sequence.
s1.rollno = 20;
s1.marks= 90.0;
printf(“%d”,s1.rollno);
We canaccessonly that variable whosevalue is
recently stored.
s1.rollno = 20;
s1.marks= 90.0;
printf(“%d”,s1.rollno);
The above code will show erroneous output. The
value of rollno is lost as most recently we have
stored value in marks. This is because all the
memberssharesamememoryspace.
All the members can be initialized
while declaring the variable of structure.
Only first member can be initialized while
declaring the variable of union. In above
example, we can initialize only variable rollno at
the time of declaration of variable.
School of ComputerEngineering
20
29. Pointers
int i = 10;
What thedeclaration tells theC compiler?
Reserve space in memory to hold the integer value
Associate the name i with this memory location
Store the value 10 at this location
Memory Map
10
i
XXXXX (e.g.6458)
LocationName
School of ComputerEngineering
Value at Location
LocationNumber
Code Snippet
#include<stdio.h>
intmain()
{
intintVariable=10;
printf(“AddressofintVariable=%u”,&intVariable);
printf(“ValueofintVariable=%d”, intVariable);
return0;
}
Apointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any
variable or constant, you must declare a pointer before using it to store any variable address. The general form of a pointer
variable declaration is− type *var-name;
21
31. Pointerscont…NULLPointers
It is always a good practice to assign a NULLvalue to a pointer variable in case you do not have an exact address to be
assigned. This is done at the time of variable declaration. Apointer that is assigned NULLis called a null pointer.
The NULLpointer is a constant with a value of zero defined in several standard libraries.
School of ComputerEngineering
Code Snippet
#include<stdio.h>
intmain()
{
int*ptr =NULL;
printf("Thevalue ofptr is :%un", ptr );
return 0;
}
Null Pointer Checking
1. if (ptr == null) or if (ptr <> null)
2. If (ptr) or if ( !ptr)
Commonlydonemistakes
int c,*pc;
pc=c; /* pc is address whereas, c is not an address. */
*pc=&c; /* &c is address whereas, *pc is not an address. */
23
32. DynamicMemory Allocation
24
The exact size of array is unknown until the compile time i.e. time when a compiler compiles code
written in a programming language into a executable form. The size of array you have declared
initially can be sometimes insufficientandsometimes morethanrequired.
School of ComputerEngineering
What?
The process of allocating memory during program execution is called dynamic memory allocation. It
also allows a program to obtain more memory space, while running or to release space when no
space is required.
Differencebetweenstatic anddynamic memoryallocation
Sr # Static Memory Allocation Dynamic Memory Allocation
1 User requested memory will be allocated
at compile time that sometimes insufficient
and sometimesmorethan required.
Memory isallocated while executing the
program.
2 Memory sizecan‟tbe modified while
execution.
Memory sizecanbe modified while
execution.
33. DynamicMemoryAllocation cont…
Functionsavailable in Cfor memory management
School of ComputerEngineering
Sr # Function Description
1 void *calloc(int num,int size) Allocates anarray of numelementseach of whichsize
in bytes will be size.
2 void free(void *address) Releasesa block of memoryblock specified by address.
3 void *malloc(int num) Allocates anarray of numbytes and leave them
initialized.
4 void *realloc(void *address,
int newsize)
Re-allocates memoryextending it upto new size.
25
34. DynamicMemoryAllocation Example
pi=(int *) malloc(sizeof(int));
pj=(float*) malloc(sizeof(float));
free(pi);
free(pj);
#include<stdio.h>
#include<stdlib.h>
int main()
{
int*pi;
float*pj;
*pi =10;
*pj =3.56;
printf(“integer=%d, float=%f”,*pi,*pj);
return 0;
}
if(!pi|| !pj)
{
printf(“Insufficient Memory”);
return;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int*pi;
float *pj;
pi=(int*)malloc(sizeof(int));
pj=(float*)malloc(sizeof(float));
*pi =10;
*pj=3.56;
printf(“integer=%d, float=%f”,*pi,*pj);
free(pi);
free(pj);
return0;
}
I
M
H
School of ComputerEngineering
IMH : Insufficient Memory Handling
26
35. DMAreallocExample
#include <stdio.h>
#include <stdlib.h>
int main()
{
School of ComputerEngineering
char *mem_allocation;
/* memory is allocated dynamically */
mem_allocation = malloc( 20 *sizeof(char));
if( mem_allocation== NULL )
{
printf("Couldn't able to allocaterequested memoryn"); return;
}
else
{
strcpy( mem_allocation,“dynamic memory allocationfor realloc function");
}
printf("Dynamically allocatedmemory content : %sn", mem_allocation );
mem_allocation=realloc(mem_allocation,100*sizeof(char));
if( mem_allocation== NULL )
{
printf("Couldn't able to allocaterequested memoryn");
}
else
{
strcpy( mem_allocation,"spaceis extended upto 100 characters");
}
printf("Resizedmemory : %sn", mem_allocation );
free(mem_allocation);
return 0;
}
CProgram illustrating the usage of realloc
27
36. Differencebetweencallocand malloc
Sr # malloc calloc
1 It allocates only single block of
requested memory
It allocates multiple blocks of
requested memory
2 doesn‟tinitializes the allocated
memory.It containsgarbage values.
initializes the allocated memoryto
zero
3 int *ptr;
ptr = malloc( 20 * sizeof(int));
Forthe above, 20*2 bytes of
memoryonly allocated inoneblock.
Total= 40 bytes
int *ptr;
Ptr = calloc( 20, 20 * sizeof(int));
Forthe above, 20 blocksof memory
will be created and eachcontains
20*2 bytes of memory.
Total= 800 bytes
School of ComputerEngineering
28
37. Algorithm Specification
29
An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In
addition, all algorithms must satisfy the following criteria:
1. Input.There are zero or more quantities that are externally supplied.
2. Output.At least one quantity isproduced.
3. Definiteness.Each instruction is clear and unambiguous.
4. Finiteness.If we trace out the instructions of an algorithm, then for all cases, the algorithm
terminates after a finite number of steps.
5. Effectiveness. Every instruction must be basic enough to be carried out, in principle, by a
person using only pencil and paper. It is not enough that each operation be definite as in (3); it
also must befeasible.
Differencebetweenanalgorithm&program– program does not have to satisfy the 4th condition.
School of ComputerEngineering
Describing Algorithm
1. NaturalLanguage–e.g. English, Chinese - Instructions must be definite and effectiveness.
2. Graphicsrepresentation–e.g.Flowchart- work well only if the algorithm is small and simple.
3. PseudoLanguage -
• Readable
• Instructions must be definite and effectiveness
4. CombiningEnglishand C
38. AlgorithmSpecification cont…
DescribingAlgorithm – Natural Language
Problem- Design an algorithm to add two
numbers anddisplay result.
Step 1 −START
Step 2 − declare three integers a, b &c
Step 3 − define values of a &b
Step 4 − add values of a &b
Step 5 − store output of step 4 to c
Step 6− print c
Step 7 −STOP
School of ComputerEngineering
Note - Writing step numbers, is
optional.
Problem - Design an algorithm find the
largest data value of a set of given positive
data values
Step 1 −START
Step 2 − input NUM
Step 3 –LARGE= NUM
Step 4− While (NUM >=0)
if (NUM > LARGE)then
LARGE= NUM
input NUM
Step 5 – display “Largest Value is:”, LARGE
Step 6 −STOP
30
39. AlgorithmSpecification cont…
DescribingAlgorithm – Flowchart
Problem–Write an algorithm to determine a student’s final grade and indicate whether it is passing of failing.
The final grade is calculated as the average of five marks.
Start
Input
M1 to M5
Grade = (M1 + M2 + M3 + M4 + M5) / 5
IsGrade < 4.0
Print “Pass”
Print “Fail”
Stop
31
School of ComputerEngineering
40. PseudoLanguage
32
The Pseudo language is neither an algorithm nor a program. It is an abstract form of a program. It consists of
English like statements which perform the specific operations. It employs programming-like statements to
depict the algorithm and no standard format (language independent) is followed. The statements are carried out
in a order &followings are the commonly used statements.
School of ComputerEngineering
Statement Purpose General Format
Input Get Information INPUT: Nameof variable
e.g. INPUT:user_name
Process Performanatomic activity Variable arithmetic expression
e.g. x 2 or x x + 1 or a b * c
Decision Choosebetweendifferent alternatives
IF(condition ismet)then
statement(s)
ENDIF
IF(condition ismet)THEN
statement(s)
ELSE
statements
(s) ENDIF
e.g.
IF(amount< 100) THEN
interestRate .06
ENDIF
e.g.
IF(amount< 100) THEN
interestRate .06
ELSE
interestRate .10
ENDIF
41. PseudoLanguage cont…
33
School of ComputerEngineering
Statement Purpose General Format
Repetition Performa stepmultiple times REPEAT
statement(s)
UNTIL (conditionis met)
WHILE (conditionismet)
statement(s)
ENDWHILE
e.g.
count 0
REPEAT
ADD1 to count
OUTPUT:count
UNTIL(count < 10)
OUTPUT:“TheEnd”
e.g.
count 0
WHILE(count< 10)
ADD1 to count
OUTPUT: count
ENDWHILE
OUTPUT:“TheEnd”
Output Display information OUTPUT: Nameof variable
e.g. OUTPUT: user_name
OUTPUT: message
OUTPUT:„Credit Limit‟limit
42. PseudoLanguage Guidelines
Guidelines Explanation
Write only onestatementper line Eachstatementinpseudocodeshouldexpressjustoneactionfor thecomputer.If thetasklist isproperly
drawn, thenin mostcaseseachtask will correspondto oneline of pseudocode.
Task List Pseudo code
Readname,hours worked, rate of pay INPUT:name,hoursWorked,payRate
gross= hoursworked * rate of pay gross hoursWorked* payRate
Write name, hoursworked, gross OUTPUT:name,hoursWorked,gross
Capitalize initial keyword Intheexample above notethewords:INPUT and OUTPUT. Theseare justa few of thekeywordsto use,
othersinclude:IF, ELSE,REPEAT, WHILE, UNTIL, ENDIF
Indentto show hierarchy Eachdesignstructure usesa particular indentation pattern.
Sequence - Keepstatementsinsequenceall starting in the samecolumn
Selection - Indentstatementsthat fall insideselectionstructure,but notthekeywordsthat form the
selection
Loop - Indentstatementsthat fall insidetheloop but notkeywordsthat form theloop
INPUT:name,grossPay,taxes
IF(taxes > 0)
net grossPay– taxes
ELSE
net grossPay
ENDIF
OUTPUT:name,net
School of ComputerEngineering
34
43. PseudocodeGuidelines cont…
35
School of ComputerEngineering
Guidelines Explanation
Endmultilinestructures INPUT:name,grossPay,taxes
IF(taxes > 0)
net grossPay– taxes
ELSE
net grossPay
ENDIF
OUTPUT:name,net
WatchtheIF/ELSE/ENDIFasconstructedabove,theENDIFisin line with theIF.Thesameapplies for
WHILE/ENDWHILEetc…
Keepstatementslanguage
independent
Resisttheurge to write inwhatever language youare mostcomfortable with, inthelong runyouwill save
time.Rememberyouare describinga logic plan to develop a program, youare not programming!
44. PseudoLanguage Example
36
1. Problem- Design the pseudo code to add two numbers and display the average.
INPUT: x, y
sum x + y
average sum / 2
OUTPUT: ‘Average is:’average
2. Problem- Design the pseudo code to calculate &display the area of a circle
INPUT: radius
area 3.14 *radius *radius
OUTPUT: ‘Area of the circle is ‘area
2. Problem- Design the pseudo code to calculate &display the largest among 2 numbers
INPUT: num1, num2
max num1
IF (num2 > num 1) THEN
max num2
ENDIF
OUTPUT: ‘Largest among 2 numbers is’max
School of ComputerEngineering
45. AlgorithmSpecification cont…
Example- Translatinga Probleminto anAlgorithm – CombiningEnglishandC
School of ComputerEngineering
Problem - Devise a program that sorts a set of n>= 1 integers
Step I – Concept– looks good but not an algorithm
From those integers that are currently unsorted, find the smallest and place it next in the sorted list – selection sort
Step II – An algorithm,written in Cand English
for (i= 0; i< n; i++)
{
Examine list[i] to list[n-1] and suppose that the smallest integer is list[min];
Interchange list[i] and list[min];
}
Optional Step III – Coding– translating the algorithm to Cprogram
void sort(int *a, int n) {
for (i= 0; i< n; i++) {
int j=i;
for (int k= i+1; k< n; k++) {
if (a[k]< a[j]) {
j = k; int temp=a[i]; a[i]=a[j]; a[j]=temp;
}
}
}
}
37
46. AlgorithmSpecification cont…
Translatinga Probleminto anAlgorithm cont… Correctness Proof
Theorem
Function sort(a, n) correctly sorts a set of n>= 1 integers. The result
remains in a[0], ..., a[n-1] such that a[0]<= a[1]<=...<=a[n-1].
Proof
For i= q, following the execution of lines, we have a[q]<= a[r], q< r< =n-1.
For i> q, observing, a[0], ..., a[q] are unchanged.
Hence, increasing i, for i= n-2, we have a[0]<= a[1]<= ...<=a[n-1]
School of ComputerEngineering
38
47. RecursiveAlgorithm
A recursive algorithm is an algorithm which calls itself. In general, recursive computer
programs require more memory and computation compared with iterative algorithms, but
they are simpler and for many cases a natural way of thinking about the problem. There
are 2 types of recursive functions.
School of ComputerEngineering
Directrecursion Function Indirectrecursion Function
Functions call themselves e.g. function α
calls α
Functions call other functions that invoke the calling
function again e.g. a function α calls a function β that in
turn calls the original function α.
Example–
int fibo (int n)
{
if (n==1 || n==2)
return 1;
else
return (fibo(n-1)+fibo(n-2));
}
Example–
int func1(int n)
{
if (n<=1)
return 1;
else
return func2(n);
}
int func2(int n)
{
return func1(n);
}
39
48. RecursiveAlgorithm cont…
When is recursionanappropriatemechanism?
The problem itself is defined recursively
Statements: if-else and while can be written recursively
Art of programming
Whyrecursivealgorithms ?
Powerful, express an complex process very clearly
Properties - Arecursive function can go infinite like a loop. To avoid infinite running of
recursive function, there are two properties that a recursive function must have −
Basecriteria− There must be at least one base criteria or condition, such that,
when this condition is met the function stops calling itself recursively.
Progressivecriteria− The recursive calls should progress in such a way that each
time a recursive call is made it comes closer to the base criteria.
Implementation- Many programming languages implement recursion by means of
stack.
School of ComputerEngineering
40
49. RecursiveImplementationof Fibonacci
#include<stdio.h>
void Fibonacci(int);
int main()
{
int k,n;
long int i=0,j=1,f;
printf("Enter the range of the Fibonacci series: ");
scanf("%d",&n);
printf("Fibonacci Series: ");
printf("%d %d ",0,1);
Fibonacci(n);
return 0;
}
//continuation ofprogram
void Fibonacci(int n)
{
static long intfirst=0,second=1,sum;
if(n>0)
{
}
}
Base Criteria
School of ComputerEngineering
sum = first+ second;
first = second;
second = sum;
printf("%ld ",sum);
Fibonacci(n-1); Progressive Criteria
41
50. AlgorithmAnalysis
We design an algorithm to get solution of a given problem. Aproblem can be
solved in more than one ways.
Hence, many solution algorithms can be derived for a given problem. Next step
is to analyze those proposed solution algorithms and implement the best
suitable.
School of ComputerEngineering
42
51. AlgorithmAnalysis cont…
stages, before
A priori analysis − This is theoretical analysis of an algorithm. Efficiency of
algorithm is measured by assuming that all other factors e.g. processor speed,
are constant and have no effect on implementation.
A posterior analysis − This is empirical analysis (by means of direct and
indirect observation or experience) of an algorithm. The selected algorithm is
implemented using programming language. This is then executed on target
computer machine. In this analysis, actual statistics like running time and space
required and arecollected.
Focus
School of ComputerEngineering
43
Efficiency of an algorithm can be analyzed at two different
implementation and after implementation, as mentioned below −
Apriori analysis
52. Algorithm Complexity
Suppose X is an algorithm and n is the size of input data, the time and
space used by the Algorithm Xare the two main factors which decide the
efficiency of X.
TimeFactor−The time is measured by counting the number of key
operations such as comparisons in sorting algorithm
SpaceFactor−The space is measured by counting the maximum
memory space required by the algorithm.
The complexity of an algorithm f(n) gives the running time and / or
storage space required by the algorithm in terms of n as the size of input
data.
School of ComputerEngineering
44
53. SpaceComplexity
45
Space complexity of an algorithm represents the amount of memory space required by the
algorithm in its life cycle. Space required by an algorithm is equal to the sum of the following two
components −
Afixed part that is a space required to store certain data and variables, that are independent of
the size of the problem. For example simple variables &constant used, program size etc.
Avariable part is a space required by variables, whose size depends on the size of the problem.
For example dynamic memory allocation, recursion stack space etc.
Space complexity SC(P) of any algorithm P is SC(P) = FP + VP (I) where FP is the fixed part and
VP(I) is the variable part of the algorithm which depends on instance characteristic I. Following is a
simple example that tries to explain the concept −
Algorithm: SUM(A,B)
Step 1 - START
Step 2 - C←A+ B+10
3 variables and data type of each variable is int, So VP(3)
= 3*2 = 6 bytes (No. of characteristic i.e. I = 3)
1 constant (i.e. 10) and it is int, so FP = 1*2 = 2 bytes
Step 3 - Stop So - SC(SUM) = FP + VP(3) = 2 + 6 = 8 bytes
School of ComputerEngineering
54. SpaceComplexity cont…
Example 1
int square(int a)
{
return a*a;
}
In above piece of code, it requires 2 bytes of
memory to store variable 'a' and another 2
bytes of memory is used for return value.
That means, totally it requires 4 bytes of
memory to complete its execution. And this
4 bytes of memory is fixed for any input
value of 'a'. This space complexity is said to
be ConstantSpaceComplexity.
If any algorithm requires a fixed amount of
space for all input values then that space
complexity is said to be Constant Space
said to be Linear Space Complexity
Complexity
School of ComputerEngineering
Example 2
int sum(int a[], int n)
{
}
int sum= 0, i;
for(i = 0; i < n; i++) {sum = sum +A[i];}
return sum;
In above piece of code it requires -
• 2*n bytes of memory to store array variable ‘a[]’
• 2 bytes of memory for integer parameter 'n‘
• 4 bytes of memory for local integer variables 'sum'
and 'i' (2 bytes each)
• 2 bytes of memory for return value.
That means, totally it requires '2n+8' bytes of memory to
complete its execution. Here, the amount of memory depends
on the input value of 'n'. This space complexity is said to be
LinearSpace Complexity.
If the amount of space required by an algorithm is increased
with the increase of input value, then that space complexity is
46
55. TimeComplexity
Time Complexity of an algorithm represents the amount of time required by the
algorithm to run to completion. Time requirements can be defined as a numerical
function T(n), where T(n) can be measured as number of steps * time taken by
each steps
For example, addition of two n-bit integers takes n steps. Consequently, the total
computational time is T(n) = c*n, where c is the time taken for addition of two bits.
Here, we observe that T(n) grows linearly as input size increases.
considered constant.
School of ComputerEngineering
to defining the mathematical
Asymptotic analysis
Asymptotic analysis of an algorithm, refers
foundation/framing of its run-timeperformance.
Asymptotic analysis are input bound i.e., if there's no input to the algorithm it is
concluded to work in a constant time. Other than the "input" all other factors are
47
56. TimeComplexitycont…Asymptotic analysis
Asymptoticanalysisrefers to computing the running time of any
operation in mathematical units of computation.
For example,
- Running time of one operation is computed as f(n)
- May be for another operation it is computed as g(n2)
Usually, time required by an algorithm falls under three types –
BestCase− Minimum time required for program execution.
Average Case− Average time required for program execution.
WorstCase− Maximum time required for program execution.
School of ComputerEngineering
48
57. TimeComplexitycont…Best,AverageandWorst
Caseexamples
BestCase − The 1st item of the array equals to k
AverageCase− Match at n/2
WorstCase − The last position of the array equals to k
Example1: Travelfrom KanyakumaritoSrinagar
WorstCase− Yougo to Ahemdabad and then you take a east go to
Guhwati and then again take a west and go to Srinagar.
AverageCase − You go normal route highways only to reach there.
Best Case − Take every short cut possible leave the national
highway if you need to take state highway, district road if you need to
but you have to get to Srinagar with least possible distance
Example2: Sequential Searchfor k in anarray of nintegers
School of ComputerEngineering
49
58. TimeComplexitycont…Asymptotic Notations
Following are commonly used asymptotic notations used in calculating running
time complexity of an algorithm.
Ο Notation – “Big Oh” - The Ο(n) is the formal way to express the upper
bound of an algorithm's running time. It measures the worst case time
complexity or longest amount of time an algorithm can possibly take to
complete.
Ω Notation – “Omega” - The Ω(n) is the formal way to express the lower
bound of an algorithm's running time. It measures the best case time
complexityor best amountof time an algorithm can possibly take to complete.
θ Notation –“Theta” - The θ(n) is the formal way to express both the lower
boundandupperboundof an algorithm's running time.
School of ComputerEngineering
50
59. TimeComplexitycont…AsymptoticNotations cont…
Time-SpaceTradeOff
School of ComputerEngineering
The best algorithm to solve a given problem is one that requires less space in memory and takes less time
to complete its execution. But in practice it is not always possible to achieve both these objectives. As we
know there may be more than one approach to solve a particular problem. One approach may take more
space but takes less time to complete its execution while the other approach may take less space but takes
more time to complete its execution. We may have to sacrifice one at the cost of the other. If space is our
constraint, then we have to choose a program that requires less space at the cost of more execution time.
On the other hand if time is our constraint then we have to choose a program that takes less time to
complete its execution at the cost of more space.
Sr # Algorithm Time Complexity
Best Average Worst
1 Bubble Sort Ω(n) Θ(n2) O(n2)
2 Insertion Sort Ω(n2) Θ(n2) O(n2)
3 Quick Sort Ω(n log n) Θ(n log n) O(n2)
4 Merge Sort Ω(n log n) Θ(n log n) O(n log n)
5 Heap Sort Ω(n log n) Θ(n log n) O(n2)
51
60. TimeComplexityRules
52
Time complexity of a function (or set of statements) is considered as O(1) if it
doesn’t contain loop, recursion and call to any other non-constant time
function. Example:
void swap(int *x, int*y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
Time complexity of swap function= Total number of simple statements = 4 =
constant =O(1)
Note-
ConstantTime- algorithm runs in a fixed amount of time, it just means that it isn't proportional to the length/size/magnitude of the
input. i.e., for any input, it can be computed in the same amount of time (even if that amount of time is really long).
School of ComputerEngineering
61. TimeComplexityRulesfor Loops
Aloop or recursion that runs a constant number of times is also considered as
O(1). Example-
int i;
for (i = 1; i <= c; i++) / / c is a constant
{
/ / some O(1) expressions
}
Time Complexity of a loop is considered as O(n)if the loop variables i is
incremented / decremented by a constant amount c. Example-
for (i = 1; i <= n; i = i+c)
{
/ / some O(1) expressions
}
School of ComputerEngineering
53
62. TimeComplexityRulesforLoops cont…
Time Complexity of a loop is considered as O(logn)if the loop variables i is
multiplied or divided by a constant amount c. Example-
for (i = 1; i <= n; i=i*c)
{
/ / some O(1) expressions
}
Time Complexity of a loop is considered as O(log log n) if the loop variables i
if the loop variables is reduced / increased exponentially by a constant
amount c. Example-
School of ComputerEngineering
Example 1 Example 2
Here cisa constantgreater than1
for (i = 2; i <= n;i=pow(i,c))
{
/ / someO(1)expressions
}
//Here funissqrt or cuberoot or any other constantroot
for (i = n;i > 0; i = fun(i))
{
/ / someO(1)expressions
}
54
63. Time complexity of nested loops is equal to the number of times the innermost
statement is executed that is nothing but the multiplication of outer loop complexity
into inner loop complexity.
School of ComputerEngineering
Sr # Program Segment Time Complexity Explanation
1 int i, j, k;
for (i = 1; i <=m; i ++)
{
for (j = 1; j <=n; j ++)
{
k=k+1;
}
}
O(m*n)
If m= n,thenO(n2)
Outer for mtimesand inner for n
times,sototal m*n times
2 int i, j, k;
for (i = n;i >1; i =i-2)
{
for (j = 1; j <=n; j=j+3)
{
k=k+1;
}
}
O(n2) Outer loop approx n times and
inner approx n times, so total n2
times.
TimeComplexityRulesforLoops cont…
55
64. Sr # Program Segment Time Complexity Explanation
3 int i, j, k;
for (i = n;i >1; i =i*2)
{
for (j = 1; j <=n; j++)
{
k=k+1;
}
}
O(nlog n) Outer loop approx log ntimes,inner
loop ntimes,sototal nlog ntimes.
4 int i, j, k;
for (i = 1; i<=n; i=i*2)
{
for (j =n; j>=1; j=j/2)
{
k= k +1;
}
}
O((log n)2) Outer loop approx log ntimesand
innerloop approx log ntimes,sototal
((log n)2times.
School of ComputerEngineering
TimeComplexityRulesforLoops cont…
56
65. Sr # Program Segment Time Complexity Explanation
1 for (int i = 1; i <=m; i += c)
{
/ / someO(1)expressions
}
for (int i = 1; i <=n; i += c)
{
/ / someO(1)expressions
}
O(m+n)
If m=n, then
O(2n)=O(n
)
Firstfor outer i loop O(m),secondfor
inneri loop O(n)times,sototal
O(m+n) times
School of ComputerEngineering
Sr # Program Segment Time Complexity Explanation
5 for (i = 1; i<=n; i++)
{
for (j =1; j<=100; j++)
{
Simple-Statements;
}
}
O(n) Theouter loop executesapprox. n
times,and theinnermost100 times.
Here n=O(n) and 100=O(1) constant
time.Sototal = O(n)*O(1) = O(n)
When there are consecutive loops, the time complexity is calculated as sum of time
complexities of individual loops and final time complexity is the higher order term in
terms of n (the one which is larger than others for larger value of n)
TimeComplexityRulesforLoops cont…
57
66. Sr # Program Segment Time Complexity Explanation
2 for (int i = 1; i <=n; i *= 2)
{
/ / someO(1)expressions
}
for (int i = 1; i <=n; i ++)
{
/ / someO(1)expressions
}
O(n) First for outer i log n times, second inner i it
is n times. Now total=log n + n = O(n) as n
isasymptotically larger thanlog n.
3 int i, j, k,l;
for (i = 1; i <=n; i ++)
{
for (j = 1; j <=n; j=j*2) {p=i+j;}
}
for (k= n;k>=1; k=k/3)
{ q=k+p; }
for (l = n;l >=1; l=l-2)
{ q=k+p; }
O(nlog n) Nestedfor-ij loop isexecuted nlog
ntimes.kloop log ntimes,l loop
ntimes.Sototal= nlog n+ log n+ n=
O(nlog n)asnlog n> n> logn
School of ComputerEngineering
TimeComplexityRulesforLoops cont…
1<logn< n<n<nlogn<n2<n3<....<2n<3n<...<nn
58
67. TimeComplexityRulesfor Recursion
Sr # Program Segment Time Complexity Explanation
1 Factorial of a number
int Factorial (int n)
{
if n== 0 then
return 0;
else
return n* Factorial(n – 1)
}
O(n) comparison,multiplication and subtraction
are simplestatementsand eachtakes1
unitof time.SoT(n)= T(n-1)+ 3 if n> 0
T(0)= 1 if n= 0
SoT(n)= T(n-1)+ 3
= T(n-2)+ 6
= T(n-k)+ 3k
Whenk= n,T(n)= T(0)+ 3n
= 3n+ 1
SoT(n)= O(n)
2 Fibonacci Sequence
int Fib(int n)
{
if n<= 1then
return1;
else
return Fib(n-1)+ Fib (n–2)
}
?? ??
School of ComputerEngineering
59
68. Sr # Program Segment Space
Complexit
y
Explanation
1 int sum(intx, int y, int z)
{
int r = x + y + z;
return r;
}
O(1) requires 3 unitsof spacefor theparameters
and 1 for thelocal variable, and thisnever
changes,sothisisO(1).
2 int sum(inta[], int n){
int r = 0;
for (int i = 0; i < n;++i) {
r += a[i];
}
return r;
}
O(n) requires nunitsfor a, plusspacefor n,r and
i, soit's O(n).
3 void matrixAdd(int a[], int b[], int c[], int n){
for (int i = 0; i < n;++i) {
c[i] = a[i] + b[j]
}
}
O(n) requires nunitsfor a, b and cplusspacefor
n,and i, soit'sO(n).
School of ComputerEngineering
SpaceComplexity Rules
60
73. Assignments
1. Find the time complexity of the following code segment
for (i = 1; i <= n; i = i*2)
{
for (j = n; j >= 1; j = j/2) {some statement }
}
for (j= c; j > 0; j--) / / consider c as const
{
some statement
}
for (i = n; i <= 1; i = i/c) / / consider c as const
{
/ / some statement
}
2. Write an recursive algorithm to print from 1 to n (where n > 1)
3. Write an recursive algorithm to find the kth smallest element of a set S
4. Write an recursive algorithm to sum the list of numbers
63
School of ComputerEngineering
74. 5. Find the space complexity of the following code segment
int Factorial (int n)
{
if n== 0 then
return 0;
else
return n *Factorial(n – 1)
}
6. Find the time and space complexity of the following code segment
int Fib(intn)
{
if n <= 1then
return 1;
else
return Fib(n-1) + Fib (n – 2)
}
64
Assignments
School of ComputerEngineering
75. HomeWork(HW)
Find the time and space complexity of the following code segment
int GCD(int x, inty)
{
if y == 0 then
return x
else if x >= y ANDy > 0
return GCD(y, x % y)
else
return 0;
}
65
School of ComputerEngineering
76. HomeWork(HW)
Find the time and space complexity of the following code segment
void matrixAddition(int a[][], int b[][], int c[][], int n)
{
int i,j;
for (i = 0; i < n; ++i)
{
for (j = 0; j < n; ++j)
{
c[i][j] = a[i][j] +b[i][j];
}
}
}
66
School of ComputerEngineering
77. SupplementaryReading
Watch thefollowing video
https://www.youtube.com/watch?v=8syQKTdgdzc
https://www.youtube.com/watch?v=AL7yO-I5kFU
http://nptel.ac.in/courses/106102064/1
Read the following
https://www.tutorialspoint.com/data_structures_algorithms/
67
School of ComputerEngineering
78. F
AQ
What is Information - If we arrange some data in an appropriate sequence,
then it forms a Structure and gives us a meaning. This meaning is called
Information . The basic unit of Information in Computer Science is a bit,
Binary Digit. So, we found two things in Information: One is Data and the
other isStructure.
Whatis Data Structure?
1. Adata structure is a systematic way of organizing and accessing data.
2. Adata structure tries to structure data!
Usually more than one piece of data
Should define legal operations on the data
The data might be grouped together (e.g. in an linked list)
3. When we define a data structure we are in fact creating a new data type
of our own.
i.e. using predefined types or previously user defined types.
Such new types are then used to reference variables type within a
program
68
School of ComputerEngineering
79. FAQcont…
WhyData Structures?
1. Data structures study how data are stored in a computer so that
operations can be implemented efficiently
2. Data structures are especially important when you have a large amount of
information
3. Conceptual and concrete ways to organize data for efficient storage and
manipulation.
ADT
1. Abstract Data Types (ADT's) are a model used to understand the design of
a data structure
2. 'Abstract' implies that we give an implementation-independent view of the
data structure
3. ADTsspecify the type of data stored and the operations that support the
data
4. Viewing a data structure as an ADTallows a programmer to focus on an
idealized model of the data and its operations
69
School of ComputerEngineering
80. FAQcont…
Time Complexity of algorithm - Time complexity of an algorithm signifies
the total time required by the program to run till its completion. The time
complexity of algorithms is most commonly expressed using the big O
notation. Time Complexity is most commonly estimated by counting the
number of elementary functions performed by the algorithm. And since the
algorithm's performance may vary with different types of input data, hence
for an algorithm we usually use the worst-case Time complexity of an
algorithm because that is the maximum time taken for any input size.
Types ofNotationsforTime Complexity
1. Big Oh denotes "fewer than or the same as" <expression> iterations.
2. Big Omega denotes "more than or the same as" <expression> iterations.
3. Big Theta denotes "the same as" <expression> iterations.
4. Little Oh denotes "fewer than" <expression> iterations.
5. Little Omega denotes "more than" <expression> iterations. idealized
model of the data and its operations
70
School of ComputerEngineering