PPS 5.5.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.), BASIC SORTING ALGORITHMS (BUBBLE, INSERTION AND SELECTION), FINDING ROOTS OF EQUATIONS, NOTION OF ORDER OF COMPLEXITY THROUGH EXAMPLE PROGRAMS (NO FORMAL DEFINITION REQUIRED)
BASIC ALGORITHMS
SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.), BASIC SORTING ALGORITHMS (BUBBLE, INSERTION AND SELECTION), FINDING ROOTS OF EQUATIONS, NOTION OF ORDER OF COMPLEXITY THROUGH EXAMPLE PROGRAMS (NO FORMAL DEFINITION REQUIRED)
FUNCTION
INTRODUCTION & WRITING FUNCTIONS, SCOPE OF VARIABLES FUNCTIONS (INCLUDING USING BUILT IN LIBRARIES), PARAMETER PASSING IN FUNCTIONS, CALL BY VALUE, PASSING ARRAYS TO FUNCTIONS: IDEA OF CALL BY REFERENCE
This document contains some programs of C using Data structures, like Stack, LinkedList, queue, Fibonacci series, addition and multiplication of two matrices,etc.
INTRODUCTION TO COMPONENTS OF A COMPUTER SYSTEM (DISKS, MEMORY, PROCESSOR, WHERE A PROGRAM IS STORED AND EXECUTED, OPERATING SYSTEM, COMPILERS ETC). IDEA OF ALGORITHM: STEPS TO SOLVE LOGICAL AND NUMERICAL PROBLEMS. REPRESENTATION OF ALGORITHM: FLOWCHART/PSEUDO CODE WITH EXAMPLES. FROM ALGORITHMS TO PROGRAMS; SOURCE CODE, VARIABLES (WITH DATA TYPES) VARIABLES AND MEMORY LOCATIONS, TYPE CASTING/TYPE CONVERSION, RUN TIME ENVIRONMENT (STATIC, DYNAMIC LOCATION), STORAGE CLASSES (AUTO, REGISTER, STATIC, EXTERN), SYNTAX AND LOGICAL ERRORS IN COMPILATION, OBJECT AND EXECUTABLE CODE.
This document provides an overview of algorithms and recursion from a lecture. It discusses performance analysis using Big O notation. Common time complexities like O(1), O(n), O(n^2) are introduced. The document defines an algorithm as a set of well-defined steps to solve a problem and categorizes algorithms as recursive vs iterative, logical, serial/parallel/distributed, deterministic/non-deterministic, exact/approximate, and quantum. Examples of recursive algorithms like factorials, greatest common divisor, and the Fibonacci sequence are presented along with their recursive definitions and code implementations.
This document discusses different operations on linked lists such as insertion, deletion, and traversal. It begins with an introduction to linked lists explaining that each node contains a data field and pointer to the next node. It then covers implementing a basic node structure and various functions like creating a new node, adding a node to the beginning or end of the list, and deleting a node from the beginning, end, or a given position. Traversal and keeping track of previous nodes is important for operations like deletion from within the list. The document provides pseudocode to demonstrate common linked list operations.
The document discusses binary tree traversal methods. It defines key binary tree terminology like nodes, edges, root, and provides examples of different types of binary trees like strictly binary, complete, and almost complete binary trees. It also explains the three common traversal techniques for binary search trees - in-order, pre-order and post-order traversals - and provides pseudocode algorithms and examples for each traversal method.
Variables, Data Types, Operator & Expression in c in detailgourav kottawar
This document provides an overview of variables, data types, operators, and expressions in C programming. It covers C's character set and tokens. It describes the different data types like integer, floating point, character, and string. It also discusses variables, declarations, definitions, and user-defined types. The document outlines the various operators in C including arithmetic, relational, logical, increment/decrement, bitwise, assignment, and conditional operators. It explains type conversions, both implicit and explicit, in expressions. Finally, it covers operator precedence and associativity rules for evaluating expressions in C.
BRANCHING STATEMENTS
if statement
if – else statement
if – else if ladder
Nested if
Goto
Switch case
programs
output
flowchart
Branching / Decision Making Statements
The statements in the program that helps to transfer the control from one part to other parts of the program.
Facilitates program in determining the flow of control
Involves decision making conditions
See whether the condition is satisfied or not
If statement; Execute a set of command line or one command line when the logical condition is true.
It has only one option
syntax with flowchart
If else if ladder; Number of logical statements are checked for executing various statement
If the first condition is true the compiler executes the block followed by first if condition.
If false it skips the block and checks for the next logical condition followed by else if.
Process is continued until a true condition is occurred or an else condition is satisfied.
Switch case; Multiway branch statement
It only requires one argument of any type, which is checked with number of cases.
If the value matches with the case constant, that particular case constant is executed. If not the default statement is executed.
Break statement – used to exit from current case structure
Nested if else; When a series of decisions are involved we use more than one if-else statement.
If condition is true control passes to first block i.e., if block. In this case there may be one more if block.
If condition is false control passes to else block. There we may have one more if block.
Stacks are linear data structures that only allow insertion and deletion of elements from one end, called the top. Elements are inserted via a push operation and deleted via a pop operation. Stacks can be implemented using arrays, with a pointer tracking the top element. Common applications of stacks include reversing the order of elements and evaluating mathematical expressions by treating them as a postfix notation.
The document discusses various topics related to analyzing algorithms, including:
i. Analysis of running time and using recurrence equations to predict how long recursive algorithms take on different input sizes.
ii. Iteration, induction, and recursion as fundamental concepts in data structures and algorithms. Recursive programs can sometimes be simpler than iterative programs.
iii. Proving properties of programs formally or informally, such as proving statements are true for each iteration of a loop or recursive call of a function. This is often done using induction.
Merge sort is a divide and conquer algorithm that divides an array into halves, recursively sorts the halves, and then merges the sorted halves back together. The key steps are:
1. Divide the array into equal halves until reaching base cases of arrays with one element.
2. Recursively sort the left and right halves by repeating the divide step.
3. Merge the sorted halves back into a single sorted array by comparing elements pairwise and copying the smaller element into the output array.
Merge sort has several advantages including running in O(n log n) time in all cases, accessing data sequentially with low random access needs, and being suitable for external sorting of large data sets that do not fit in memory
Input Output Management In C ProgrammingKamal Acharya
This document discusses input/output functions in C programming, including printf() and scanf(). It explains how to use format specifiers like %d, %f, %s with printf() to output variables of different types. It also covers escape sequences like \n, \t that control formatting. Scanf() uses similar format specifiers to read input from the keyboard into variables. The document provides examples of using printf() and scanf() with different format specifiers and modifiers.
The document discusses different types of decision making or control statements in programming including if, if-else, nested if-else, else-if ladder, and switch statements. It provides syntax and examples for each type of statement. The if statement executes code if a condition is true, if-else adds an else block for when the condition is false, nested if-else allows multiple levels of conditions, else-if ladder provides multiple else if conditions in a chain, and switch allows executing different code for different cases.
An array is a collection of similar data elements stored in contiguous memory locations that can each be accessed using an index number. Arrays allow storing multiple values, like student marks for 5 subjects, without defining individual variables. Basic array operations include traversing to print all elements, insertion to add an element, deletion to remove an element, and searching to find an element by index or value.
This document discusses asymptotic notations which are mathematical tools used to analyze the time and space complexity of algorithms. It introduces Big O, Big Omega, and Big Theta notations. Big O notation represents the upper bound and worst case time complexity. Big Omega notation represents the lower bound and best case time complexity. Big Theta notation defines the average time complexity of an algorithm. Examples are provided for how to determine the asymptotic notation of polynomial functions.
Introduction to control structure in C Programming Language include decision making (if statement, if..else statement, if...else if...else statement, nested if...else statement, switch...case statement), Loop(for loop, while loop, do while loop, nested loop) and using keyword(break, continue and goto)
This document provides an introduction to strings in C programming. It discusses that strings are arrays of characters terminated by a null character. It explains how to declare and initialize strings, and provides examples of simple string programs. It also lists common string functions like strlen(), strcpy(), and strcat(), and provides examples of using each function. The document is intended as a presentation on strings for C programming.
The document discusses various sorting algorithms. It describes how sorting algorithms arrange elements of a list in a certain order. Efficient sorting is important as a subroutine for algorithms that require sorted input, such as search and merge algorithms. Common sorting algorithms covered include insertion sort, selection sort, bubble sort, merge sort, and quicksort. Quicksort is highlighted as an efficient divide and conquer algorithm that recursively partitions elements around a pivot point.
Contents:-
Introduction
What is a File?
High Level I/O Functions
Defining & Opening a File
Closing a File
The getc and putc Functions
The getw and putw Functions
The fprintf and fscanf Functions
The document defines various algebraic structures including algebraic systems, semi groups, monoids, groups, subgroups, homomorphisms, and isomorphisms. It provides examples of algebraic systems including (N, +), (Z, +, -), and (R, +, ., -). It defines the properties of closure, associativity, identity, and inverse for algebraic structures. It provides examples of semi groups, monoids, groups, and abelian groups. It also discusses the properties of groups including unique identity, unique inverses, and cancellation laws.
Analysis of Algorithm (Bubblesort and Quicksort)Flynce Miguel
Quicksort is a recursive divide-and-conquer algorithm that works by selecting a pivot element and partitioning the array into two subarrays of elements less than and greater than the pivot. It recursively sorts the subarrays. The divide step does all the work by partitioning, while the combine step does nothing. It has average case performance of O(n log n) but worst case of O(n^2). Bubble sort repeatedly swaps adjacent elements that are out of order until the array is fully sorted. It has a simple implementation but poor performance of O(n^2).
This document provides an overview of linear search and binary search algorithms.
It explains that linear search sequentially searches through an array one element at a time to find a target value. It is simple to implement but has poor efficiency as the time scales linearly with the size of the input.
Binary search is more efficient by cutting the search space in half at each step. It works on a sorted array by comparing the target to the middle element and determining which half to search next. The time complexity of binary search is logarithmic rather than linear.
The document provides an introduction to C programming, covering topics such as what a program is, programming languages, the history of C, and the development stages of a C program. It discusses the key components of a C program including preprocessing directives, the main function, and program layout. Examples are provided to illustrate C code structure and the use of variables, keywords, operators, input/output functions, and formatting output with printf.
The document discusses two searching algorithms - linear search and binary search. Linear search sequentially compares the target element to each element in the array, while binary search uses a divide and conquer approach to quickly hone in on the target element in a sorted array. Both algorithms are demonstrated with pseudocode and examples.
The document discusses linear search and binary search algorithms.
Linear search is the simplest search algorithm that works by sequentially checking each element of a list to see if it matches the search item. It has linear time complexity of O(n) as it may need to traverse the entire list in the worst case.
Binary search works on sorted lists by comparing the search item to the middle element and recursively searching either the left or right half. It has logarithmic time complexity of O(log n) as it cuts the search space in half each step. Pseudocode and examples are provided to illustrate both algorithms.
Variables, Data Types, Operator & Expression in c in detailgourav kottawar
This document provides an overview of variables, data types, operators, and expressions in C programming. It covers C's character set and tokens. It describes the different data types like integer, floating point, character, and string. It also discusses variables, declarations, definitions, and user-defined types. The document outlines the various operators in C including arithmetic, relational, logical, increment/decrement, bitwise, assignment, and conditional operators. It explains type conversions, both implicit and explicit, in expressions. Finally, it covers operator precedence and associativity rules for evaluating expressions in C.
BRANCHING STATEMENTS
if statement
if – else statement
if – else if ladder
Nested if
Goto
Switch case
programs
output
flowchart
Branching / Decision Making Statements
The statements in the program that helps to transfer the control from one part to other parts of the program.
Facilitates program in determining the flow of control
Involves decision making conditions
See whether the condition is satisfied or not
If statement; Execute a set of command line or one command line when the logical condition is true.
It has only one option
syntax with flowchart
If else if ladder; Number of logical statements are checked for executing various statement
If the first condition is true the compiler executes the block followed by first if condition.
If false it skips the block and checks for the next logical condition followed by else if.
Process is continued until a true condition is occurred or an else condition is satisfied.
Switch case; Multiway branch statement
It only requires one argument of any type, which is checked with number of cases.
If the value matches with the case constant, that particular case constant is executed. If not the default statement is executed.
Break statement – used to exit from current case structure
Nested if else; When a series of decisions are involved we use more than one if-else statement.
If condition is true control passes to first block i.e., if block. In this case there may be one more if block.
If condition is false control passes to else block. There we may have one more if block.
Stacks are linear data structures that only allow insertion and deletion of elements from one end, called the top. Elements are inserted via a push operation and deleted via a pop operation. Stacks can be implemented using arrays, with a pointer tracking the top element. Common applications of stacks include reversing the order of elements and evaluating mathematical expressions by treating them as a postfix notation.
The document discusses various topics related to analyzing algorithms, including:
i. Analysis of running time and using recurrence equations to predict how long recursive algorithms take on different input sizes.
ii. Iteration, induction, and recursion as fundamental concepts in data structures and algorithms. Recursive programs can sometimes be simpler than iterative programs.
iii. Proving properties of programs formally or informally, such as proving statements are true for each iteration of a loop or recursive call of a function. This is often done using induction.
Merge sort is a divide and conquer algorithm that divides an array into halves, recursively sorts the halves, and then merges the sorted halves back together. The key steps are:
1. Divide the array into equal halves until reaching base cases of arrays with one element.
2. Recursively sort the left and right halves by repeating the divide step.
3. Merge the sorted halves back into a single sorted array by comparing elements pairwise and copying the smaller element into the output array.
Merge sort has several advantages including running in O(n log n) time in all cases, accessing data sequentially with low random access needs, and being suitable for external sorting of large data sets that do not fit in memory
Input Output Management In C ProgrammingKamal Acharya
This document discusses input/output functions in C programming, including printf() and scanf(). It explains how to use format specifiers like %d, %f, %s with printf() to output variables of different types. It also covers escape sequences like \n, \t that control formatting. Scanf() uses similar format specifiers to read input from the keyboard into variables. The document provides examples of using printf() and scanf() with different format specifiers and modifiers.
The document discusses different types of decision making or control statements in programming including if, if-else, nested if-else, else-if ladder, and switch statements. It provides syntax and examples for each type of statement. The if statement executes code if a condition is true, if-else adds an else block for when the condition is false, nested if-else allows multiple levels of conditions, else-if ladder provides multiple else if conditions in a chain, and switch allows executing different code for different cases.
An array is a collection of similar data elements stored in contiguous memory locations that can each be accessed using an index number. Arrays allow storing multiple values, like student marks for 5 subjects, without defining individual variables. Basic array operations include traversing to print all elements, insertion to add an element, deletion to remove an element, and searching to find an element by index or value.
This document discusses asymptotic notations which are mathematical tools used to analyze the time and space complexity of algorithms. It introduces Big O, Big Omega, and Big Theta notations. Big O notation represents the upper bound and worst case time complexity. Big Omega notation represents the lower bound and best case time complexity. Big Theta notation defines the average time complexity of an algorithm. Examples are provided for how to determine the asymptotic notation of polynomial functions.
Introduction to control structure in C Programming Language include decision making (if statement, if..else statement, if...else if...else statement, nested if...else statement, switch...case statement), Loop(for loop, while loop, do while loop, nested loop) and using keyword(break, continue and goto)
This document provides an introduction to strings in C programming. It discusses that strings are arrays of characters terminated by a null character. It explains how to declare and initialize strings, and provides examples of simple string programs. It also lists common string functions like strlen(), strcpy(), and strcat(), and provides examples of using each function. The document is intended as a presentation on strings for C programming.
The document discusses various sorting algorithms. It describes how sorting algorithms arrange elements of a list in a certain order. Efficient sorting is important as a subroutine for algorithms that require sorted input, such as search and merge algorithms. Common sorting algorithms covered include insertion sort, selection sort, bubble sort, merge sort, and quicksort. Quicksort is highlighted as an efficient divide and conquer algorithm that recursively partitions elements around a pivot point.
Contents:-
Introduction
What is a File?
High Level I/O Functions
Defining & Opening a File
Closing a File
The getc and putc Functions
The getw and putw Functions
The fprintf and fscanf Functions
The document defines various algebraic structures including algebraic systems, semi groups, monoids, groups, subgroups, homomorphisms, and isomorphisms. It provides examples of algebraic systems including (N, +), (Z, +, -), and (R, +, ., -). It defines the properties of closure, associativity, identity, and inverse for algebraic structures. It provides examples of semi groups, monoids, groups, and abelian groups. It also discusses the properties of groups including unique identity, unique inverses, and cancellation laws.
Analysis of Algorithm (Bubblesort and Quicksort)Flynce Miguel
Quicksort is a recursive divide-and-conquer algorithm that works by selecting a pivot element and partitioning the array into two subarrays of elements less than and greater than the pivot. It recursively sorts the subarrays. The divide step does all the work by partitioning, while the combine step does nothing. It has average case performance of O(n log n) but worst case of O(n^2). Bubble sort repeatedly swaps adjacent elements that are out of order until the array is fully sorted. It has a simple implementation but poor performance of O(n^2).
This document provides an overview of linear search and binary search algorithms.
It explains that linear search sequentially searches through an array one element at a time to find a target value. It is simple to implement but has poor efficiency as the time scales linearly with the size of the input.
Binary search is more efficient by cutting the search space in half at each step. It works on a sorted array by comparing the target to the middle element and determining which half to search next. The time complexity of binary search is logarithmic rather than linear.
The document provides an introduction to C programming, covering topics such as what a program is, programming languages, the history of C, and the development stages of a C program. It discusses the key components of a C program including preprocessing directives, the main function, and program layout. Examples are provided to illustrate C code structure and the use of variables, keywords, operators, input/output functions, and formatting output with printf.
Similar to PPS 5.5.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.), BASIC SORTING ALGORITHMS (BUBBLE, INSERTION AND SELECTION), FINDING ROOTS OF EQUATIONS, NOTION OF ORDER OF COMPLEXITY THROUGH EXAMPLE PROGRAMS (NO FORMAL DEFINITION REQUIRED) (20)
The document discusses two searching algorithms - linear search and binary search. Linear search sequentially compares the target element to each element in the array, while binary search uses a divide and conquer approach to quickly hone in on the target element in a sorted array. Both algorithms are demonstrated with pseudocode and examples.
The document discusses linear search and binary search algorithms.
Linear search is the simplest search algorithm that works by sequentially checking each element of a list to see if it matches the search item. It has linear time complexity of O(n) as it may need to traverse the entire list in the worst case.
Binary search works on sorted lists by comparing the search item to the middle element and recursively searching either the left or right half. It has logarithmic time complexity of O(log n) as it cuts the search space in half each step. Pseudocode and examples are provided to illustrate both algorithms.
The document discusses linear and binary search algorithms.
Linear search is the simplest algorithm that sequentially compares each element of an array to the target element. It has a worst case time complexity of O(N).
Binary search works on a sorted array by comparing the middle element to the target. It eliminates half of the remaining elements with each comparison. It has a worst case time complexity of O(log n), which is faster than linear search for large data sets.
Pseudocode and C programs are provided as examples to implement linear and binary search.
Dsa – data structure and algorithms searchingsajinis3
The document discusses different searching algorithms like linear search and binary search. Linear search checks each element in a list sequentially until the target element is found. It has O(n) time complexity in worst case. Binary search works on sorted arrays by comparing the target value to the middle element and eliminating half of remaining elements in each step. It has O(log n) time complexity. Both algorithms have O(1) space complexity as they require storage for only one element.
Searching is an extremely fascinating and useful computer science technique. It helps to find the desired object with its location and number of occurrences. The presentation includes the basic principles, algorithms and c-language implementation.
This document summarizes two common searching algorithms: linear search and binary search. Linear search sequentially checks each element of an array to find a target value, making it suitable for unsorted data. Binary search divides a sorted array in half at each step to quickly locate a value. Pseudocode is provided for implementations of both search types. Key differences are that linear search has O(n) time complexity while binary search has O(log n) time for sorted data. Visualizations are included to illustrate how each search approach works.
This document provides information on various searching and sorting algorithms, including linear search, binary search, bubble sort, selection sort, and insertion sort. It begins with an overview of searching and describes linear and binary search algorithms. For linear search, it provides pseudocode and an example. For binary search, it also provides pseudocode and an example. The document then discusses sorting algorithms like bubble sort, selection sort, and insertion sort, providing descriptions, pseudocode, examples, and analyses of each.
• Read and understand Java-based software code of medium-to-high complexity.
• Use standard and third party Java's API’s when writing applications.
• Understand the basic principles of creating Java applications with graphical user interface (GUI).
• Understand the features of Java supporting object oriented programming
• Understand the relative merits of Java as an object oriented programming language
• Understand how to produce object-oriented software using Java
• Understand how to apply the major object-oriented concepts such as encapsulation, inheritance and polymorphism to implement object oriented programs in Java.
• Understand advanced features of Java specifically stream I/O, Files etc.
• Apply the abovementioned points to design, implement, appropriately document and test a Java application of medium complexity, consisting of multiple classes.
• Read and understand Java-based software code of medium-to-high complexity.
• Use standard and third party Java's API’s when writing applications.
• Understand the basic principles of creating Java applications with graphical user interface (GUI).
• Understand the features of Java supporting object oriented programming
• Understand the relative merits of Java as an object oriented programming language
• Understand how to produce object-oriented software using Java
• Understand how to apply the major object-oriented concepts such as encapsulation, inheritance and polymorphism to implement object oriented programs in Java.
• Understand advanced features of Java specifically stream I/O, Files etc.
• Apply the abovementioned points to design, implement, appropriately document and test a Java application of medium complexity, consisting of multiple classes.
• Read and understand Java-based software code of medium-to-high complexity.
• Use standard and third party Java's API’s when writing applications.
• Understand the basic principles of creating Java applications with graphical user interface (GUI).
• Understand the features of Java supporting object oriented programming
• Understand the relative merits of Java as an object oriented programming language
• Understand how to produce object-oriented software using Java
• Understand how to apply the major object-oriented concepts such as encapsulation, inheritance and polymorphism to implement object oriented programs in Java.
• Understand advanced features of Java specifically stream I/O, Files etc.
• Apply the abovementioned points to design, implement, appropriately document and test a Java application of medium complexity, consisting of multiple classes.
The document discusses various searching algorithms. It introduces linear search and binary search. Linear search sequentially checks each element until the target is found or the entire array is searched. Binary search works on a sorted array by repeatedly dividing the search space in half and focusing on only one half. The best case for both is O(1) while the worst case for linear search is O(N) and for binary search is O(LogN).
Searching algorithms are used to find elements within datasets. Sequential search linearly checks each element until a match is found, taking O(n) time on average. Interval search algorithms like binary search target the center of a sorted structure and divide the search space in half at each step, taking O(log n) time on average. Jump search checks fewer elements than linear search by jumping ahead by a fixed number of steps or block size, typically the square root of the list length. Interpolation search may check non-middle indexes based on the searched value, working best for uniformly distributed sorted data.
This document discusses various searching and sorting algorithms. It begins by defining searching as finding an element in a given list. Linear search and binary search are described as two common searching algorithms. Linear search has O(n) time complexity while binary search has O(log n) time complexity but requires a sorted list. The document also discusses different sorting algorithms like bubble sort, insertion sort, and merge sort, and defines key concepts related to sorting like stability, efficiency, and passes.
The document discusses two search algorithms: linear search and binary search. Linear search sequentially scans an array to find a value, while binary search divides the array in half at each step to quickly locate a value in a sorted array. It provides pseudocode for both algorithms and compares their benefits, with linear search being simpler but less efficient than binary search for large data sets.
The document discusses various searching and sorting algorithms that use the divide and conquer approach. It describes linear search, binary search, and merge sort algorithms. Linear search has a time complexity of O(n) as it must examine each element to find the target. Binary search has a time complexity of O(log n) as it divides the search space in half each iteration. Merge sort also has a time complexity of O(n log n) as it divides the list into single elements and then merges them back together in sorted order.
The document discusses various searching algorithms like linear search and binary search. It provides details on how linear search works by sequentially checking each element of an unsorted array to find a target value. Binary search is described as more efficient for sorted arrays, as it repeatedly divides the search space in half by comparing the target to the middle element. Implementation of both iterative and recursive binary search algorithms is demonstrated through pseudocode.
The STET (State Teacher Eligibility Test) 2025 refers to the examination for teachers in Bihar, India. The exam is expected to be conducted by the Bihar School Examination Board (BSEB) to determine the eligibility of candidates for teaching positions.
n the world of Artificial Intelligence, two giants have emerged: DeepSeek and ChatGPT. Both offer groundbreaking capabilities and features, but which one is the best fit for your needs? Whether you're an entrepreneur, a developer, a student, or simply an enthusiast, "DeepSeek vs. ChatGPT: The Battle of AI Titans" will guide you through the intricate world of these AI systems, helping you choose the right one for you and your specific use case.
Highlights of the Book:
Comprehensive AI Comparison: Learn about the strengths and weaknesses of both DeepSeek and ChatGPT. Understand how each one operates, their unique features, and how they can benefit you in different scenarios.
Advanced Techniques: Gain insight into advanced techniques for using DeepSeek and ChatGPT. Learn how to fine-tune prompts, troubleshoot common issues, and integrate these AIs with other tools to maximize their potential.
Real-World Use Cases: Learn how each AI system performs in specific industries and use cases, from customer service and marketing to software development and education. Understand which one excels in each domain and how you can leverage them for your goals.
Practical Tips and Tricks: Get actionable strategies for optimizing performance, solving technical challenges, and using both AIs in a way that aligns with your goals. These tips will help you become a power user and get the most out of these AI systems.
Choosing the Right AI for You: This book doesn't just provide information-it helps you make the best choice for your unique needs. Whether you're focused on accuracy, creativity, or scalability, you'll find clear guidance on which AI system will serve you best.
Why This Book Is for You:
If you're looking to stay ahead in the fast-paced world of AI, this book will serve as your ultimate guide. Whether you're choosing between DeepSeek and ChatGPT for a personal project or an enterprise solution, this book helps you weigh the pros and cons of each system. Armed with in-depth insights and real-world applications, you will be able to make an informed decision that aligns with your needs.
With clear, actionable advice, "DeepSeek vs. ChatGPT: The Battle of AI Titans" helps you cut through the complexity of these systems and unlock their full potential. From integrating AI into your workflow to solving the most common issues, this book provides you with everything you need to succeed in your AI journey.
Get your copy today and join the battle of AI titans!
The Purpose of Cutting and Copying
Copying: Creates a duplicate of the selected data without removing it from its original location. This is useful when the same data is needed in multiple locations.
Cutting: Moves the selected data from its original location to a new one. The original data is removed after pasting.
Example: If you have a list of names in Column A and need to duplicate them in Column B, you can use Ctrl+C (Copy) to duplicate them. To move the data instead, use Ctrl+X (Cut).
Unlock Seamless Cloud Storage with "Beginners' Guide to Microsoft OneDrive"!
Master the essentials of OneDrive with this easy-to-follow guide designed for beginners and everyday users. From setting up your account to syncing and securing files across all your devices, this book covers everything you need to streamline your digital life.
Inside this all-in-one guide, you’ll discover:
🚀 Getting Started with OneDrive – Step-by-step instructions to set up your OneDrive account and navigate the intuitive interface, so you can start organizing and storing files in minutes.
📂 Efficient File Management – Learn how to upload, tag, and organize files for effortless storage, using OneDrive’s powerful search functions and management tools.
💻 Syncing Across Devices – Master the art of syncing files on Windows, macOS, and mobile devices, ensuring your important documents are always up-to-date and accessible, wherever you are.
Sharing and Collaboration – Discover how to share files, co-author documents, and collaborate in real-time with Microsoft’s seamless integration of OneDrive, Teams, and Office Online.
🔐 Security at Its Best – Understand OneDrive’s security features, like two-factor authentication and version control, to safeguard your files and recover older versions whenever needed.
💼 OneDrive for Work and School – Explore how OneDrive can enhance productivity in both professional and educational settings, with practical examples and tips for organizing, sharing, and collaborating on work or academic projects.
🔧 Troubleshooting Common Issues – Solve syncing problems, upload errors, and access issues with simple, practical solutions that keep you running smoothly.
Start mastering Microsoft OneDrive today and transform how you manage your files and collaborate online!
Buy now and simplify your file management today!
Are you interested in using AI strategies to 10x your productivity and money via human and real-world applications?
Are you interested in getting updated on the use of artificial intelligence and ChatGPT for your personal and professional growth?
Perhaps you used ChatGPT once or twice and the results you got were disappointing. You've found yourself staring at your screen in frustration, wondering how some people are effortlessly skyrocketing their productivity and financial success with ChatGPT, while you on the other hand, are still struggling to experience at least a quarter of the potential AI claims to have.
YOU DON'T HAVE TO KEEP STRUGGLING. Being a pro at using ChatGPT is way EASIER than you think it is–- As long as you have the right guide to help you!
This book was human-written, with ChatGPT used for research purposes. You too can get the knowledge, skills, and planning that is needed for exploring the use of artificial intelligence, to any level, right at your fingertips.
‘ChatGPT Prompts and Generative AI for Beginners’ gives you everything you need to get started or to enhance your current journey. With this indispensable resource, you will learn the necessary skills to thrive AND how to make money at the same time.
Inside ‘ChatGPT Prompts and Generative AI for Beginners’, you're going to learn about:
• The foundations of AI and ChatGPT
• How to enhance personal productivity with AI
• The best ways to apply effective ChatGPT prompts
• Strategies for driving business growth and competitiveness with AI
• How to use AI tools for consultants
• Tailored solutions for sustainable business growth, to outsmart your competitors, outperform and outgrow your current limitations.
• AI-powered tools for overcoming productivity obstacles
• Leveraging AI for long-term financial success
• AI-driven wealth management
• Ethical dilemmas surrounding AI and how to stay safe
• And a whole lot more!
All rights reserved. No part of this book may be reproduced, stored in a
retrieval system, or transmitted in any form or by any means, electronic,
mechanical, photocopying, recording, or otherwise, without prior written
permission by the author
Are you passionate about filmmaking but feel limited by the constraints of expensive equipment and complex setups? Smart Phone Film Making is here to show you how to transform your smartphone into a powerful, portable film studio. Whether you're an aspiring filmmaker, content creator, or an experienced director eager to explore the possibilities of mobile technology, this book is packed with the tools, techniques, and inspiration you need to bring your stories to life.
Filmmaking has come a long way, and now smartphones can produce high-quality films that rival traditional cameras. With the right approach, your mobile device can become an incredible tool for storytelling, opening up opportunities for creativity, flexibility, and innovation. Smart Phone Film Making guides you step-by-step, from conceptualizing your idea to editing your final cut—all with just your phone.
Discover how to generate and refine ideas that resonate with audiences. Learn how to build compelling narratives and structure your stories effectively, whether you're working on a short film, a documentary, or a full-length feature. This book will help you translate your vision into an engaging screenplay.
Dive into smartphone cinematography by exploring the fundamentals of composition and shot techniques that enhance the look and feel of your film. Learn about framing, depth, the rule of thirds, and how to capture dynamic shots with your phone. From lighting techniques to camera movement, you'll gain insights to create visually stunning scenes.
Explore the best apps and tools for mobile filmmaking, from camera control apps with professional-level settings to editing software that handles complex projects. You'll find everything you need for a seamless workflow, plus discover affordable accessories like gimbals, lenses, and microphones that can elevate your film quality.
Editing is a crucial part of filmmaking, and your smartphone is fully capable of producing polished results. Learn about top mobile editing apps and techniques for cutting scenes, color grading, adding soundtracks, and enhancing visuals. With practical advice, you'll turn raw footage into a cohesive story.
Filming with a smartphone does come with unique challenges, from battery life and storage issues to achieving stable shots. This book shares proven strategies for managing these obstacles, ensuring your production stays smooth and uninterrupted. You'll learn how to make the most of your smartphone's capabilities while finding creative ways to navigate its limitations.
Once your film is complete, knowing how to promote it and reach an audience is key. Learn how to create buzz, submit your work to film festivals, and leverage social media and online platforms for maximum exposure. This book covers best practices for marketing and distribution to help your film gain the recognition it deserves.
BASIC COMPUTER CONCEPTS MADE BY: SIR NASEEM AHMED KHAN DOW VOCATIONAL & TECHNICAL TRAINING CENTRE
What is a computer? An electronic device, operating under the control of instructions stored in its own memory unit, that can accept data (input), manipulate the data according to specified rules (process), produce information (output) from the processing, and store the results for future use.
Advantages of Computers • Speed • Storage • High Accuracy • Versatility • Diligence • Automatic Operation • Obedience • Decision Making Capability
Ages of Computer • At the early age people used pebbles, stones, sticks, scratches, symbols and finger tips to count, which were later replaced by numbers. • The history of computing is divided into three ages during which man invented and improved different types of calculating machines. These ages are, • Dark age - 300 BC to 1890 • Middle age - 1890 AD to 1944 • Modern age - since 1944 AD
Classification of Computers According to Purpose General Purpose Computers: General purpose computers are designed to solve a large variety of problems. The different programs can be used to solve many problems. Most digital computers are general purpose computers and used in business and commercial data processing.
Classification of Computers According to Purpose . 2 Special Purpose Computers • The special purpose computers are designed to solve specific problems. The computer program for solving a specific problem is built right into the computer. Most analog computers are special purpose computers. These special purpose computers are widely used in industrial robotics.
Types of Computers . 1 Analog Computers A computer that uses moving parts to show changing information. The word “Analog” means continuously varying in quantity. The voltage, current, sound, speed, temperature, pressure etc. values are examples of analog data. The thermometer is an example of analog device because it measures continuously the length of a mercury column. Another example of analog computer is the analog clock because it measures the time by means of the distance continuously covered by the needle around a dial.
Types of Computers . 2 Digital Computers The word “Digital” means separate. It refers to binary system, which consists of only two digits, i.e. 0 and 1. Digital data consists of binary data represented by OFF (low) and ON (high) electrical pulses. These pulses are increased and decreased in discontinuous form rather than in continuous form. In digital computers, quantities are counted rather than measured. A digital computer operates by counting numbers or digits and gives output in digital form.
Types of Computers 3. Hybrid Computers The hybrid computers have best features of both analog and digital computers. These computers contain both the digital and analog components. In hybrid computers, the users can process both the continuous (analog) and discrete (digital) data.
Classification of Computers According to Size • Super Comput
Index
MS Word .....................................................................................................................................................1
What is Microsoft Word......................................................................................................................3
Brief History...........................................................................................................................................3
Quick Access Toolbar................................................................................................................................3
Title Bar........................................................................................................................................................4
Ribbon and Tabs ........................................................................................................................................4
Home tab:...........................................................................................................................................5
Insert tab: ...........................................................................................................................................5
Page Layout tab: ..............................................................................................................................6
References tab:.................................................................................................................................6
Mailings tab:......................................................................................................................................6
Review tab: ........................................................................................................................................7
View tab:.............................................................................................................................................7
Ruler.............................................................................................................................................................7
How to Select Text in MS Word...............................................................................................................8
How to Copy and Paste Text in MS Word..............................................................................................9
How to Save the Document in MS Word..............................................................................................10
How to Correct Errors in Ms Word.........................................................................................................12
How to Change Font Size in MS Word.................................................................................................14
How to Change Font Style in MS Word................................................................................................15
How to Format Font Color in MS Word.............
Eligibility Criteria
Programmer: Candidates should have a B.Tech (CS), BE (CS), MCA, B.Sc. Engg. (CS) and M.Sc. IT or equivalent from a recognized University/Board/Institute.
Important Date
Start Date for Submit of Online Apply: 11 November 2024.
Last Date for Submit of Apply Online: 10 December 2024.
Application Fee
All Other Candidates Rs.1000/-.
SC/ ST/ All Female of Bihar State/PH (Disabled) Candidates Rs.250/-.
Age Limit as of 01/08/2024
Minimum Age: 21 Years.
Maximum Age: 59 Years.
Selection Process
CBT-based MCQ (Multiple Choice Question) exam.
Proficiency Test.
How to Apply
Mode of Apply: Through Online.
Job Location: Bihar.
The document provides an overview of corporate social responsibility (CSR) through a presentation by R.K. Sahoo on August 14, 2012. It defines CSR as a company's commitment to operate in an economically, socially, and environmentally sustainable manner. The presentation discusses the importance of CSR and outlines how companies can integrate the principles of CSR, such as by respecting human rights, protecting the environment, and contributing to local communities
In this slides I explain how I have used storytelling techniques to elevate websites and brands and create memorable user experiences. You can discover practical tips as I showcase the elements of good storytelling and its applied to some examples of diverse brands/projecT
Algorithms are the central part of computing and Design and Analysis of algorithms course is the core
of the study of Computer Science discipline. The revised course on design and analysis of algorithm
introduces many new topics: Deterministic and Stochastic Algorithms , how to solve recurrence
relation problems through Substitution method, Recurrence tree and Master methods, An overview of
local and global optima ,Fractional Knapsack problem ,Huffman Codes ,a task scheduling algorithm ,
Topological Sort ,Strongly Connected Components , Maximum Bipartite Matching Problem, Binomial
coefficient computation , Floyd Warshall algorithm , String Matching Techniques :The naïve String
Matching Algorithm, The Rabin Karp Algorithm, Knuth –Morris Pratt Algorithm, Handling
Intractability: Approximation algorithms for Vertex Cover problem and Minimizing makespan as
parallel machines(Graham’s algorithm) , Parameterized algorithm for Vertex Cover problem and
Meta-heuristic Algorithms
Course Structure*
Block- 1 Introduction to Algorithms
Unit 1: Basics of an Algorithm and its
properties
- Introduction
- Objective
- Example of an Algorithm
- Basics building blocks of Algorithms
- A survey of common running time
- Analysis & Complexity of Algorithm
- Types of problems
- Problem Solving Techniques
- Deterministic and Stochastic
Algorithms
- Summary
- Solutions/Answers
- Further Readings
Unit 2: Some pre-requisites and
Asymptotic Bounds
Introduction
Objectives
Some Useful Mathematical
Functions &Notations
Functions & Notations
Modular Arithmetic/Mod
Function
Mathematical Expectation
Principle of Mathematical
Induction
Concept of Efficiency of an Algorithm
Well Known Asymptotic Functions &
Notations
Summary
Solutions/Answers
Unit 3: Analysis of Simple Algorithm
Introduction
Objectives
complexity Analysis of Algorithms
Euclid Algorithm for GCD
Polynomial Evaluation Algorithm
Exponent Evaluation
Sorting Algorithm
3.3 Analysis of Non-Recursive Control
Structures
Sequencing
for Construct
While and Repeat Constructs
Recursive Constructs
Summary
Solutions/Answers
Further Readings
22
Unit 4: Solving Recurrences
- Introduction
- Objective
- Substitution Methods
- Iteration Methods
- Recursive Tree Methods
- Master Methods
- Summary
- Solution/Answers
- Further Readings
Block- 2 Design Techniques-I
Unit 1: Greedy Technique
Some Examples to understand Greedy
Techniques
Formalization of Greedy Techniques
An overview of local and global
optima
Fractional Knapsack problem
Huffman Codes
A task scheduling algorithm
Unit 2: Divide & Conquer Technique
General Issues in Divide and Conquer
Technique
Binary Search Algorithm
Sorting Algorithm
o Merge Sort
o Quick Sort
Matrix Multiplication Algorithm
Unit 3: Graph Algorithm -I Basic Definition and terminologies Graph Representation
o Adjacency Matrix
o Adjacency List Graph Traversal Algorithms
o Depth First Search
o Breadth First Search Topological Sort Strongly Connected Components
Bl
Decoding Kotlin - Your Guide to Solving the Mysterious in Kotlin - Devoxx PL ...João Esperancinha
Kotlin can be very handy and easy to use. Kotlin offers the possibility to develop code that is easy to understand, safe, immutable, and thus predictable and follows standards that avoid side effects. I realized that very quickly after I started my Kotlin journey that already amounts to more than 5 years.
This is the third version of this presentation focused on more detail explaining inline, crossinline, tailrec and as a bonus a quick run through unnamed classes.
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSsamueljackson3773
In this paper, the author discusses the concerns of using various wireless communications and how to use
them safely. The author also discusses the future of the wireless industry, wireless communication
security, protection methods, and techniques that could help organizations establish a secure wireless
connection with their employees. The author also discusses other essential factors to learn and note when
manufacturing, selling, or using wireless networks and wireless communication systems.
Blood bank management system project report.pdfKamal Acharya
The main objective of the “Blood Bank management System” all the details in the Blood
Bank’sprocess. This project has some tasks to maintain the Blood Bank through computerization.
Using this blood bank system people can search blood group available which they are needed.
They check it on using our blood bank management website. If in case blood group is not available
in blood bank they can also contact numbers of the persons who has the same blood group he is
need. And he can request the person to done the blood for saving someone life.
The Project describes the smart Blood Bank management system. This report will help you
to know in deep the actual work that has been done as a team work. The main objective of this
application is to automate the complete operations of the blood bank. They need to maintain
hundreds of thousands of records. Also searching should be very faster, so they can find required
details instantly. Main objective is to create a system which helps them to complete their work
faster in simple way by using computer not the oldest way which is used paper. Also our project
contains updated information and many things else.
The project consists of a central repository containing various blood deposits available
along with associated details. These details include blood type, storage area and date of storage.
These details help in maintaining and monitoring the blood deposits. The project is an online
system that allows checking weather required blood deposits of a particular group are available in
the blood bank. Moreover the system also has added features such as patient name and contacts,
blood booking and even need for certain blood group is posted on the website to find available
donors for a blood emergency. This online system is developed on PHP platform and supported
by an MYSQL database to store blood and user specific details.
OCS Group SG - HPHT Well Design and Operation - SN.pdfMuanisa Waras
This course is delivered as a scenario-based course to
provide knowledge of High Pressure and High-Temperature (HPHT) well design, drilling and completion operations. The course is specifically designed to provide an
understanding of the challenges associated with the design
and construction of HPHT wells. The course guides the
participants to work through the various well design
aspects starting from a geological well proposal with an
estimated formation pressure and temperature profile.
Working with real well data allows the participants to learn
not only theory, technicalities and practicalities of drilling
and completing HPHT wells but it also ensures that participants gain real experience in understanding the HPHT issues.
Water demand - Types , variations and WDSdhanashree78
Water demand refers to the volume of water needed or requested by users for various purposes. It encompasses the water required for domestic, industrial, agricultural, public, and other uses. Essentially, it represents the overall need or quantity of water required to meet the demands of different sectors and activities.
4th International Conference on Computer Science and Information Technology (...ijait
4th International Conference on Computer Science and Information Technology
(COMSCI 2025) will act as a major forum for the presentation of innovative ideas,
approaches, developments, and research projects in the area computer Science and
Information Technology. It will also serve to facilitate the exchange of information
between researchers and industry professionals to discuss the latest issues and
advancement in the research area.
chemistry investigatory project for class 12Susis10
PPS 5.5.BASIC ALGORITHMS SEARCHING (LINEAR SEARCH, BINARY SEARCH ETC.), BASIC SORTING ALGORITHMS (BUBBLE, INSERTION AND SELECTION), FINDING ROOTS OF EQUATIONS, NOTION OF ORDER OF COMPLEXITY THROUGH EXAMPLE PROGRAMS (NO FORMAL DEFINITION REQUIRED)
1. PPS
Unit – 5
Basic Algorithms
5.1 Searching (Linear Search, Binary Search Etc.)
Sorting and Searching are fundamental operations in computer science. Sorting refers to
the operation of arranging data in some given order. Searching refers to the operation
of searching the particular record from the existing information.
Consider a database of banking system where information of all customers such as
name, contact number, address, account number is stored. If a manager wants to search
for a record of a particular customer, he has to look for that record from among all
records that has been stored in a database. This process of looking up for a particular
record in a database is referred as searching.
If records in a banking database are not ordered properly it will be very difficult for a
manager to search for a specific record. On the contrary if all record are arranged in
order according to some criteria like names in alphabetical order or account numbers in
ascending order, searching becomes easy and fast. The process of ordering the records
in a data base is called sorting. Thus for efficient searching sorting is necessary.
Linear Search
Given a collection of objects, the goal of search is to find a particular object in this
collection. The objects have key values on which search is performed and data values
which correspond to the information one wishes to retrieve once an object is found. For
example, a telephone book is a collection of names on which one searches and
telephone numbers which correspond to the data being sought. The collection of
objects is often stored in a list or an array. Given a collection of objects in an array A[1..
n], the ith element A[i] corresponds to the key value of the ith object in the collection.
The input to a search algorithm is an array of objects A, the number of objects n, and the
key value being sought x.
Thus Algorithm for Linear Search is
1. start at one end of the list
2. if the current element is not equal to the search target, move to the next element,
3. stop when a match is found or the opposite end of the list is reached.
2. Function for Linear search is
find(values, target)
{
for(i = 0; i<values.length; i++)
{
if (values[i] == target)
{ returni; }
}
return –1;
}
If element is found this function returns index of that element otherwise it returns –1.
Example : we have an array of integers, like the following:
Elements 9 6 7 12 1 5
Index 0 1 2 3 4 5
Let’s search for the number 7. According to function for linear search index for element
7 should be returned. We start at the beginning and check the first element in the array.
9 6 7 12 1 5
First element is 9.Match is not found and hence we move to next element i.e 6.
9 6 7 12 1 5
Again match is not found so move to next element i.e.7.
9 6 7 12 1 5
0 1 2 3 4 5
We found the match at the index position 2. Hence output is 2.
3. If we try to find element 10 in above array, it will return –1,as 10 is not present in the
array.
Complexity Analysis of Linear Search:
Let us assume element x is to be searched in array A of size n.
An algorithm can be analyzed using following three cases.
1. Worst case
2. Average case
3. Best case
1. Worst case :In Linear search worst case happens when element to be searched is not
present. When x is not present, the linear search function compares it with all the
elements of A one by one. The size of A is n and hence x is to be compared with all n
elements. Thus, the worst case time complexity of linear search would be O(n).
2. Average case : In average case analysis, we take all possible inputs and calculate
computing time for all of the inputs. Sum all the calculated values and divide the sum by
total number of inputs. Following is the value of average case time complexity.
3. Best Case : In linear search , the best case occurs when x is present at the first
location. So time complexity in the best case would be O(1).
P1 : Program for Linear Search
#include<stdio.h>
#include<conio.h>
int search(int [],int, int);
void main()
{
int a[20],k,i,n,m;
clrscr();
4. printf(“nn ENTER THE SIZE OF ARRAY”);
scanf(“%d”,&n);
printf(“nnENTER THE ARRAY ELEMENTSnn”);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(“nnENTER THE ELEMENT FOR SEARCHn”);
scanf(“%d”,&k);
m=search(a,n,k);
if(m==–1)
{
printf(“nnELEMENT IS NOT FOUND IN LIST”);
}
else
{
printf(“nnELEMENT IS FOUND AT LOCATION %d”,m);
}
}
getch();
}
int search(int a[],intn,int k)
{
inti;
for(i=0;i<n;i++)
{
if(a[i]==k)
{
return i;
}
}
if(i==n)
{
return –1;
}
}
Merits :
1. Simple and easy to implement
5. 2. It works well even on unsorted arrays.
3. It is memory efficient as it does not require copying and partitioning of the array
being searched.
Demerits :
1. Suitable only for small number of values.
2. It is slow as compared to binary search.
Binary Search
Binary Search requires sorted array.
Steps to perform binary search on sorted array A of size n are as follows.
1. Initialize lower and upper limit of array to be searched Low=0,High= n–1.
2. Find the middle position
Mid=(Low + High)/2
3. Compare the input key value with the key value of the middle element of the array. It
has 3 possibilities.
Case 1 : If keys match then return mid and print element found.
if(key==A[mid])
return mid
Case 2 : If key is less than middle element then element is present in left half of array.
Update High and goto step 2.
if(key<A[mid])
High= Mid–1
goto step 2
Case 3 : If key is greater than middle element then element is present in right half of
array. Update Low and goto step 2.
if(key>A[mid])
6. Low= Mid+1
goto step 2
Case 4:if(Low>High)
Print element not found.
Iterative algorithm for Binary Search
intBinarySearch( int A[],int x)
{
intmid,n;
int Low = 0;
int High = n–1;
while ( Low <= High )
{
mid = (Low + High) / 2;
if ( A[mid] == x )
return mid;
if ( A[mid] > x )
High = mid – 1;
else Low = mid + 1;
}
return –1;
}
7. Example 1 :Let array A= {–1, 5, 6, 18, 19, 25, 46, 78, 102, 114}. We want to find element
‘6’ using binary search.
–1 5 6 18 19 25 46 78 102 114
0 1 2 3 4 5 6 7 8 9
Solution:
Step 1 : Low=0, High= 9
Step 2 :Mid=(Low + High)/2
Mid = (0+9)/2 =4.5 i.e 4. It means middle element is located at position 4. So A[Mid] is
19.Thus
Low=0
Mid=4
High=9
Low Mid High
–1 5 6 18 19 25 46 78 10
2
114
0 1 2 3 4 5 6 7 8 9
Step 3 :Compare 6 with 19. It satisfies case 2 of step 3. so High= 4–1=3 and element is
present in left half of array. We can ignore right half of array.
Repeat step 2. So mid= (0+3)/2 = 1.5 i.e 1. mid is at position 1. Element 5 is present at
position 1.
Low = 0
Mid = 1
High = 3
Low Mid High
–1 5 6 18 19
0 1 2 3 4
Again compare 5 with 6. It satisfies case 3 of step 3. so
Low = 1+1=2.
8. Repeat step 2. Mid= (2+ 3)/2= 2.5 i.e 2 .Mid is at position 2. Element 6 is at position 2.
Low=2
Mid=2
High=3
Low,
Mid
High
–1 5 6 18 19
0 1 2 3 4
Compare 6 with 6.
Match is found. Return the position and print element found.
Example 2 : Find 103 in {–1, 5, 6, 18, 19, 25, 46, 78, 102, 114} using Binary Search.
Low Mid High
–1 5 6 18 19 25 46 78 10
2
114
0 1 2 3 4 5 6 7 8 9
Step 1 : Low=0
High=9
Step 2 :Mid=(0+9)/2=4
So middle element is 19.
Step 3 : Compare(103,19)
103>19 hence element is located at right half of array and we can ignore left half of
array. Update Low and recalculate mid.
Low = 4+1=5
High = 9
Mid = (5+9)/2=7
Low Mid High
25 46 78 102 114
5 6 7 8 9
9. Middle element is 78. Compare(103,78)
103>78. Recalculate Low and Mid
Low = 7+1=8
High = 9
Mid = (8+9)/2=8
Low, Mid High
102 114
8 9
Middle element is 102. Compare(103,102)
103>102. Recalculate Low and Mid.
Low = 8+1=9
High = 9
Here Low=High and match is not found hence we conclude that element is not present
in array.
Example 3 : Find 44 in A={5,12,17,23,38,44,77,84,90} using binary search.
Step 1: Low=0
High=8
Mid=(0+8)/2=4
Low Mid High
5 12 17 23 38 44 77 84 90
0 1 2 3 4 5 6 7 8
Middle element is 38. Compare(44,38)
44>38.Thus element is located at right half of array and we can ignore left half of array.
Recalculate Low and Mid.
Low = (4+1)= 5
10. High = 8
Mid = (5+8)/2=6.5 i.e 6
Low Mid high
44 77 84 90
0 1 2 3
Middle element is 77. Compare(44,77)
44<77. Recalculate High and Mid.
Low=5
High = 6–1=5
Mid = (5+5)/2=5
Low, Mid,
high
44 77 84 90
0 1 2 3
Middle element is 44. Compare(44,44)
Match is Found. Return index and print “Element Found.”
Algorithm for Recursive Binary Search
intBinarySearch (int A[], int x, int Low, int High)
{
if (High > Low)
return –1;
int mid = (High + Low) / 2;
if (A[mid] == x)
return mid;
if (A[mid] < x)
11. returnBinarySearch(A, x, mid+1, High);
returnBinarySearch(A, x, Low, mid–1);
}
P2 : Program for Binary Search
#include<stdio.h>
#include<conio.h>
void main()
{
intn,i,search,f=0,low,high,mid,a[20];
clrscr();
printf("Enter the number of elements:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the number in ascending order a[%d]=",i);
scanf("%d",&a[i]);
}
printf("Enter the element to be searched:");
scanf("%d",&search);
low=0;
high=n–1;
while(low<=high)
{
mid=(low+high)/2;
if(search<a[mid])
{
high=mid–1;
}
else if(search>a[mid])
{
low=mid+1;
}
else
{
f=1;
printf("Element is found at the position %d:",mid);
exit();
12. }
}
if(f==0)
{
printf("Element not found");
}
getch();
}
Complexity Analysis of Binary Search :
Assume our array size is 16.
When n= 16 BinarySearch is called to reduce size to n=8.
When n= 8 BinarySearch is called to reduce size to n=4.
When n= 4 BinarySearch is called to reduce size to n=2.
When n= 2 BinarySearch is called to reduce size to n=1 .
Thus we see that BinarySearch function is called 4 times
i.e. 4 elements of the array were examined for n =16.
Note that 16 = 24
Let us consider a more general case where
n is still a power of 2. Let us say n =2k
After k searches, the while loop is executed k times and n reduces to size 1. Let us
assume that each run of the while loop involves at most 4 operations.
Thus total number of operations: 4k.
The value of k can be determined from the expression
2k = n
Taking log of both sides
k = log n
13. Thus total number of operations = 4 log n.
We conclude that the time complexity of the Binary search method is O(log n), which is
much more efficient than the Linear Search method.
Merits :
Binary Search is fast and efficient.
Suitable for large number of values.
Demerits :
Binary search works only on sorted array or list.
5.2 Basic Sorting Algorithms (Bubble, Insertion And Selection)
Bubble Sort
Steps to perform Bubble sort are as follows.
Assume we want to sort the elements in ascending order and no two elements are equal.
1. Compare first element with second element. If first element is greater than next
element, we interchange their position accordingly. i.e first element is moved to second
element’s position and second element is moved to first element’s position. If No, then
we don’t interchange any elements.
2. The element in second position is compared with element in third position and the
process of interchanging elements is performed if second is greater than third element.
The whole process of comparing and interchanging is repeated till last element. When
the process gets completed, the largest element in array will get placed in the last
position of the array.
Let us consider array A of size n. Then Algorithm for Bubble sort is
1. Set i to 0.
2. Set j to 0.
3. if(A[j]>A[j+1])
swap A[j],A[j+1]
14. 4. Increment j
5. if j<(n–1–i) goto step 3
6. Increment i
7. if(i<n–1) goto step 2.
Example 1 : Suppose the following numbers are stored in an array A:
32 51 27 85 66 23 13 57
j = 0 1 2 3 4 5 6 7
We apply bubble sort to array A. We discuss each pass separately.
Pass 1
1. Compare j[0] and j[1]. Since 32 < 51, the list is not altered.
2. Compare j[1] and j[2] Since 51 > 27, interchange 51 and 27 as follows:
32 51 27 85 66 23 13 57
j = 0 1 2 3 4 5 6 7
Array A becomes
32 27 51 85 66 23 13 57
j = 0 1 2 3 4 5 6 7
3. Compare j[2] and j[3]. Since 51 < 85, array is not altered.
4. Compare j[3] and j[4]. Since 85 > 66, interchange 85 and 66 as follows:
32 27 51 85 66 23 13 57
j = 0 1 2 3 4 5 6 7
Array A becomes
32 27 51 66 85 23 13 57
j = 0 1 2 3 4 5 6 7
5. Compare j[4] and j[5]. Since 85 > 23, interchange 85 and 23 as follows:
32 27 51 66 85 23 13 57
j = 0 1 2 3 5 6 7
15. 4
Array A becomes
32 27 51 66 23 85 13 57
j = 0 1 2 3 4 5 6 7
6. Compare j[5] and j[6]. Since 85 > 13, interchange 85 and 13 as follows:
32 27 51 66 23 85 13 57
j = 0 1 2 3 4
5
6 7
32 27 51 66 23 13 85 57
j = 0 1 2 3 4 5 6 7
7. Compare j[6] and j[7]. Since 85 > 57, interchange 85 and 57 as follows:
32 27 51 66 23 13 85 57
j = 0 1 2 3 4 5
6
7
Array A becomes
32 27 51 66 23 13 57 85
j = 0 1 2 3 4 5 6 7
At the end of this first pass, the largest number, 85, has moved to the last position.
However, the rest of the numbers are not sorted, even though some of them have
changed their positions.
Pass 2 will move second last number at second last position, Pass 3 will move third last
number at third last position and so on. Here we show array after every pass.
Pass 2 :
27 33 51 23 13 57 66 85
j =
0
1 2 3 4 5 6 7
Pass 3 :
27 33 23 13 51 57 66 85
18. Pass 2 :
23 45 8 32 56 78
23 45 8 32 56 78
23 8 45 32 56 78
23 8 32 45 56 78
Pass 3 :
23 8 32 45 56 78
8 23 32 45 56 78
This array is sorted in 3 passes.
P3: Write a Program for Bubble sort in C
#include <stdio.h>
#include<conio.h>
voidbubble_sort(int A[], int n);
int main()
{
int A[100], n, i, j, swap;
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter the elementsn", );
for (i = 0; i< n; i++)
scanf("%d", &A[i]);
19. bubble_sort(A, n);
printf("Sorted list in ascending order:n");
for ( i = 0 ; i< n ; i++ )
printf("%ldn", A[i]);
return 0;
}
voidbubble_sort(int A[], int n)
{
inti, j, t;
for (i = 0 ; i< ( n – 1 ); i++)
{
for (j = 0 ; j < (n – i – 1); j++)
{
if (A[j] > list[j+1])
{
/* Swapping */
t = A[j];
A[j] = A[j+1];
A[j+1] = t;
}
}
}
20. }
Complexity Bubble sort:
Suppose we have a list with n elements, and each element perform n – 1 comparisons
with elements to its left, and swap, if necessary.
Best Case: If the list is already sorted, only one iteration is performed and complexity is
O(1).
Average and Worst case: For n elements at most n – 1 swap operations is performed in
each pass. The worst and average case complexity is O(n2).
Selection Sort
Assume we want to sort list in ascending order. Selection sort finds the smallest element
from unsorted list and swap it with the element in first position. Then it finds second
smallest element and swap it with element at second position. This process is repeated
till entire list is sorted in ascending order. Each time we swap elements, we say that
we have completed a sort pass. A list of n elements requires n–1 passes to
completely rearrange the data.
Procedure for every pass is as follows.
Pass 1 : Find the position P of the smallest in the list of N elements A[l], A[2], . . . , A[N],
and then interchange A[P] and A[1] . Then A[1] is sorted.
Pass 2 : Find the position P of the smallest in the sublist of N –1 elements A[2], A[3],. . . ,
A[N], and then interchange A[P]and A[2]. Then A[l], A[2] is sorted.
Pass 3 : Find the position P of the smallest in the sublist of N–2 elements A[3], A[4], . . . ,
A[N], and then interchange A[P] and A[3]. Then: A[l], A[2] , A[3] is sorted.
Pass N –1 :Find the position P of the smaller of the elements A[N –1), A[N], and then
interchange A[P] and A[N–1]. Then: A[l], A[2], . . . , A[N] is sorted. Thus A is sorted after
N –1 passes.
Example 1 :
25 79 41 9 34 60
Fig. 4.2 : Original List
We will apply selection sort on this list.
21. Unsorted sublist has 25 as a smallest element and 79 is located at second position.
Hence we swap 25 and 79.
23. 9 25 34 41 60 79
Thus list is sorted.
We will see one more example.
Apply selection sort on array A= {77,30,40,10,88,20,65,56}
24. Function for Selection Sort
voidselectionSort(int A[], int n)
{
inti, j, s, temp;
for (i= 0; i<= n; i ++)
{
s = i;
25. for (j=i+1; j <= n; j++)
if(A[j] < A[s])
s= j;
// Smallest selected; swap with current element
temp = A[i];
A[i] = A[s];
A[s] = temp;
}
P4 : Program to perform Selection Sort.
#include <stdio.h>
int main()
{
int A[100], n, i, j, s, temp;
/* n=total no. of elements in array
s= smallest element in unsorted array
temp is used for swapping */
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter %d integersn", n);
for ( i = 0 ; i< n ; i++ )
scanf("%d", &A[i]);
26. for ( i = 0 ; i< ( n – 1 ) ; i++ )
{
s = i;
for ( j = i + 1 ; j < n ; j++ )
{
if ( A[s] > A[j] )
s = j;
}
if ( s != i )
{
temp = A[i];
A[i] = A[s];
A[s] = temp;
}
}
printf("Sorted list in ascending order:n");
for ( i = 0 ; i< n ; i++ )
printf("%dn", A[i]);
return 0;
}
Output:
Enter number of elements
27. 5
Enter 5 integers
4
1
7
5
9
Sorted list in ascending order
1
4
5
7
9
Complexity of Selection Sort :
In selection sort outer for loop is executed n–1 times. On the kth time through the outer
loop, initially the sorted list holds
k–1 elements and unsorted portion holds n–k+1 elements. In inner for loop 2 elements
are compared each time.
Thus, 2*(n–k) elements are examined by the inner loop during the k th pass through the
outer loop. But k ranges from 1 to n–1.
Total number of elements examined is:
T(n) = 2*(n –1) + 2*(n–2) + 2*(n–3) + .. + 2*(n–(n–2))
+ 2*(n–(n–1))
28. = 2*((n–1) + (n–2) + (n–3) + ... + 2 + 1)
(or 2*(sum of first n–1 integers)
= 2*((n–1)*n)/2)
= n2
– n, so complexity of algorithm is O(n2
).
Insertion Sort
Insertion Sort reads all elements from 1 to n and inserts each element at its proper
position. This sorting method works well on small list of elements.
Procedure for each pass is as follows.
Pass 1 :
A[l] by itself is trivially sorted.
Pass 2 :
A[2] is inserted either before or after A[l] so that: A[l], A[2] is sorted.
Pass 3 :
A[3] is inserted into its proper place so that: A[l], A[2], A[3] is sorted.
Pass 4 :
A[4] is inserted into its proper place A[l], A[2], A[3], A[4] is sorted.
Pass N :
A[N] is inserted into its proper place in so that:
A[l], A[ 2 ] , . . . , A[ N ] is sorted
Example :We will apply insertion sort on original list of Fig.3.Assume we are arranging
elements in ascending order.
25 79 41 9 34 60
Fig. 4.3 : Original List
33. C Function for Insertion Sort
voidinsertionSort(int A[], int n)
{
inti, p, temp, j;
for (i = 1; i<=n; i++)
{
p= 0;
temp = A[i];
for (j=i–1; j >= 0 && !p;)
if(temp < A[j])
{
A[j + 1]= A[j];
j––;
34. }
else
p = 1;
A[j + 1] = temp;
}
return;
}
P5 : Program to implement insertion sort.
#include <stdio.h>
int main()
{
int n, A[100], i, j, t;
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter %d integersn", n);
for (i = 0; i< n; i++) {
scanf("%d", &A[i]);
}
for (i = 1 ; i<=( n – 1); i++)
{
j = i;
while ( j > 0 && A[j] < A[j–1])
35. {
t = A[j];
A[j] = A[j–1];
A[j–1] = t;
j––;
}
}
printf("Sorted list in ascending order:n");
for (i = 0; i<= n – 1; i++) {
printf("%dn", A[i]);
}
return 0;
}
Output :
Enter number of elements
5
Enter 5 integers
9
4
2
5
3
36. Sorted list in ascending order
2
3
4
5
9
Complexity of Insertion Sort :
Worst Case Complexity: In the worst case, for each i we do (i – 1) swaps inside the inner
for–loop–therefore, overall number of swaps (when i goes from 2 to n in the outer for
loop) is
T(n) = 1 + 2 + 3 +...+(I – 1) +....+ n – 1
= n (n – 1)/2
= O(n2
)
Average case Complexity is O(n2
).
Best Case Complexity is O(n).
5.3 Finding Roots Of Equations
Algorithm:
Step 1: Start
Step 2: Read a,b,c
Step 3: Initialize d <- (b*b) – (4*a*c)
Step 4: Initialize r<- b/2*a
Step 5: if d>0 go to step 6
37. Step 6: r1 = r+(sqrt(d)/2*a) and r2 = r-(sqrt(d)/2*a)
Step 7: print roots are real and distinct first root r1, second root r2
Step 8: if d=0 go to step 9
else go to step 10
Step 9: print roots are real and equal -r
Step 10 : d= -d
Step 11: im = sqrt(d)/2*a
Step 12: print roots are imaginary, first root r+iim, second root r-iim
Step 13: stop
Program:
void main()
{
float a,b,c,r,d,r1,r2,im;
clrscr();
printf(“nt Quadratic Equtionnn Enter the coefficientsn”);
scanf(“%f%f%f”, &a,&b,&c);
d= (b*b) –(4*a*c);
r=b/2*a
if(d>0)
{
r 1 = -r + (sqrt (d)/2*a)
r2 = -r - + (sqrt (d)/2*a)
printf(“n Roots are real and distinct nn first roott: %.2fnn second roott:%.2f
n”,r1,r2);
38. }
else if(d==0)
printf(“n Roots are real and equal nn roots =:%.2f,-r);
}
else
{
d=-d;
im=sqrt(d)/2*a;
printf(“nRoots are imaginary nnfirst roott;%.2fnnsecond roott:%.2f-i
%.2f”,r,im,r,im);
}
getch();
}
5.4 Notion Of Order Of Complexity Through Example Programs (No Formal
Definition Required)
To express the running time complexity of algorithm three asymptotic notations are
available. Asymptotic notations are also called as asymptotic bounds. Notations are used
to relate the growth of complex function with the simple function. Asymptotic notations
have domain of natural numbers. These notations are as follows
1. Big-oh notation: Big-oh notations can be express by using ‘o’ symbol. This notation
indicates the maximum number of steps required to solve the problem. This notation
expresses the worst case growth of an algorithm. Consider the following diagram in
which there are two functions f(x) and g(x). f(x) is more complex than the function g(x).
39. Fig. 3.7
In the above diagram out of two function f(n) and g(n), more complex function is f(n), so
need to relate its growth as compare to simple function g(n). More specifically we need
one constant function c(n) which bound function f(n) at some point n0. Beyond the point
‘n0’ function c*g(n) is always greater than f(n).
Now f(n)=Og(n)if there is some constant ‘c’ and some initial value ‘n0’. such that
f(n)<=c*g(n) for all n>n0
In the above expression ‘n’ represents the input size
f(n) represents the time that algorithm will take
f(n) and g(n) are non-negative functions.
Consider the following example
40. Fig. 3.8
In the above example g(n) is ‘’n’ and f(n) is ‘2n+1’ and value of constant is 3. The point
where c*g(n) and f(n) intersect is ‘’n0’. Beyond ‘n0’ c*g(n) is always greater than f(n) for
constant ‘3’. We can write the conclusion as follows
f(n)=O g(n) for constant ‘c’ =3 and ‘n0’=1
such that f(n)<=c*g(n) for all n>n0
2. Big-omega notation: Big-omega notations can be express by using ‘Ω’ symbol. This
notation indicates the minimum number of steps required to solve the problem. This
notation expresses the best case growth of an algorithm. Consider the following
diagram in which there are two functions f(n) and g(n). f(n) is more complex than the
function g(n).
41. Fig. 3.9
In the above diagram out of two function f(n) and g(n), more complex function is f(n), so
need to relate its growth as compare to simple function g(n). More specifically we need
one constant function c(n) which bound function f(n) at some point n0. Beyond the point
‘n0’ function c*g(n) is always smaller than f(n).
Now f(n)=Ωg(n)if there is some constant ‘c’ and some initial value ‘n0’. such that c*g(n)
<= f(n)for all n>n0
In the above expression ‘n’ represents the input size
f(n) represents the time that algorithm will take
f(n) and g(n) are non-negative functions.
Consider the following example
In the above example g(n) is ‘2n’ and f(n) is ‘2n-2’ and value of constant is 0.5. The point
where c*g(n) and f(n) intersect is ‘’n0’. Beyond ‘n0’ c*g(n) is always smaller than f(n) for
constant ‘0.5’. We can write the conclusion as follows
f(n)=Ω g(n) for constant ‘c’ =0.5 and ‘n0’=2
such that c*g(n)<= f(n) for all n>n0
42. Fig. 3.10
Big-theta notation: Big-theta notations can be express by using ‘Ɵ’ symbol. This
notation indicates the exact number of steps required to solve the problem. This
notation expresses the average case growth of an algorithm. Consider the following
diagram in which there are two functions f(n) and g(n). f(n) is more complex than the
function g(n).
Fig. 3.11
43. In the above diagram out of two function f(n) and g(n), more complex function is f(n), so
need to relate its growth as compare to simple function g(n). More specifically we need
one constant function c1 and c2 which bound function f(n) at some point n0. Beyond the
point ‘n0’ function c1*g(n) is always smaller than f(n) and c2*g(n) is always greater than
f(n).
Now f(n)= g(n) if there is some constant ‘c1 and c2’ and some initial value ‘n0’. such
that c1*g(n) <= f(n)<=c2*g(n)for all n>n0
In the above expression ‘n’ represents the input size
f(n) represents the time that algorithm will take
f(n) and g(n) are non-negative functions.
f(n)= g(n) if and only if f(n)=O g(n) and f(n)=Ω g(n)
Consider the following example
Fig. 3.12
In the above example g(n) is ‘2n’ and f(n) is ‘3n-2’ and value of constant c1 is 0.5 and c2
is 2. The point where c*g(n) and f(n) intersect is ‘’n0’. Beyond ‘n0’ c1*g(n) is always
smaller than f(n) for constant ‘0.5’ and c2*g(n) is always greater than f(n) for constant ‘2’.
We can write the conclusion as follows
44. f(n)=Ω g(n) for constant ‘c1’ =0.5 , ‘c2’ = 2 and ‘n0’=2
such that c1*g(n)<= f(n)<=c2*g(n) for all n>n0