This document provides definitions and implementations of various operations on one-dimensional arrays in C++. It begins with definitions of a 1D array, including how to calculate its size and address of elements. It then discusses implementations of basic operations like insertion, deletion, searching and sorting. Linear and binary search algorithms are presented for searching arrays. Selection, bubble, and insertion sort algorithms are covered for sorting. The document also discusses merging two sorted arrays. Examples of array problems and their solutions are provided at the end.
Entity Relationship Diagrams (ERDs) are used to model relationships between entities in a database. The document discusses ERD components like entities, relationships, cardinality, and attributes. It provides an example of an ERD for a company with departments, supervisors, employees, and projects. Key entities are identified and their relationships and attributes are represented in the example ERD diagrams.
This document discusses conceptual data modeling using the entity-relationship (ER) model. It defines key concepts of the ER model including entities, attributes, relationships, entity sets, relationship sets, keys, and ER diagrams. It explains how the ER model is used in the early conceptual design phase of database design to capture the essential data requirements and produce a conceptual schema that can be later mapped to a logical and physical database implementation.
The document provides an overview of entity-relationship (ER) modeling concepts used in database design. It defines key terms like entities, attributes, relationships, and cardinalities. It explains how ER diagrams visually represent these concepts using symbols like rectangles, diamonds, and lines. The document also discusses entity types, relationship degrees, key attributes, weak entities, and how to model one-to-one, one-to-many, many-to-one, and many-to-many relationships. Overall, the document serves as a guide to basic ER modeling principles for conceptual database design.
Data Structures & Recursion-Introduction.pdfMaryJacob24
This document provides an introduction to data structures and recursion. It defines data structures as organized collections of data and discusses common data structures like arrays, linked lists, stacks, and queues. Data structures are classified as primitive (like integers and characters) or non-primitive (like arrays and linked lists). Non-primitive structures are further divided into linear (arrays, linked lists) and non-linear (trees, graphs). Memory allocation techniques like static and dynamic allocation are also covered. The document concludes with an overview of recursion, including direct and indirect recursion, and examples of recursive functions like factorial and Fibonacci.
Data flow Diagram
In this presentation we are going to briefly
Describe what is DFD.
Why Should Use DFD ?
Components of a generic DFD.
Levels of DFD.
DFD with an example (SMS Mela).
This document discusses bi-connected components in graphs. It defines an articulation point as a vertex in a connected graph whose removal would disconnect the graph. A bi-connected component is a maximal subgraph that contains no articulation points. The document presents algorithms for identifying articulation points and bi-connected components in a graph using depth-first search (DFS). It introduces the concepts of tree edges, back edges, forward edges and cross edges in a DFS tree and explains how to use these edge types to determine if a vertex is an articulation point based on the minimum discovery time of its descendant vertices.
The document discusses object-oriented databases and the need for complex data types that traditional databases cannot support well. It covers the core concepts of the object-oriented data model including objects, classes, inheritance, and object identity. Key advantages of the object-oriented approach include its ability to model complex relationships and enable persistence of programming language objects.
Entity Relationship Diagrams (ERDs) are used to model relationships between entities in a database. The document discusses ERD components like entities, relationships, cardinality, and attributes. It provides an example of an ERD for a company with departments, supervisors, employees, and projects. Key entities are identified and their relationships and attributes are represented in the example ERD diagrams.
This document discusses conceptual data modeling using the entity-relationship (ER) model. It defines key concepts of the ER model including entities, attributes, relationships, entity sets, relationship sets, keys, and ER diagrams. It explains how the ER model is used in the early conceptual design phase of database design to capture the essential data requirements and produce a conceptual schema that can be later mapped to a logical and physical database implementation.
The document provides an overview of entity-relationship (ER) modeling concepts used in database design. It defines key terms like entities, attributes, relationships, and cardinalities. It explains how ER diagrams visually represent these concepts using symbols like rectangles, diamonds, and lines. The document also discusses entity types, relationship degrees, key attributes, weak entities, and how to model one-to-one, one-to-many, many-to-one, and many-to-many relationships. Overall, the document serves as a guide to basic ER modeling principles for conceptual database design.
Data Structures & Recursion-Introduction.pdfMaryJacob24
This document provides an introduction to data structures and recursion. It defines data structures as organized collections of data and discusses common data structures like arrays, linked lists, stacks, and queues. Data structures are classified as primitive (like integers and characters) or non-primitive (like arrays and linked lists). Non-primitive structures are further divided into linear (arrays, linked lists) and non-linear (trees, graphs). Memory allocation techniques like static and dynamic allocation are also covered. The document concludes with an overview of recursion, including direct and indirect recursion, and examples of recursive functions like factorial and Fibonacci.
Data flow Diagram
In this presentation we are going to briefly
Describe what is DFD.
Why Should Use DFD ?
Components of a generic DFD.
Levels of DFD.
DFD with an example (SMS Mela).
This document discusses bi-connected components in graphs. It defines an articulation point as a vertex in a connected graph whose removal would disconnect the graph. A bi-connected component is a maximal subgraph that contains no articulation points. The document presents algorithms for identifying articulation points and bi-connected components in a graph using depth-first search (DFS). It introduces the concepts of tree edges, back edges, forward edges and cross edges in a DFS tree and explains how to use these edge types to determine if a vertex is an articulation point based on the minimum discovery time of its descendant vertices.
The document discusses object-oriented databases and the need for complex data types that traditional databases cannot support well. It covers the core concepts of the object-oriented data model including objects, classes, inheritance, and object identity. Key advantages of the object-oriented approach include its ability to model complex relationships and enable persistence of programming language objects.
The document discusses Strassen's algorithm for matrix multiplication. It begins by explaining traditional matrix multiplication that has a time complexity of O(n3). It then explains how the divide and conquer strategy can be applied by dividing the matrices into smaller square sub-matrices. Strassen improved upon this by reducing the number of multiplications from 8 to 7 terms, obtaining a time complexity of O(n2.81). His key insight was applying different equations on the sub-matrix multiplication formulas to minimize operations.
Triggers are stored programs that are automatically executed in response to events like data manipulation language (DML) statements or database definition language (DDL) statements. They can be used for purposes like enforcing referential integrity, auditing, and event logging. The syntax to create a trigger includes keywords like BEFORE, AFTER, INSTEAD OF to specify when it should be executed in relation to a triggering statement. PL/SQL packages are used to group related logic, types, variables and subprograms. A package has a specification that declares its elements and a body that defines them. Packages provide a way to encapsulate and organize code.
This document defines SQL data definition statements and basic SQL query structure. It discusses DDL statements like CREATE, ALTER, and DROP that are used to define and manage database structures. It also explains the typical components of an SQL query including the SELECT, FROM, and WHERE clauses. Finally, it outlines several set operations in SQL like UNION, UNION ALL, INTERSECT, and MINUS.
Merge sort is a divide and conquer algorithm that works as follows:
1) Divide the array to be sorted into two halves recursively until single element subarrays are reached.
2) Merge the subarrays in a way that combines them in a sorted order.
3) The merging process involves taking the first element of each subarray and comparing them to place the smaller element in the final array until all elements are merged.
Merge sort runs in O(n log n) time in all cases making it one of the most efficient sorting algorithms.
A heap is a special tree-based data structure where the tree is a complete binary tree. There are two types of heaps: a max-heap where the root node has the greatest key, and a min-heap where the root node has the minimum key. Operations on heaps include insertion and deletion of nodes in O(log N) time and peeking the max/min element. Heapify is the process of building the heap from an array by comparing nodes to ensure the heap property is maintained.
The document discusses primary keys and foreign keys in entity relationship diagrams (ERDs). It defines a primary key as a unique identifier for each instance of an entity. A foreign key completes a relationship by identifying the parent entity and maintains referential integrity between entities. The document then provides an example of designing an ERD for a college, identifying the entities, relationships, keys, and other attributes to draw the complete diagram.
Welcome to my series of articles on Unified Modeling Language. This is "Session 10 – Sequence Diagram" of the series. Please view my other documents where I have covered each UML diagram with examples
Types Of Join In Sql Server - Join With Example In Sql Serverprogrammings guru
Do you know How many types of Joins in SQL. In this ppt presentation we are discussion about types of joins in sql server eg: INNER JOIN , SELF JOIN ,OUTER JOIN ,Right outer Join,Left outer Join,Full Outer Join,CROSS JOIN .
This presentation contains:
Definition of the group by, having and order by clauses
Examples with tables of the group by, having and order by clauses
SQL queries for the group by, having and order by clauses
Quicksort is a sorting algorithm that works by partitioning an array around a pivot value, and then recursively sorting the sub-partitions. It chooses a pivot element and partitions the array based on whether elements are less than or greater than the pivot. Elements are swapped so that those less than the pivot are moved left and those greater are moved right. The process recursively partitions the sub-arrays until the entire array is sorted.
The document discusses the relational data model and query languages. It provides the following key points:
1. The relational data model organizes data into tables with rows and columns, where rows represent records and columns represent attributes. Relations between data are represented through tables.
2. Relational integrity constraints include key constraints, domain constraints, and referential integrity constraints to ensure valid data.
3. Relational algebra and calculus provide theoretical foundations for query languages like SQL. Relational algebra uses operators like select, project, join on relations, while relational calculus specifies queries using logic.
This document provides information about tree data structures. It defines key tree terminology like root, parent, child, leaf node, internal node, subtree, and siblings. It also describes different types of trees like binary trees, binary search trees, threaded binary trees, and heaps. Common tree traversal algorithms like preorder, inorder, and postorder are explained. Priority queues and their representations using heaps are also discussed.
Trees are hierarchical data structures composed of nodes connected by edges. A tree has a root node with child nodes below it. Leaf nodes have no children, while internal nodes have children. Binary trees restrict nodes to having 0, 1, or 2 children. Binary search trees organize nodes so that all left descendants of a node are less than or equal to the node and all right descendants are greater than or equal. Common tree operations include insertion, searching, and deletion.
The document discusses activity diagrams, including their purpose, elements, notation, guidelines for creation, and an example. Activity diagrams can model tasks, system functions, and life cycles. Key elements include activities, transitions, decisions, and parallel paths. Notation includes rectangles for activities, arrows for transitions, diamonds for decisions, and bars for parallelism. Guidelines recommend setting context, identifying activities and flows, decisions, and parallelism. The example models scheduling appointments in a dentist office.
This document discusses one-dimensional arrays. It defines a one-dimensional array as a list of values with the same data type stored under a single name. Elements are stored in consecutive memory locations and can be accessed using the array name and index. Individual elements are referenced as array_name[index]. The size of an array is the number of elements, and the type refers to the data type of the values. Memory addresses for elements are calculated from the base address using the index and size. Examples are provided to demonstrate accessing elements and calculating memory addresses.
The document discusses SQL data manipulation topics including retrieving data using SELECT statements, filtering rows with WHERE clauses, sorting results with ORDER BY, grouping data with GROUP BY, restricting groups with HAVING, and using subqueries. It provides examples of each concept and rules for writing SQL statements and using different clauses.
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationBIT Durg
This document discusses key concepts in the Extended Entity Relationship (EER) model, including specialization, generalization, attribute inheritance, and aggregation. Specialization involves dividing a higher-level entity set into lower-level subsets, while generalization groups multiple lower-level entity sets into a single higher-level set based on common attributes. Attribute inheritance allows attributes to be passed from higher to lower levels. Aggregation models relationships between relationships by treating them as higher-level entities. The document provides examples and discusses constraints like disjointness and completeness that can be applied.
This document discusses deterministic and non-deterministic algorithms. A deterministic algorithm always produces the same output for a given input, while a non-deterministic algorithm may have multiple possible outputs for one input. Non-deterministic algorithms have two stages: a guessing stage that generates a potential solution, and a verification stage that checks if the guess is correct. Examples of non-deterministic algorithms given are a search algorithm that guesses a location containing the search value, and a sorting algorithm that guesses the sorted order of elements.
The document discusses different types of joins in database systems. It defines natural join, inner join, equi join, theta join, semi join, anti join, cross join, outer join including left, right and full outer joins, and self join. Examples are provided for each type of join to illustrate how they work.
An array is a collection of variables of the same type that are referenced using a common name and contiguous memory locations. One-dimensional arrays allow storing multiple variables of the same type under a single variable name. Linear/sequential search compares each element to the search key while binary search divides the array in half at each step to find the search key faster than linear search.
The document provides information about 1-D arrays including definitions, implementation, basic operations like insertion, deletion, searching, sorting, and merging. It defines a 1-D array as comprising finite homogeneous elements represented by an array name with lower and upper bounds. The size is calculated as upper bound - lower bound + 1. Implementation involves calculating an element's address using the base address and element size. Basic operations covered are insertion by adding an element at the end or in a sorted position, deletion by shifting elements, linear and binary searching, selection sort, bubble sort, insertion sort, and merging two sorted arrays. Worked examples at the end demonstrate searching using binary search and swapping the first and second half of an array.
The document discusses Strassen's algorithm for matrix multiplication. It begins by explaining traditional matrix multiplication that has a time complexity of O(n3). It then explains how the divide and conquer strategy can be applied by dividing the matrices into smaller square sub-matrices. Strassen improved upon this by reducing the number of multiplications from 8 to 7 terms, obtaining a time complexity of O(n2.81). His key insight was applying different equations on the sub-matrix multiplication formulas to minimize operations.
Triggers are stored programs that are automatically executed in response to events like data manipulation language (DML) statements or database definition language (DDL) statements. They can be used for purposes like enforcing referential integrity, auditing, and event logging. The syntax to create a trigger includes keywords like BEFORE, AFTER, INSTEAD OF to specify when it should be executed in relation to a triggering statement. PL/SQL packages are used to group related logic, types, variables and subprograms. A package has a specification that declares its elements and a body that defines them. Packages provide a way to encapsulate and organize code.
This document defines SQL data definition statements and basic SQL query structure. It discusses DDL statements like CREATE, ALTER, and DROP that are used to define and manage database structures. It also explains the typical components of an SQL query including the SELECT, FROM, and WHERE clauses. Finally, it outlines several set operations in SQL like UNION, UNION ALL, INTERSECT, and MINUS.
Merge sort is a divide and conquer algorithm that works as follows:
1) Divide the array to be sorted into two halves recursively until single element subarrays are reached.
2) Merge the subarrays in a way that combines them in a sorted order.
3) The merging process involves taking the first element of each subarray and comparing them to place the smaller element in the final array until all elements are merged.
Merge sort runs in O(n log n) time in all cases making it one of the most efficient sorting algorithms.
A heap is a special tree-based data structure where the tree is a complete binary tree. There are two types of heaps: a max-heap where the root node has the greatest key, and a min-heap where the root node has the minimum key. Operations on heaps include insertion and deletion of nodes in O(log N) time and peeking the max/min element. Heapify is the process of building the heap from an array by comparing nodes to ensure the heap property is maintained.
The document discusses primary keys and foreign keys in entity relationship diagrams (ERDs). It defines a primary key as a unique identifier for each instance of an entity. A foreign key completes a relationship by identifying the parent entity and maintains referential integrity between entities. The document then provides an example of designing an ERD for a college, identifying the entities, relationships, keys, and other attributes to draw the complete diagram.
Welcome to my series of articles on Unified Modeling Language. This is "Session 10 – Sequence Diagram" of the series. Please view my other documents where I have covered each UML diagram with examples
Types Of Join In Sql Server - Join With Example In Sql Serverprogrammings guru
Do you know How many types of Joins in SQL. In this ppt presentation we are discussion about types of joins in sql server eg: INNER JOIN , SELF JOIN ,OUTER JOIN ,Right outer Join,Left outer Join,Full Outer Join,CROSS JOIN .
This presentation contains:
Definition of the group by, having and order by clauses
Examples with tables of the group by, having and order by clauses
SQL queries for the group by, having and order by clauses
Quicksort is a sorting algorithm that works by partitioning an array around a pivot value, and then recursively sorting the sub-partitions. It chooses a pivot element and partitions the array based on whether elements are less than or greater than the pivot. Elements are swapped so that those less than the pivot are moved left and those greater are moved right. The process recursively partitions the sub-arrays until the entire array is sorted.
The document discusses the relational data model and query languages. It provides the following key points:
1. The relational data model organizes data into tables with rows and columns, where rows represent records and columns represent attributes. Relations between data are represented through tables.
2. Relational integrity constraints include key constraints, domain constraints, and referential integrity constraints to ensure valid data.
3. Relational algebra and calculus provide theoretical foundations for query languages like SQL. Relational algebra uses operators like select, project, join on relations, while relational calculus specifies queries using logic.
This document provides information about tree data structures. It defines key tree terminology like root, parent, child, leaf node, internal node, subtree, and siblings. It also describes different types of trees like binary trees, binary search trees, threaded binary trees, and heaps. Common tree traversal algorithms like preorder, inorder, and postorder are explained. Priority queues and their representations using heaps are also discussed.
Trees are hierarchical data structures composed of nodes connected by edges. A tree has a root node with child nodes below it. Leaf nodes have no children, while internal nodes have children. Binary trees restrict nodes to having 0, 1, or 2 children. Binary search trees organize nodes so that all left descendants of a node are less than or equal to the node and all right descendants are greater than or equal. Common tree operations include insertion, searching, and deletion.
The document discusses activity diagrams, including their purpose, elements, notation, guidelines for creation, and an example. Activity diagrams can model tasks, system functions, and life cycles. Key elements include activities, transitions, decisions, and parallel paths. Notation includes rectangles for activities, arrows for transitions, diamonds for decisions, and bars for parallelism. Guidelines recommend setting context, identifying activities and flows, decisions, and parallelism. The example models scheduling appointments in a dentist office.
This document discusses one-dimensional arrays. It defines a one-dimensional array as a list of values with the same data type stored under a single name. Elements are stored in consecutive memory locations and can be accessed using the array name and index. Individual elements are referenced as array_name[index]. The size of an array is the number of elements, and the type refers to the data type of the values. Memory addresses for elements are calculated from the base address using the index and size. Examples are provided to demonstrate accessing elements and calculating memory addresses.
The document discusses SQL data manipulation topics including retrieving data using SELECT statements, filtering rows with WHERE clauses, sorting results with ORDER BY, grouping data with GROUP BY, restricting groups with HAVING, and using subqueries. It provides examples of each concept and rules for writing SQL statements and using different clauses.
Dbms Notes Lecture 9 : Specialization, Generalization and AggregationBIT Durg
This document discusses key concepts in the Extended Entity Relationship (EER) model, including specialization, generalization, attribute inheritance, and aggregation. Specialization involves dividing a higher-level entity set into lower-level subsets, while generalization groups multiple lower-level entity sets into a single higher-level set based on common attributes. Attribute inheritance allows attributes to be passed from higher to lower levels. Aggregation models relationships between relationships by treating them as higher-level entities. The document provides examples and discusses constraints like disjointness and completeness that can be applied.
This document discusses deterministic and non-deterministic algorithms. A deterministic algorithm always produces the same output for a given input, while a non-deterministic algorithm may have multiple possible outputs for one input. Non-deterministic algorithms have two stages: a guessing stage that generates a potential solution, and a verification stage that checks if the guess is correct. Examples of non-deterministic algorithms given are a search algorithm that guesses a location containing the search value, and a sorting algorithm that guesses the sorted order of elements.
The document discusses different types of joins in database systems. It defines natural join, inner join, equi join, theta join, semi join, anti join, cross join, outer join including left, right and full outer joins, and self join. Examples are provided for each type of join to illustrate how they work.
An array is a collection of variables of the same type that are referenced using a common name and contiguous memory locations. One-dimensional arrays allow storing multiple variables of the same type under a single variable name. Linear/sequential search compares each element to the search key while binary search divides the array in half at each step to find the search key faster than linear search.
The document provides information about 1-D arrays including definitions, implementation, basic operations like insertion, deletion, searching, sorting, and merging. It defines a 1-D array as comprising finite homogeneous elements represented by an array name with lower and upper bounds. The size is calculated as upper bound - lower bound + 1. Implementation involves calculating an element's address using the base address and element size. Basic operations covered are insertion by adding an element at the end or in a sorted position, deletion by shifting elements, linear and binary searching, selection sort, bubble sort, insertion sort, and merging two sorted arrays. Worked examples at the end demonstrate searching using binary search and swapping the first and second half of an array.
Strings are arrays of characters that are null-terminated. They can be manipulated using functions like strlen(), strcpy(), strcat(), and strcmp(). The document discusses initializing and reading strings, passing strings to functions, and using string handling functions to perform operations like copying, concatenating, comparing, and reversing strings. It also describes arrays of strings, which are 2D character arrays used to store multiple strings. Examples are provided to demonstrate reading and sorting arrays of strings.
A string in C is an array of characters that ends with a null character '\0'. Strings are stored in memory as arrays of characters with the null character added to the end. Common string operations in C include declaring and initializing strings, reading strings from users, and built-in string handling functions like strlen(), strcpy(), strcat(), and strcmp().
The document discusses different types of arrays. An array is a collection of consecutive memory locations with the same name and data type. Arrays allow storing multiple values under a single name. The key types are one-dimensional, two-dimensional, and multi-dimensional arrays. One-dimensional arrays store elements in a linear list, while two-dimensional arrays can be visualized as a table with rows and columns. The document also covers array initialization, accessing elements, searching, sorting, and provides examples of one-dimensional and two-dimensional arrays.
This document discusses one-dimensional and multi-dimensional arrays. It defines arrays as data structures that can hold multiple values of the same type stored consecutively in memory. One-dimensional arrays use a single set of indexes, while multi-dimensional arrays have two or more indexes to access elements. The document provides syntax examples and demonstrates how to initialize, read from, and display one-dimensional and multi-dimensional arrays. It also lists some example programs involving arrays.
The document discusses various concepts related to arrays in C/C++ including:
- What an array is and its key properties like contiguous memory locations and common data type
- Different types of arrays like single dimensional and multi dimensional
- How to declare, initialize and access array elements
- Passing arrays to functions
- Searching and sorting arrays
- Common array operations like insertion and deletion
The document discusses arrays in C language. It defines an array as a data structure that stores a collection of similar data types. An array is declared by specifying the data type, array name, and size/number of elements. Once declared, an array's size cannot be changed. Elements can be accessed via their index. Multidimensional arrays store elements in multiple dimensions and are accessed using two or more indices.
The document discusses divide and conquer algorithms. It explains that divide and conquer algorithms follow three steps: 1) divide the problem into subproblems, 2) conquer the subproblems by solving them recursively, and 3) combine the results to solve the original problem. Binary search, merge sort, and quicksort are provided as examples of divide and conquer algorithms. Binary search divides a sorted array in half at each step to search for a target value. Merge sort divides the array in half, recursively sorts the halves, and then merges the sorted halves. Quicksort chooses a pivot to partition the array into left and right halves, recursively sorts the halves, and returns the fully sorted array.
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDev Chauhan
Arrays, stacks, queues, and linked lists are common data structures in computer science. Arrays allow direct access to elements but have fixed size, while linked lists can dynamically grow and shrink but require traversing nodes sequentially. Stacks follow LIFO (last in first out) and queues follow FIFO (first in first out) ordering for inserting and removing elements. Linked lists store data in nodes that link to the next node, allowing efficient insertion/removal anywhere in the list. Common operations on these structures include push/pop for stacks, enqueue/dequeue for queues, and insert/delete nodes for linked lists.
data structure and algorithm Array.pptx btech 2nd yearpalhimanshi999
The document discusses arrays and algorithms. It begins by defining arrays as lists of homogeneous data elements referenced by indices. Linear arrays are one-dimensional while multi-dimensional arrays include matrices. Common array operations like traversal, insertion, deletion and searching algorithms like linear and binary search are described. For linear search, the best, average and worst case complexities are analyzed to be O(1), O(n/2) and O(n) respectively. Binary search is more efficient, having a complexity of O(log n) as it halves the search space on each comparison. Examples and pseudocode are provided to illustrate key concepts.
This document discusses different sorting algorithms including insertion sort, selection sort, and shell sort. It provides examples of how each algorithm works and pseudocode for implementation. Insertion sort iterates through an array and inserts each element into its sorted position. Selection sort finds the minimum element in each pass and swaps it into the front. Shell sort improves on insertion sort by comparing elements separated by gaps to sort sublists and gradually reduce the gaps.
A one-dimensional array stores elements linearly such that they can be accessed using an index, the document provides an example of finding the address of an element in a 1D array and taking user input to store in an array and display all elements, and abstract data types provide only the interface of a data structure without implementation details.
The document discusses various operations that can be performed on arrays, including traversing, inserting, searching, deleting, merging, and sorting elements. It provides examples and algorithms for traversing an array, inserting and deleting elements, and merging two arrays. It also discusses two-dimensional arrays and how to store user input data in a 2D array. Limitations of arrays include their fixed size and issues with insertion/deletion due to shifting elements.
This document describes the array-based representation of linear lists as a data structure. It defines a linear list as a collection of elements in the form (e1, e2, ..., en) where ei is an individual element and n is the length of the list. An array is used to store the elements, where the ith element is stored at location i-1. It then provides code for a LinearList class that implements basic linear list operations like find, search, delete, insert using this array-based representation in O(1) or O(n) time.
The document discusses 2D arrays including their definition, implementation, and how to calculate the address of elements. It covers storing arrays in row-major and column-major order and includes formulas to calculate addresses based on the lower and upper bounds. Operations on 2D arrays like addition, subtraction, and multiplication are also explained. Some example problems are provided at the end to demonstrate calculating addresses of elements in 2D arrays stored in both row-major and column-major order.
The document discusses 2D arrays, including their definition as an array of arrays, implementation methods of row-major and column-major ordering, and formulas for calculating element addresses based on storage method. It also covers basic arithmetic operations on 2D arrays like addition, subtraction, and multiplication. Examples of problems involving 2D arrays and their solutions are provided.
The document discusses various sorting algorithms including insertion sort, selection sort, bubble sort, merge sort, and quick sort. It provides detailed explanations of how each algorithm works through examples using arrays or lists of numbers. The key steps of each algorithm are outlined in pseudocode to demonstrate how they sort a set of data in either ascending or descending order.
The document discusses arrays in C programming language. It defines an array as a collection of items stored at contiguous memory locations that can be accessed randomly using indices. Arrays allow storing homogeneous data in an organized linear structure. The key points covered include: declaration and initialization of arrays; accessing array elements; advantages like easy traversal and sorting; disadvantages like fixed size; and examples of one-dimensional and two-dimensional arrays. Common array operations like searching, sorting and traversal algorithms are also explained.
The document discusses different searching algorithms like linear search and binary search. It explains the time complexity of linear search is O(n) in the worst case while binary search has a time complexity of O(log n). The document also covers multidimensional arrays and matrix multiplication algorithms.
The document introduces algorithms for sorting and searching tasks. It discusses sequential search, binary search, selection sort, bubble sort, merge sort, and quick sort algorithms. For each algorithm, it provides pseudocode to describe the steps, an example, and analysis of time complexity in the best, worst and average cases. The time complexities identified are Θ(n) for sequential search average case, Θ(log n) for binary search, Θ(n2) for selection, bubble and quick sort worst cases, and Θ(n log n) for merge and quick sort average cases.
Insertion sort and merge sort are discussed. Insertion sort works by inserting elements in the proper position one by one. Its worst case time is O(N^2). Merge sort uses a divide and conquer approach to sort elements. It divides the list into halves, recursively sorts the halves, and then merges the sorted halves. Merging two sorted lists takes linear time. The overall time for merge sort is O(N log N). Heaps are discussed as a way to implement priority queues. A heap has the heap property where a node is always less than its children. This allows finding the minimum element and deleting it to take O(log N) time.
The document discusses arrays and their representation in memory. It contains 3 main points:
1) It introduces linear arrays and how they are represented in memory with sequential and contiguous locations. It also discusses multidimensional arrays.
2) It provides algorithms for common linear array operations like traversing, inserting, deleting and searching using binary search. It explains how each algorithm works through examples.
3) It discusses how 2D arrays are represented in memory and visualized, using an example of storing student exam marks in a 2D array.
The document discusses and compares several sorting algorithms: bubble sort, selection sort, insertion sort, merge sort, and quick sort. For each algorithm, it provides an explanation of how the algorithm works, pseudocode for the algorithm, and an analysis of the time complexity. The time complexities discussed are:
Bubble sort: O(N^2) in worst case, O(N) in best case
Selection sort: O(N^2)
Insertion sort: O(N^2) in worst case, O(N) in best case
Merge sort: O(N log N)
Quick sort: O(N log N) on average
The document discusses arrays and sparse matrices as data structures. It defines array and sparse matrix abstract data types, including methods for creating, accessing, and manipulating the structures. Examples are given of representing polynomials using arrays or as a sparse matrix to illustrate different implementations of these data structures.
Mergesort is a divide and conquer algorithm that works as follows:
1) Recursively sort the left and right halves of the array.
2) Merge the two sorted halves into a new sorted array.
3) Repeat until the entire array is sorted.
It has superior time complexity of O(n log n) in all cases but requires O(n) additional space for the auxiliary array used during merging.
The document discusses algorithms and their analysis. It begins by defining an algorithm and key aspects like correctness, input, and output. It then discusses two aspects of algorithm performance - time and space. Examples are provided to illustrate how to analyze the time complexity of different structures like if/else statements, simple loops, and nested loops. Big O notation is introduced to describe an algorithm's growth rate. Common time complexities like constant, linear, quadratic, and cubic functions are defined. Specific sorting algorithms like insertion sort, selection sort, bubble sort, merge sort, and quicksort are then covered in detail with examples of how they work and their time complexities.
Concatenation of two strings using class in c++Swarup Boro
This C++ program defines a class called "str" that represents strings as private character array members. It overloads the + operator as a friend function to concatenate two "str" objects by calling strcat() on their character arrays and returning a new "str" object. The main function demonstrates creating "str" objects from input strings, concatenating two of them by calling the overloaded + operator, and printing out the result.
Program: Inheritance in Class - to find topper out of 10 studentsSwarup Boro
Write a program that has a class student to store details of the students in a class. Derive another class topper from student that store records of only top three students of the class
This program uses recursion to print the elements of an array. It takes in the array, number of elements, and initial index as parameters for the recursive function. The function prints the element at the current index, increments the index, and calls itself until the index equals the number of elements, at which point it returns without printing or recursing further.
Binary addition using class concept in c++Swarup Boro
Binary addition of two binary numbers using class, object oriented concept in c++
Q. Program to print the sum of two binary numbers by taking two user inputs
Study of Diffusion of solids in Liquids Swarup Boro
The student conducted experiments to study the diffusion of solids in liquids. They found that (1) when solids like copper sulfate come into contact with water, diffusion occurs as intermixing of the substances, (2) the rate of diffusion increases with increasing temperature, and (3) smaller solid particles diffuse more quickly than larger particles. The experiments demonstrated how temperature, particle size, and other factors influence the rate at which solids diffuse into liquids.
Program to sort array using insertion sortSwarup Boro
This program uses insertion sort to sort an array of integers. It prompts the user to enter the number of elements for the array, then collects the elements from the user. It then calls the inssort function, passing the array and size. The inssort function iterates through the array, inserting each element into the sorted portion by shifting greater elements to the right. It prints the array after each pass to show the sorting progress. After sorting, it prints the final sorted array.
This C++ program asks the user to input two numbers, adds them together, divides the sum by 2 to calculate the average, and displays the average to the user. It uses basic input/output functions like cout, cin, and getch() to prompt the user for input, calculate the average of the two numbers, and output the result.
This C++ program finds the factorial of a user-input number. It prompts the user to enter an integer, initializes variables to track the number, factorial, and counter, then uses a while loop to multiply the factorial by each descending integer from the number down to 1. It finally displays the calculated factorial.
The document contains code for a C++ program that manages a canteen inventory and purchase system. It allows users to view the menu, purchase items, view purchase details and available quantities. The program tracks inventory quantities, calculates totals for purchases and provides a receipt. It also has options to add new customers or view instructions.
This C++ program defines a Student class with private data members like roll number, name, marks, and grade. It has public member functions to read student details, display student details, get roll number, and get marks. The calcGrade() function calculates the grade based on marks. The main() function creates an array of 10 Student objects, reads their details, and provides a menu to display details of a specific student by roll number or the topper. It loops until the user exits.
This document contains C++ code for a railway reservation system. It defines classes for login credentials, train details, reservations, cancellations, and performs functions like reserving tickets, cancelling reservations, and displaying train/passenger information from databases. The main function displays a menu and calls additional functions for administrative tasks, user login, reservation, cancellation etc. based on user input. Databases are maintained using file streams to store and retrieve object data from files.
Classes and objects are key concepts in C++. A class defines the data and functions that can act on that data, while an object is an instance of a class. Classes contain public and private members to control access and promote reusability. Common tasks like initializing data, cleaning up memory, and accessing members are handled through constructors, destructors, and methods. Well-designed classes encapsulate data and behavior to be reused across programs while hiding implementation details. Examples demonstrate defining classes for counters, checkbooks, cans, and using built-in classes like string and file streams.
Constructor and Destructor
Constructors are member functions that initialize objects of a class. They are automatically called when an object is created. Destructors are member functions that perform cleanup actions for an object and are called automatically when an object is destroyed.
Some key points about constructors include: they have no return type; they are used to initialize objects; and they can be overloaded. Destructors also have no return type, are called automatically for cleanup, and follow the usual access rules as other member functions. Copy constructors make deep copies of objects and are important for memory management.
Inheritance allows new classes called derived classes to inherit features from existing classes called base classes. This provides code reuse and
Arrays allow storing multiple values of the same type under one common name. They come in one-dimensional and two-dimensional forms. One-dimensional arrays store elements indexed with a single subscript, while two-dimensional arrays represent matrices with rows and columns indexed by two subscripts. Arrays can be passed to functions by passing their name and size for numeric arrays, or just the name for character/string arrays since strings are null-terminated. Functions can operate on arrays to perform tasks like finding the highest/lowest element or reversing a string.
The document discusses pointers in C++. It defines a pointer as a variable that stores the memory address of another variable of the same data type. Pointers allow a program to indirectly access the memory location of another variable. The key points covered include:
- Declaring pointer variables using a data type followed by an asterisk (*)
- Initializing pointers using the address-of (&) operator to store the address of another variable
- Accessing the value at a pointer's address using the dereference (*) operator
- Pointer arithmetic, where pointers can be incremented or decremented to access subsequent memory addresses
- Dynamic memory allocation using new/delete to allocate memory at runtime through a pointer.
A queue is a first-in, first-out (FIFO) data structure where insertion is done at the rear end and deletion is done at the front end. It can be implemented using either an array or linked list. Basic operations on a queue include enqueue, which inserts an item at the rear, and dequeue, which removes an item from the front. A circular queue addresses the issue of empty spaces in a linear queue by connecting the rear end to the front so the queue can migrate in a circular fashion.
This document discusses structures in C++. It defines a structure as a collection of variables under a single name where the variables can be of different data types. It provides an example of declaring a structure with three variables of different types. It also discusses how to declare a structure variable which allocates memory, and how to access structure members using the dot operator. The document notes that structures can be nested within other structures and that arrays can contain structures or structures can contain arrays. It discusses passing structures to functions by value and by reference. Finally, it briefly introduces typedef, enumerated data types, and practice questions related to structures.
The document discusses stacks, which are linear data structures that follow the LIFO (last in, first out) principle. Stacks can be implemented using arrays or linked lists. Elements are inserted and removed only from one end, called the top of the stack. Insertion is called pushing and removal is called popping. Stacks are used extensively in computer systems, for example in operating system function calls and interrupt handling. The Java programming language contains a Stack class that can be used by programmers.
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
Thinking of getting a dog? Be aware that breeds like Pit Bulls, Rottweilers, and German Shepherds can be loyal and dangerous. Proper training and socialization are crucial to preventing aggressive behaviors. Ensure safety by understanding their needs and always supervising interactions. Stay safe, and enjoy your furry friends!
Strategies for Effective Upskilling is a presentation by Chinwendu Peace in a Your Skill Boost Masterclass organisation by the Excellence Foundation for South Sudan on 08th and 09th June 2024 from 1 PM to 3 PM on each day.
How to Build a Module in Odoo 17 Using the Scaffold MethodCeline George
Odoo provides an option for creating a module by using a single line command. By using this command the user can make a whole structure of a module. It is very easy for a beginner to make a module. There is no need to make each file manually. This slide will show how to create a module using the scaffold method.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
This presentation was provided by Steph Pollock of The American Psychological Association’s Journals Program, and Damita Snow, of The American Society of Civil Engineers (ASCE), for the initial session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session One: 'Setting Expectations: a DEIA Primer,' was held June 6, 2024.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
1. Page 1 of 14
Array
Areas Covered on:
1- D ARRAY
. Definition of 1-D
array.
Implementation of 1-D
array
Basic operations of 1-D
array
Insertion & Deletion
. Searching
Sorting
. Merging
1-D Array Definations:
One dimensional array comprise of finite homogeneous elements represented as:
Array name [Lower bound L, Upper bound U] ranges from L through U.
To calculate array size (length) =U-L+1
Ex: Ar [-9, 15]
Size=15-(-9) +1=23
Implementation of 1-D array:
It is done to calculate address of any element in an array.
Address of element with subscript I=Base address +ES (I-L)
Where ES is size of an array element
L is the lower bound of the array.
Prepared By Sumit Kumar Gupta, PGT Computer Science
2. Page 2 of 14
Basic operations of 1-D array:--1. Insertion & Deletion
2. Searching
3. Sorting
4. Merging
Insertion: placing of new element within the existing array.
Insertion is done in two ways:
i) If the array is unordered, placing the new element at the end of the array.
ii)if the array is sorted then new element is added at appropriate position.
Algorithm:
1.ctr=L
2.If LST=U then
{
Print “Overflow:”
Exit from program
}
3. if AR[ctr]>ITEM then
Pos=1
Else
{
4. Repeat steps 5 and 6 until ctr>=U
5. if AR[ctr]<=ITEM and ITEM<=AR[ctr+1] then
{ Pos=ctr+1
Break
}
6. ctr=ctr+1
/*end of repeat here*/
7. if ctr=U then
Pos=U+1
}
/*end of if step 3 */
/* shift the element to create space*/
8. ctr=U
9.while ctr>=pos perform steps 10 through 11
10.AR[ctr+1]=AR[ctr]
Prepared By Sumit Kumar Gupta, PGT Computer Science
3. Page 3 of 14
11.ctr=ctr=ctr-1
}
12. AR[pos]=ITEM
13. END
Using Function:
int FindPos(int AR[],int size,int item) /*to determine the position for element
{
int pos;
if(item<AR[0]) pos=0;
else
{
for(int i=0;i<size-1;i++)
{
if(AR[i]<=item && item <AR[i+1]
{
Pos=i+1;
Break;
}
if(i==size-1) pos=size;
}
return pos;
}
Deletion:
To delete an element from existing array.
Algorithm:
/*considering that Item’s search in array AR is successful at location pos*/
Two cases arises:
Case1: Shifting Upward or left side
1. ctr=pos
2. Repeat steps 3 and 4 until ctr>=U
3. AR [ctr] =AR [ctr-1]
4. ctr=ctr+1
Prepared By Sumit Kumar Gupta, PGT Computer Science
4. Page 4 of 14
/*end of repeat*/
Case II: shifting downwards (or in right side)
1. Ctr=pos
2. Repeat steps 3 and 4 until Ctr<=L
3.AR[ctr]=AR[ctr-1]
4.ctr=ctr-1
/*End of Repeat*/
Searching:
Linear search:
Linear search method is used to scan the array in a sequential
manner.Under this method the whole array is searched one by one until the
matching element is obtained .
Note: Linear search is done in Unordered array.
Algorithm:
/*Initialise counter by assigning lower bound value of the array*/
Step1:Set ctr=L
(Lower bound=0 in c++)
/*Now search for the ITEM*/
Step2: Repeat steps 3 through 4 until ctr>U //Upper Bound(U) is size-1
Step3: if AR [ctr]==ITEM then
{
Print “search Successful”
Print ctr,”is the location of”,ITEM
Break
}
Step 4: ctr=ctr+1
/*End of repeat*/
Step 5 if ctr>U then
Print “search Unsuccessful!”
Step 6 END
Using Function:
Int LSearch(int AR[],int size,int item)
{
For(int i=0;i<size;i++)
{
Prepared By Sumit Kumar Gupta, PGT Computer Science
5. Page 5 of 14
If(AR[i]==item)
return i;
}
return -1;
}
Binary search:
Steps:To search for ITEM in sorted array (in ascending order)
1. ITEM is compared with middle element of the segment(i.e,in the entire
array for the first time).
2.If the ITEM is more than the middle element ,latter part of the segment
becomes new segment to be scanned.
3.The same process is repeated for the new segment(s) until the item is
found(search successful) or the segment is reduced to the single element and
the ITEM is not found(search Unsuccessful).
Condition: Array should be in sorted manner
Using Function:
int Bsearch(int AR[10], int I, int N)
{
int beg=0, last = N-1,Mid;
While(beg<=last)
{
Mid =(beg+last)/2;
If (AR[Mid]==I)
Return 1;
Else if (I > AR[Mid])
Beg=Mid+1;
Else
Last=Mid-1;
}
return 0;
}
Sorting:
Selection Sorting:
Steps:
Prepared By Sumit Kumar Gupta, PGT Computer Science
6. Page 6 of 14
Pass-1 Find the location LOC of the smallest in the list of n elements.
a[1],a[2],……..a[n],then interchange a[loc]with a[1].
Pass-2 Find the location LOC and then interchanged a [LOC] and a [2].since
a[1]<=a[2]
Pass-3 Find the location LOC of the smallest in the sublist of n-2 elements.
a [3],a[4],……a[n], and then interchanged a[LOC] and a[3].Then
a[1],a[2]….a[3] is stored, since a[2]<=a[3]
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Pass N-1: Find the location LOC of the smallest of the elements a[n-],a[n] and
interchanged a[LOC] and a[n-1].Then:
a [1],a[2]….a[n] is strored, since a[n-1]<=a[n]
Thus a is sorted after n-1 passes
Algorithm:
1. small=AR[L]
2. For i=L to U do
{
3.
small=AR[i]
4.
for J=I to U do
{
5.
If AR[j]<small then
6.
{
Small==AR[j]
7.
Pos=j
}
j=j+1;
}
//In c++ ,0 to size-1
/*end of inner loop*/
/*swap the smallest element with ith element */
8. temp=AR[i]
9. AR[i]=small
10. AR[pos]=temp
}
11. END
Prepared By Sumit Kumar Gupta, PGT Computer Science
7. Page 7 of 14
Using Function :
Void SelSort(int AR[],int size)
{
int small, pos,tmp;
for(int i=0;i<size;i++)
{
small=AR[i];
for(int j=i+1;j<size;j++)
{
if(AR[j]<small)
{
small=AR[j];
pos=j;
}
}
tmp=AR[i];
AR[i]=AR[pos];
AR[pos]=tmp;
cout<<”n Array after pass –“<<i+1<<”—is :”;
for(j=0;j<size;j++)
cout<<AR[j]<<””;
}
}
Bubble Sort
The basic idea of bubble sort is to compare two adjoining values and exchange them
if they are not in proper order.
Algorithm:
1. For I=L to U
2. {
For j=to [(U-1)-I]
{
Prepared By Sumit Kumar Gupta, PGT Computer Science
8. Page 8 of 14
3.
If AR[j]>AR[j+1] then
{
temp=AR[j]
AR[j]=AR[j+1]
AR[j+1]=temp
}
4.
5.
6.
}
}
7.
END
Using Function
Void BubbleSort(int AR[],int size)
{
int tmp,ctr=0;
for(int i=0;i<size;i++)
{
for (int j=0;j<(size-1)-i;j++)
{
if(AR[j]<AR[j+1])
{
tmp=AR[j];
AR[j]=Ar[j+1];
AR[j+1]=tmp;
}
}
cout<<”Array after iteration—“<<++ctr<<”--: “;
for(int k=0;k<size;k++)
cout<<AR[k]<<””;
cout<<endl
}
}
Insertion sorting:
Condition: Introduce a sentinel element A [0] = - ∞ (or a very small number)
An insertion sort is one that sorts a set of values by inserting values into an
existing sorted file.
Prepared By Sumit Kumar Gupta, PGT Computer Science
9. Page 9 of 14
The insertion sort algorithm scans array a from a[1] to a[n], inserting each
element
A[k] into its proper position on the previously sorted subarray a [1],a [2]...a [k1].
Using Function:
Void InsSort (int AR [], int size)
{
int tmp,j;
AR [0] =INT_MIN;
for (int i=1;i<=size;i++)
{
tmp=AR[i];
j=i-1;
while(tmp<AR[j])
{
AR[j+1]=AR[j];
j--;
}
AR[j+1]=tmp;
cout<<”Array after iteration—“<<++ctr<<”--: “;
for (int k=0;k<size;k++)
cout<<AR[k]<<””;
cout<<endl;
}
}
Merging:
Merging means combining elements of two arrays to form a new array.
Merging in array
/* Merging of two array A and B where A is in ascending order ,B is in ascending
order and resultant array C will be in Ascending
ctr A=L1
ctr B=L2
ctr C=L3
while (ctr A<=U1) &&( ctr B<=U2)
{
If(A[ctr A]<=B[ctr B]) then
Prepared By Sumit Kumar Gupta, PGT Computer Science
10. Page 10 of 14
{
C[ctr C]=A[ctr A]
ctr C=ctr C + 1
ctr A=ctr A+1
}
else
{
C[ctr C]=B[ctr B]
ctr C=ctr C+1
ctr B=ctr B+1
}/*end of while loop
If(ctr A >U1) then
{
While(ctr B <=U2)
{
C[ctrC]=B[ctr B]
ctrC=ctrC+1
ctr B=ctr B+1
}
}
If(ctr B>U2) then
{
While (ctr A<=U1)
{
C[ctr C]=A[ctr A]
ctr C=ctr C+1
ctr A=ctr A+1
}
}
There are some other cases are also possible .These cases are taken place in
following situations:
1. When array A[n] is in Acsending order then its control variable ,say ctr A
,should be initialized with array’s lower bound ,which is 0(zero).And the test
condition will be ctr<n.
2. When an array ,say A[n] ,is in descending order,then its control variable ,say
ctr A ,should be initialized with array’s upper bound,which is n-1.
Prepared By Sumit Kumar Gupta, PGT Computer Science
11. Page 11 of 14
Assuming length of array A is M and Length of array B is N-1 . Thus array A has
elements A[0] to A[N-1] and B has elements B[0] to B[N-1] .let the resultant array be
C with length 10.
CtrB=n-1 , ctrA=0 , ctrC=0
while (ctrC<5) do
{
C[ctrC]=A[ctrA]
ctrC=ctrC+1
ctrA=ctrA+1
}
while (ctrC<10) do
{ C[ctrC]=B[ctrB]
ctrC=ctrC+1
ctrB=ctrB-1
}
ctrC=0
while(ctrC<10) do
{
print C[ctrC]
ctrC= ctrC+1
}
END
Solved Examples:
Q.1 What do you understand by Data Structure. Describe about the types of data
structure
Ans A data Structure is a named group of data of different data types which can be
processed as single unit.
There are two types of data structure
a. Simple :- i. Array ii. Structure
b. Complex
i. Linear :- i.Stack ii. Queue iii. Linked-list
ii. Non-Linear : Tree
Q.2What will be the address of 5th element in a floating point array implemented in
C++?The array is specified as amount[16].the base address of the array is 1058.
Ans) Standard size of floating-point array=4 bytes
5th element in the array Amount is specified as Amount[4] as the index numbers
in c++ starts from 0.
Address of Amount[4]=base address +es(I-L)
L=0
Prepared By Sumit Kumar Gupta, PGT Computer Science
12. Page 12 of 14
Es=4
Base Address=1058
Putting all these values,
Address of Amount[4]=1058+4(4-0)=1074
Q.3 Suppose a one dimentional Array AR containing integers is arranged in
ascending order .Write a user defined function in C++ to search for one integer
from AR with the help of Binary Search Method , returning an integer 0 to show
absence of the number and 1 to show the presence of the number in the array. The
function should have three parameters (1. an array AR 2. the number to be
searched 3. the number of elements N)
Ans. Int Bsearch(int AR[10], int I, int N)
{
int beg=0, last = N-1,Mid;
While(beg<=last)
{
Mid =(beg+last)/2;
If (AR[Mid]==I)
Return 1;
Else if (I > AR[Mid])
Beg=Mid+1;
Else
Last=Mid-1;
}
return 0;
}
Practice also For Descending order
Q.4 Write a function in C++ which accepts an integer array and its size as
arguments and exchange the values of first half side element with the second half
elements of the array. Example if an array of 10 elements has initial content
12,15,45,23,34,43,77,46,35,47
The resultant array should be like this 43,77,46,35,47,12,15,45,23,34
Ans void swap( int A[ ] ,int size)
{
int I,j,temp,mid=size/2;
if (size %2 = = 0)
j=mid ;
else
j=mid+1;
for(i=0;i<mid;i++,j++)
{
temp= A[i];
Prepared By Sumit Kumar Gupta, PGT Computer Science
13. Page 13 of 14
A[i]=A[j];
A[j]=temp;
}
}
5. Write an Algorithm for Selection Sort .
Ans :
1. small=AR[L]
2. for i= L to U loop
3. { small = AR[i]
4. for j = I to U
do
5. { if AR[j] < small then
6. { small = AR[j]
7. pos = j
}
8. j = j + 1
}
9. temp = AR[i]
10. AR[i] = small
11. AR[pos] = temp
}
12. end
Q.6 An algorithm requires two stacks of size M and N that are to be
maintained in the memory .Illustrate with an example how will you adjust two
stacks in one dimensional array with M+N memory locations so that the overflow
condition is minimized .
Ans . let us say that the stack A is with size M and Stack B with size N
If the stack A is stored in locations 0 to M-1 and the stack B is stored in locations
M to M+N-1 ,the separate areas for the two are ensured .in the beginning the tops of the
stacks are at opposite ends . when Top A reaches at M-1 , any further insertion will lead
to overflow in stack A and when Top B reaches at M. any further insertion in stack B will
lead to overflow.
Q.7 Given two arrays A and B ,copy last five element of B after first five element of
A to create another array C. Assume length of A and B is greater than 5.(Merge
Sort)
Ans Assuming length of array A is M and Length of array B is N-1 . thus array A has
elements A[0] to A[N-1] and B has elements B[0] to B[N-1] .let the resultant array be C
with length 10.
ctrB=n-1 , ctrA=0 , ctrC=0
while (ctrC<5) do
{ C[ctrC]=A[ctrA]
ctrC=ctrC+1
ctrA=ctrA+1
}
while (ctrC<10) do
{ C[ctrC]=B[ctrB]
ctrC=ctrC+1
Prepared By Sumit Kumar Gupta, PGT Computer Science
14. Page 14 of 14
ctrB=ctrB-1
}
ctrC=0
while(ctrC<10) do
{
print C[ctrC]
ctrC= ctrC+1
}
END
|
Prepared By Sumit Kumar Gupta, PGT Computer Science