Quicksort has average time complexity of O(n log n), but worst case of O(n^2). It has O(log n) space complexity for the recursion stack. It works by picking a pivot element, partitioning the array into sub-arrays of smaller size based on element values relative to the pivot, and recursively
There are three main types of binary tree representations:
1. Sequential representation stores nodes in arrays sequentially. It wastes space and has problems with insertion/deletion.
2. Linked representation stores a data field and left/right child pointer fields in each node.
3. Threaded binary trees reduce wasted space by replacing null pointers with "threads" to other nodes. This allows traversal without recursion.
The document summarizes chapter 4 on linked lists from a textbook. It covers different types of linked lists including singly linked lists, doubly linked lists, and circular lists. It describes how to implement basic linked list operations like insertion, deletion, and traversal. It also discusses using linked lists to implement stacks, queues, and sparse matrices. Dynamic storage management using linked lists and garbage collection techniques are explained.
This document provides an overview of graphs and graph algorithms. It defines graphs, directed and undirected graphs, and graph terminology like vertices, edges, paths, cycles, connected components, and degrees. It describes different graph representations like adjacency matrices and adjacency lists. It also explains graph traversal algorithms like depth-first search and breadth-first search. Finally, it covers graph algorithms for finding minimum spanning trees, shortest paths, and transitive closure.
The document discusses stacks and queues, which are common data structures that follow the Last In First Out (LIFO) and First In First Out (FIO) principles respectively. Stacks allow insertion and deletion of elements from one end only, while queues allow insertion from one end and deletion from the other end. Circular queues are better than linear queues as they make more efficient use of memory space by allowing insertion at the start when the end is reached. Multiple stacks and queues also allow managing multiple such data structures.
The document discusses evaluation of expressions and the conversion between infix and postfix notations. It provides examples of:
1) Evaluating expressions using the order of operations and precedence of operators. Scenarios are worked through step-by-step.
2) Converting infix notation expressions to equivalent postfix notation expressions using a stack-based algorithm.
3) Evaluating postfix notation expressions using a stack to pop operands and operators in order.
There are three main types of binary tree representations:
1. Sequential representation stores nodes in arrays sequentially. It wastes space and has problems with insertion/deletion.
2. Linked representation stores a data field and left/right child pointer fields in each node.
3. Threaded binary trees reduce wasted space by replacing null pointers with "threads" to other nodes. This allows traversal without recursion.
The document summarizes chapter 4 on linked lists from a textbook. It covers different types of linked lists including singly linked lists, doubly linked lists, and circular lists. It describes how to implement basic linked list operations like insertion, deletion, and traversal. It also discusses using linked lists to implement stacks, queues, and sparse matrices. Dynamic storage management using linked lists and garbage collection techniques are explained.
This document provides an overview of graphs and graph algorithms. It defines graphs, directed and undirected graphs, and graph terminology like vertices, edges, paths, cycles, connected components, and degrees. It describes different graph representations like adjacency matrices and adjacency lists. It also explains graph traversal algorithms like depth-first search and breadth-first search. Finally, it covers graph algorithms for finding minimum spanning trees, shortest paths, and transitive closure.
The document discusses stacks and queues, which are common data structures that follow the Last In First Out (LIFO) and First In First Out (FIO) principles respectively. Stacks allow insertion and deletion of elements from one end only, while queues allow insertion from one end and deletion from the other end. Circular queues are better than linear queues as they make more efficient use of memory space by allowing insertion at the start when the end is reached. Multiple stacks and queues also allow managing multiple such data structures.
The document discusses evaluation of expressions and the conversion between infix and postfix notations. It provides examples of:
1) Evaluating expressions using the order of operations and precedence of operators. Scenarios are worked through step-by-step.
2) Converting infix notation expressions to equivalent postfix notation expressions using a stack-based algorithm.
3) Evaluating postfix notation expressions using a stack to pop operands and operators in order.
This PPT is about "Double Linked List" concept of Data Structure and Algorithm. It is very informatively describe its each concept with example and also pros and cons..
If anyone has Question related to this they may ask freely.
:)
Linked Lists: Introduction Linked lists
Representation of linked list
operations on linked list
Comparison of Linked Lists with Arrays and Dynamic Arrays
Types of Linked Lists and operations-Circular Single Linked List, Double Linked List, Circular Double Linked List
The document discusses stacks and queues. It defines stacks as LIFO data structures and queues as FIFO data structures. It describes basic stack operations like push and pop and basic queue operations like enqueue and dequeue. It then discusses implementing stacks and queues using arrays and linked lists, outlining the key operations and memory requirements for each implementation.
This document discusses different types of linked lists, including singly linked lists, circular linked lists, and doubly linked lists. It provides examples of circular linked lists and explains that in a circular linked list, the last node contains the address of the first node so that the list can be traversed repeatedly. The document also discusses common linked list operations like insertion and deletion of nodes. Finally, it covers stacks and queues, defining them as LIFO and FIFO data structures, respectively, and providing examples of their implementation and different types.
This document discusses different types of linked lists including single linked lists, double linked lists, circular linked lists, and circular double linked lists. It describes the basic operations that can be performed on linked lists such as creation, insertion, deletion, traversal, searching, concatenation, and display. It provides examples of how to insert and delete nodes from both single and double linked lists. The document also discusses recursive operations and advantages and disadvantages of using linked lists.
a. Concept and Definition✓
b. Inserting and Deleting nodes ✓
c. Linked implementation of a stack (PUSH/POP) ✓
d. Linked implementation of a queue (Insert/Remove) ✓
e. Circular List
• Stack as a circular list (PUSH/POP) ✓
• Queue as a circular list (Insert/Remove) ✓
f. Doubly Linked List (Insert/Remove) ✓
For more course related material:
https://github.com/ashim888/dataStructureAndAlgorithm/
Personal blog
www.ashimlamichhane.com.np
This document discusses binary search trees (BST), including:
- The definition and properties of a BST, with nodes organized based on key values.
- Common BST operations like insertion, deletion, and searching in logarithmic time.
- Advantages of BSTs like efficient searching and working compared to arrays/lists.
- Applications of BSTs in databases, dictionaries, and evaluating expressions.
- Visual examples of searching, inserting, and deleting nodes from a BST.
This document discusses double-ended queues or deques. Deques allow elements to be added or removed from either end. There are two types: input restricted deques where elements can only be inserted at one end but removed from both ends, and output restricted deques where elements can only be removed from one end but inserted from both ends. Deques can function as stacks or queues depending on the insertion and removal ends. The document describes algorithms for common deque operations like insert_front, insert_back, remove_front, and remove_back. It also lists applications of deques like palindrome checking and task scheduling.
The document discusses stacks and queues as abstract data types. It describes their basic operations and implementations using arrays. Stacks follow LIFO (last-in, first-out) order and can be used for applications like undo operations. Queues follow FIFO (first-in, first-out) order and can be used where ordering of elements is important, like in printing queues. The document also discusses infix, prefix and postfix notations for arithmetic expressions and provides an algorithm to convert infix to postfix notation using a stack. Finally, it describes different types of queues including linear and circular queues.
Selection sort is a sorting algorithm that finds the smallest element in an unsorted list and swaps it with the first element, then finds the next smallest element and swaps it with the second element, continuing in this way until the list is fully sorted. It works by iterating through the list, finding the minimum element, and swapping it into its correct place at each step.
This document discusses implementing stacks and queues using linked lists. For a stack, elements are inserted and removed from the head (start) of the linked list for constant time operations. For a queue, elements are inserted at the head and removed from the tail (end) of the linked list, requiring traversing to the second last node for removal. Implementing stacks and queues with linked lists avoids size limitations of arrays and uses dynamic memory allocation.
This document provides information about data structures and algorithms. It begins by defining data structures and storage structures, and notes that a data structure is a logical model of data organization while a storage structure represents a data structure in computer memory. It then classifies data structures as linear or non-linear, and notes that linear data structures form a sequence. The document discusses representation of data structures in memory using arrays or linked lists, and common operations on linear structures like traversal, search, insertion and deletion. It provides detailed explanations of arrays and pointers.
An array is a data structure that stores fixed number of items of the same type. It allows fast access of elements using indices. Basic array operations include traversing elements, inserting/deleting elements, searching for elements, and updating elements. Arrays are zero-indexed and elements are accessed via their index.
Linked lists are linear data structures where elements are linked using pointers. The three main types are singly, doubly, and circular linked lists. Linked lists allow dynamic memory allocation and fast insertion/deletion compared to arrays but slower access. A linked list contains nodes, each with a data field and pointer to the next node. Basic operations on linked lists include insertion, deletion, traversal, and search. Doubly linked lists include pointers to both the next and previous nodes.
A queue is a non-primitive linear data structure that follows the FIFO (first-in, first-out) principle. Elements are added to the rear of the queue and removed from the front. Common operations on a queue include insertion (enqueue) and deletion (dequeue). Queues have many real-world applications like waiting in lines and job scheduling. They can be represented using arrays or linked lists.
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 binary trees, including their basic terminology, properties, representations, traversal methods, and common operations. It provides algorithms for inserting nodes, deleting nodes, and merging two binary trees. The key points covered are:
- Binary trees have a root node, child nodes, and properties like maximum/minimum number of nodes based on height.
- They can be represented sequentially using arrays or non-sequentially using linked lists.
- Common traversal orders are preorder, inorder, and postorder.
- Operations include insertion, deletion, traversal, and merging two trees into one larger tree.
- Algorithms are presented for inserting nodes using linked lists and merging two trees by combining their nodes.
Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
This document introduces doubly linked lists. A doubly linked list allows navigation in both directions by including a prev pointer in each node in addition to the next pointer found in singly linked lists. Each node contains data, a next pointer, and a prev pointer. The list also contains pointers to the first and last nodes. Basic operations on doubly linked lists include insertion and deletion at the beginning or end of the list as well as insertion or deletion after a specified node.
The quicksort algorithm works by recursively sorting arrays of data. It first selects a pivot element and partitions the array around the pivot so that all elements less than the pivot come before it and all elements greater than the pivot come after it. It then recursively sorts the sub-arrays to the left and right of the pivot until the entire array is sorted.
The document discusses quicksort and merge sort algorithms. It provides pseudocode for quicksort, explaining how it works by picking a pivot element and partitioning the array around that element. Quicksort has average time complexity of O(n log n) but worst case of O(n^2). Merge sort is also explained, with pseudocode showing how it recursively splits the array in half and then merges the sorted halves. Merge sort runs in O(n log n) time in all cases.
This PPT is about "Double Linked List" concept of Data Structure and Algorithm. It is very informatively describe its each concept with example and also pros and cons..
If anyone has Question related to this they may ask freely.
:)
Linked Lists: Introduction Linked lists
Representation of linked list
operations on linked list
Comparison of Linked Lists with Arrays and Dynamic Arrays
Types of Linked Lists and operations-Circular Single Linked List, Double Linked List, Circular Double Linked List
The document discusses stacks and queues. It defines stacks as LIFO data structures and queues as FIFO data structures. It describes basic stack operations like push and pop and basic queue operations like enqueue and dequeue. It then discusses implementing stacks and queues using arrays and linked lists, outlining the key operations and memory requirements for each implementation.
This document discusses different types of linked lists, including singly linked lists, circular linked lists, and doubly linked lists. It provides examples of circular linked lists and explains that in a circular linked list, the last node contains the address of the first node so that the list can be traversed repeatedly. The document also discusses common linked list operations like insertion and deletion of nodes. Finally, it covers stacks and queues, defining them as LIFO and FIFO data structures, respectively, and providing examples of their implementation and different types.
This document discusses different types of linked lists including single linked lists, double linked lists, circular linked lists, and circular double linked lists. It describes the basic operations that can be performed on linked lists such as creation, insertion, deletion, traversal, searching, concatenation, and display. It provides examples of how to insert and delete nodes from both single and double linked lists. The document also discusses recursive operations and advantages and disadvantages of using linked lists.
a. Concept and Definition✓
b. Inserting and Deleting nodes ✓
c. Linked implementation of a stack (PUSH/POP) ✓
d. Linked implementation of a queue (Insert/Remove) ✓
e. Circular List
• Stack as a circular list (PUSH/POP) ✓
• Queue as a circular list (Insert/Remove) ✓
f. Doubly Linked List (Insert/Remove) ✓
For more course related material:
https://github.com/ashim888/dataStructureAndAlgorithm/
Personal blog
www.ashimlamichhane.com.np
This document discusses binary search trees (BST), including:
- The definition and properties of a BST, with nodes organized based on key values.
- Common BST operations like insertion, deletion, and searching in logarithmic time.
- Advantages of BSTs like efficient searching and working compared to arrays/lists.
- Applications of BSTs in databases, dictionaries, and evaluating expressions.
- Visual examples of searching, inserting, and deleting nodes from a BST.
This document discusses double-ended queues or deques. Deques allow elements to be added or removed from either end. There are two types: input restricted deques where elements can only be inserted at one end but removed from both ends, and output restricted deques where elements can only be removed from one end but inserted from both ends. Deques can function as stacks or queues depending on the insertion and removal ends. The document describes algorithms for common deque operations like insert_front, insert_back, remove_front, and remove_back. It also lists applications of deques like palindrome checking and task scheduling.
The document discusses stacks and queues as abstract data types. It describes their basic operations and implementations using arrays. Stacks follow LIFO (last-in, first-out) order and can be used for applications like undo operations. Queues follow FIFO (first-in, first-out) order and can be used where ordering of elements is important, like in printing queues. The document also discusses infix, prefix and postfix notations for arithmetic expressions and provides an algorithm to convert infix to postfix notation using a stack. Finally, it describes different types of queues including linear and circular queues.
Selection sort is a sorting algorithm that finds the smallest element in an unsorted list and swaps it with the first element, then finds the next smallest element and swaps it with the second element, continuing in this way until the list is fully sorted. It works by iterating through the list, finding the minimum element, and swapping it into its correct place at each step.
This document discusses implementing stacks and queues using linked lists. For a stack, elements are inserted and removed from the head (start) of the linked list for constant time operations. For a queue, elements are inserted at the head and removed from the tail (end) of the linked list, requiring traversing to the second last node for removal. Implementing stacks and queues with linked lists avoids size limitations of arrays and uses dynamic memory allocation.
This document provides information about data structures and algorithms. It begins by defining data structures and storage structures, and notes that a data structure is a logical model of data organization while a storage structure represents a data structure in computer memory. It then classifies data structures as linear or non-linear, and notes that linear data structures form a sequence. The document discusses representation of data structures in memory using arrays or linked lists, and common operations on linear structures like traversal, search, insertion and deletion. It provides detailed explanations of arrays and pointers.
An array is a data structure that stores fixed number of items of the same type. It allows fast access of elements using indices. Basic array operations include traversing elements, inserting/deleting elements, searching for elements, and updating elements. Arrays are zero-indexed and elements are accessed via their index.
Linked lists are linear data structures where elements are linked using pointers. The three main types are singly, doubly, and circular linked lists. Linked lists allow dynamic memory allocation and fast insertion/deletion compared to arrays but slower access. A linked list contains nodes, each with a data field and pointer to the next node. Basic operations on linked lists include insertion, deletion, traversal, and search. Doubly linked lists include pointers to both the next and previous nodes.
A queue is a non-primitive linear data structure that follows the FIFO (first-in, first-out) principle. Elements are added to the rear of the queue and removed from the front. Common operations on a queue include insertion (enqueue) and deletion (dequeue). Queues have many real-world applications like waiting in lines and job scheduling. They can be represented using arrays or linked lists.
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 binary trees, including their basic terminology, properties, representations, traversal methods, and common operations. It provides algorithms for inserting nodes, deleting nodes, and merging two binary trees. The key points covered are:
- Binary trees have a root node, child nodes, and properties like maximum/minimum number of nodes based on height.
- They can be represented sequentially using arrays or non-sequentially using linked lists.
- Common traversal orders are preorder, inorder, and postorder.
- Operations include insertion, deletion, traversal, and merging two trees into one larger tree.
- Algorithms are presented for inserting nodes using linked lists and merging two trees by combining their nodes.
Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
This document introduces doubly linked lists. A doubly linked list allows navigation in both directions by including a prev pointer in each node in addition to the next pointer found in singly linked lists. Each node contains data, a next pointer, and a prev pointer. The list also contains pointers to the first and last nodes. Basic operations on doubly linked lists include insertion and deletion at the beginning or end of the list as well as insertion or deletion after a specified node.
The quicksort algorithm works by recursively sorting arrays of data. It first selects a pivot element and partitions the array around the pivot so that all elements less than the pivot come before it and all elements greater than the pivot come after it. It then recursively sorts the sub-arrays to the left and right of the pivot until the entire array is sorted.
The document discusses quicksort and merge sort algorithms. It provides pseudocode for quicksort, explaining how it works by picking a pivot element and partitioning the array around that element. Quicksort has average time complexity of O(n log n) but worst case of O(n^2). Merge sort is also explained, with pseudocode showing how it recursively splits the array in half and then merges the sorted halves. Merge sort runs in O(n log n) time in all cases.
Quick sort is an internal algorithm which is based on divide and conquer strategy. In this:
The array of elements is divided into parts repeatedly until it is not possible to divide it further.
It is also known as “partition exchange sort”.
It uses a key element (pivot) for partitioning the elements.
One left partition contains all those elements that are smaller than the pivot and one right partition contains all those elements which are greater than the key element.divide and conquer strategy. In this:
The elements are split into two sub-arrays (n/2) again and again until only one element is left.
Merge sort uses additional storage for sorting the auxiliary array.
Merge sort uses three arrays where two are used for storing each half, and the third external one is used to store the final sorted list by merging other two and each array is then sorted recursively.
At last, the all sub arrays are merged to make it ‘n’ element size of the array. Quick Sort vs Merge Sort
Partition of elements in the array : In the merge sort, the array is parted into just 2 halves (i.e. n/2). whereas In case of quick sort, the array is parted into any ratio. There is no compulsion of dividing the array of elements into equal parts in quick sort.
Worst case complexity : The worst case complexity of quick sort is O(n^2) as there is need of lot of comparisons in the worst condition. whereas In merge sort, worst case and average case has same complexities O(n log n).
Usage with datasets : Merge sort can work well on any type of data sets irrespective of its size (either large or small). whereas The quick sort cannot work well with large datasets.
Additional storage space requirement : Merge sort is not in place because it requires additional memory space to store the auxiliary arrays. whereas The quick sort is in place as it doesn’t require any additional storage.
Efficiency : Merge sort is more efficient and works faster than quick sort in case of larger array size or datasets. whereas Quick sort is more efficient and works faster than merge sort in case of smaller array size or datasets.
Sorting method : The quick sort is internal sorting method where the data is sorted in main memory. whereas The merge sort is external sorting method in which the data that is to be sorted cannot be accommodated in the memory and needed auxiliary memory for sorting.
Stability : Merge sort is stable as two elements with equal value appear in the same order in sorted output as they were in the input unsorted array. whereas Quick sort is unstable in this scenario. But it can be made stable using some changes in code.
Preferred for : Quick sort is preferred for arrays. whereas Merge sort is preferred for linked lists.
Locality of reference : Quicksort exhibits good cache locality and this makes quicksort faster than merge sort (in many cases like in virtual memory environment).
Mergesort and Quicksort are two efficient sorting algorithms that run in O(n log n) time. Mergesort uses a divide-and-conquer approach, recursively splitting the array in half until single elements remain, then merging the sorted halves back together. Quicksort chooses a pivot element and partitions the array into elements less than or greater than the pivot, then recursively sorts the subarrays. The document provides pseudocode for both algorithms and analyzes their time complexities.
Mergesort and Quicksort are efficient sorting algorithms that run in O(n log n) time. Mergesort uses a divide-and-conquer approach, recursively splitting the list into halves until single elements remain, then merging the sorted halves back together. Quicksort chooses a pivot element and partitions the list into elements less than or greater than the pivot, then recursively sorts the sublists.
Mergesort and Quicksort are efficient sorting algorithms that run in O(n log n) time. Mergesort uses a divide-and-conquer approach, recursively splitting the list into halves until single elements remain, then merging the sorted halves back together. Quicksort chooses a pivot element and partitions the list into elements less than or greater than the pivot, then recursively sorts the sublists.
Mergesort and Quicksort are two efficient sorting algorithms that run in O(n log n) time. Mergesort uses a divide-and-conquer approach, recursively splitting the list into halves until individual elements remain, then merging the sorted halves back together. Quicksort chooses a pivot element and partitions the list into elements less than or greater than the pivot, then recursively sorts the sublists until the entire list is sorted.
Mergesort and Quicksort are two efficient sorting algorithms that run in O(n log n) time. Mergesort uses a divide-and-conquer approach, recursively splitting the list into halves until individual elements remain, then merging the sorted halves back together. Quicksort chooses a pivot element and partitions the list into elements less than or greater than the pivot, then recursively sorts the sublists until the entire list is sorted.
Mergesort and Quicksort are two efficient sorting algorithms that run in O(n log n) time. Mergesort uses a divide-and-conquer approach, recursively splitting the array in half until single elements remain, then merging the sorted halves back together. Quicksort chooses a pivot element and partitions the array into elements less than or greater than the pivot, then recursively sorts the subarrays. The document provides pseudocode for both algorithms and walks through an example of Quicksort.
The quicksort algorithm sorts an array by recursively dividing it into smaller sub-arrays by picking a pivot element. It partitions the array into two halves based on the pivot, putting elements less than the pivot in one half and greater elements in the other. The process is then repeated on each sub-array until the entire array is sorted. It works by first choosing a pivot element, partitioning the array around the pivot so that elements less than the pivot come before elements greater than it, and then quicksorting the two resulting sub-arrays.
The quicksort algorithm works by first picking a pivot element. It then partitions the array into two sub-arrays - one with elements less than the pivot and one with elements greater than the pivot. It recursively sorts the two sub-arrays. In the best case, the pivot splits the array evenly in half each time, resulting in a runtime of O(n log n).
The document discusses various sorting algorithms like bubble sort, selection sort, insertion sort, merge sort, quicksort and heap sort. It provides pseudocode to explain the algorithms. For each algorithm, it explains the basic approach, complexity analysis and provides an example to illustrate the steps. Quicksort is explained in more detail with pseudocode and examples to demonstrate how it works by picking a pivot element, partitioning the array and recursively sorting the sub-arrays.
The document discusses three quadratic sorting algorithms: selection sort, insertion sort, and bubble sort. It provides pseudocode for selection sort and insertion sort, and describes their operation through examples. Both selection sort and insertion sort have a worst-case and average-case runtime of O(n^2) where n is the number of elements to sort.
Searching in data structure refers to the process of finding the required information from a collection of items stored as elements in the computer memory. These sets of items are in different forms, such as an array, linked list, graph, or tree. Searching means locating a particular element in a collection of elements. Search result determines whether that particular element is present in the collection or not. If it is present, we can also find out the position of that element in the given collection. Searching is an important technique in computer science.
Array ADT(Abstract Data Type)|Data StructureAkash Gaur
The document discusses abstract data types (ADTs) and describes an array ADT. It lists common array operations like display, add, insert, delete, search, get, set, max, min, reverse, shift, and provides pseudocode implementations. Operations like insert and delete are O(n) linear time due to array element shifting. Search operations can be improved to O(1) constant time using techniques like transposition and move to front. Binary search provides O(logn) time complexity for sorted arrays. The document also discusses sorting an array, checking if an array is sorted, arranging negative numbers to the left, and merging two sorted arrays.
The document discusses various topics related to arrays including:
- Defining an array as a collection of similar data elements of the same type stored in consecutive memory locations referenced by an index.
- Syntax for declaring arrays and accessing elements using a loop and subscript.
- Calculating addresses of array elements.
- Storing, initializing, inputting, and assigning values to array elements.
- Calculating the length of an array.
- Algorithms for inserting and deleting elements from an array.
- Sorting algorithms like bubble, selection, and insertion sort.
- Searching techniques like linear and binary search.
The document discusses quicksort analysis and ways to improve its performance. It shows that quicksort has a best case running time of O(n log n) when keys are randomly distributed, but a worst case of O(n^2) if the array is already sorted. To avoid the worst case, the document suggests improving pivot selection by choosing the median of three randomly selected elements rather than just the first element. It also recommends using brute force for small subarrays of size 3 or less.
Similar to Unit 5 internal sorting & files (20)
This document discusses composite data types in PL/SQL such as records, tables, nested records, and variable-sized arrays (varrays). Records are similar to rows in database tables and can contain fields of scalar or other composite types. Tables are collections of elements of the same type indexed by numbers. Nested records allow records to be included as fields within other records. Varrays are single-dimensional arrays with a bounded size. Procedures and functions are used to modularize PL/SQL code.
This document provides an introduction and overview of PL/SQL. It discusses that PL/SQL is Oracle's procedural language extension for SQL and allows for transactions processing and block structuring. The document then covers various PL/SQL concepts like blocks, data types, control structures, variables and SQL operations within PL/SQL code.
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLEDrkhanchanaR
The document discusses various built-in functions in Oracle including single row functions, group functions, character functions, numeric functions, and date functions. It provides examples of functions such as UPPER, LOWER, ROUND, TRUNC, SYS_DATE, and conversion functions like TO_CHAR and TO_DATE. Character functions manipulate character data, numeric functions perform calculations and return numeric values, and date functions allow date arithmetic and formatting of dates.
Oracle 9i is a client/server database management system based on the relational data model. It handles failures well through transaction logging and allows administrators to manage users and databases through administrative tools. SQL*Plus provides an interactive interface for writing and executing SQL statements against Oracle databases, while PL/SQL adds procedural programming capabilities. Common SQL statements retrieve, manipulate, define and control database objects and transactions.
This document discusses database design and data modeling concepts. It covers:
- Data modeling using entity-relationship diagrams to graphically represent database components like entities and relationships.
- Relationship types (1:1, 1:M, M:N), connectivity, cardinality, and other ERD elements.
- Database normalization forms (1NF, 2NF, 3NF) and how they reduce data anomalies by eliminating entity redundancies and dependencies.
- The three common types of data anomalies - insertion, deletion, and update anomalies - and how normalization addresses them.
- An overview of other normalization forms like BCNF, 4NF, 5NF and dependency diagrams for tracking dependencies across tables.
Unit I Database concepts - RDBMS & ORACLEDrkhanchanaR
The document provides an overview of relational database management systems (RDBMS) and Oracle. It discusses database concepts such as the relational data model, database design including normalization, and integrity rules. It also outlines the contents of 5 units that will be covered, including Oracle, SQL, PL/SQL, and database objects like procedures and triggers. Key terms discussed include entities, attributes, relationships, and the different types of keys.
How to Fix the Import Error in the Odoo 17Celine George
An import error occurs when a program fails to import a module or library, disrupting its execution. In languages like Python, this issue arises when the specified module cannot be found or accessed, hindering the program's functionality. Resolving import errors is crucial for maintaining smooth software operation and uninterrupted development processes.
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
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.
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
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.
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.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
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.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
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.
1. Unit 5
Internal Sorting & Files
Dr. R. Khanchana
Assistant Professor
Department of Computer Science
Sri Ramakrishna College of Arts and Science for
Women
http://icodeguru.com/vc/10book/books/book1/chap07.htm
http://icodeguru.com/vc/10book/books/book1/chap10.htm
Tutorials :
https://www.tutorialspoint.com/data_structures_algorithms/insertion_sort_algorithm.htm
3. Insertion Sort
• Insertion sort is a simple sorting algorithm that
builds the final sorted array one item at a time.
• It is much less efficient on large lists than more
advanced algorithms such as quicksort, heapsort,
or merge sort.
• Worst complexity: n^2
• Average complexity: n^2
• Best complexity: n
• Space complexity: 1
3
5. Insertion Sort
• Idea: like sorting a hand of playing cards
– i with an empty left hand and the cards facing down
on the table.
– Remove one card at a time from the table, and insert
it into the correct position in the left hand
• compare it with each of the cards already in the hand, from
right to left
– The cards held in the left hand are sorted
• these cards were originally the top cards of the pile on the
table
5
6. Insertion Sort
6
To insert 12, we need to make
room for it by moving first 36
and then 24.STEP 1
STEP 2
STEP 3
7. Insertion Sort
7
5 2 4 6 1 3
input array
left sub-array right sub-array
at each iteration, the array is divided in two sub-arrays:
sorted unsorted
10. Insertion Sort
• Example 7.1: Assume n = 5 and the input sequence is (5,4,3,2,1) [note the
records have only one field which also happens to be the key]. Then, after
each insertion we have the following:
Note that this is an example of the worst case behavior.
• Example 7.2: n = 5 and the input sequence is (2, 3, 4, 5, 1). After each
execution of INSERT we have:
16. Quick Sort
The idea (assume the list of items to be sorted is represented as an array):
1. Select a data item, called the pivot, which will be placed in its proper place
at the j of the current step. Remove it from the array.
2. Scan the array from right to left, comparing the data items with the pivot
until an item with a smaller value is found. Put this item in the pivot’s place.
3. Scan the array from left to right, comparing data items with the pivot, and
find the first item which is greater than the pivot. Place it in the position
freed by the item moved at the previous step.
4. Continue alternating steps 2-3 until no more exchanges are possible. Place
the pivot in the empty space, which is the proper place for that item.
5. Consider the sub-file to the left of the pivot, and repeat the same process.
6. Consider the sub-file to the right of the pivot, and repeat the same
process.
Video :https://www.youtube.com/watch?v=PgBzjlCcFvc
17. Example
We are given array of n integers to sort:
40 20 10 80 60 50 7 30 100
[0] [1] [2] [3] [4] [5] [6] [7] [8]
18. Pick Pivot Element
There are a number of ways to pick the pivot element. In
this example, we will use the first element in the array:
40 20 10 80 60 50 7 30 100
[0] [1] [2] [3] [4] [5] [6] [7] [8]
20. 40 20 10 80 60 50 7 30 100pivot_index = 0
[0] [1] [2] [3] [4] [5] [6] [7] [8]
i j
1. While data[i] <= data[pivot]
++ i
21. 40 20 10 80 60 50 7 30 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
[0] [1] [2] [3] [4] [5] [6] [7] [8]
22. 40 20 10 80 60 50 7 30 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
[0] [1] [2] [3] [4] [5] [6] [7] [8]
23. 40 20 10 80 60 50 7 30 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
2. While data[j] > data[pivot]
--j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
24. 40 20 10 80 60 50 7 30 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
2. While data[j] > data[pivot]
--j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
25. 40 20 10 80 60 50 7 30 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
[0] [1] [2] [3] [4] [5] [6] [7] [8]
26. 40 20 10 30 60 50 7 80 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
[0] [1] [2] [3] [4] [5] [6] [7] [8]
27. 40 20 10 30 60 50 7 80 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
[0] [1] [2] [3] [4] [5] [6] [7] [8]
28. 40 20 10 30 60 50 7 80 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j> i, go to 1.
[0] [1] [2] [3] [4] [5] [6] [7] [8]
29. 40 20 10 30 60 50 7 80 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and [j]
4. While j> i, go to 1.
[0] [1] [2] [3] [4] [5] [6] [7] [8]
30. 40 20 10 30 60 50 7 80 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j> i, go to 1.
[0] [1] [2] [3] [4] [5] [6] [7] [8]
31. 40 20 10 30 60 50 7 80 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
[0] [1] [2] [3] [4] [5] [6] [7] [8]
32. 40 20 10 30 60 50 7 80 100pivot_index = 0
i j
1. While data[i] <= data[pivot]
++ i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
[0] [1] [2] [3] [4] [5] [6] [7] [8]
33. 1. While data[i] <= data[pivot]
++ i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
40 20 10 30 7 50 60 80 100pivot_index = 0
i j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
34. 1. While data[i] <= data[pivot]
++i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
40 20 10 30 7 50 60 80 100pivot_index = 0
i j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
35. 1. While data[i] <= data[pivot]
++i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
40 20 10 30 7 50 60 80 100pivot_index = 0
i j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
36. 1. While data[i] <= data[pivot]
++i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
40 20 10 30 7 50 60 80 100pivot_index = 0
i j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
37. 1. While data[i] <= data[pivot]
++i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
40 20 10 30 7 50 60 80 100pivot_index = 0
i j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
38. 1. While data[i] <= data[pivot]
++i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
40 20 10 30 7 50 60 80 100pivot_index = 0
i j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
39. 1. While data[i] <= data[pivot]
++i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
40 20 10 30 7 50 60 80 100pivot_index = 0
i j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
40. 1. While data[i] <= data[pivot]
++i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
40 20 10 30 7 50 60 80 100pivot_index = 0
i j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
41. 1. While data[i] <= data[pivot]
++i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
40 20 10 30 7 50 60 80 100pivot_index = 0
i j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
42. 1. While data[i] <= data[pivot]
++i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
5. Swap data[j] and data[pivot_index]
40 20 10 30 7 50 60 80 100pivot_index = 0
i j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
43. 1. While data[i] <= data[pivot]
++i
2. While data[j] > data[pivot]
--j
3. If i > j
swap data[i] and data[j]
4. While j > i, go to 1.
5. Swap data[j] and data[pivot_index]
7 20 10 30 40 50 60 80 100pivot_index = 4
i j
[0] [1] [2] [3] [4] [5] [6] [7] [8]
45. Quick Sort Algorithm
In Quick sort algorithm, partitioning of the list is performed using
following steps...
Step 1 - Consider the first element of the list as pivot (i.e., Element at
first position in the list).
Step 2 - Define two variables i and j. Set i and j to first and last elements
of the list respectively.
Step 3 - Increment i until list[i] > pivot then stop.
Step 4 - Decrement j until list[j] < pivot then stop.
Step 5 - If i > j then exchange list[i] and list[j].
Step 6 - Repeat steps 3,4 & 5 until I < j.
Step 7 - Exchange the pivot element with list[j] element.
46. Partitioning Array
Given a pivot, partition the elements of the array
such that the resulting array consists of:
1. One sub-array that contains elements >= pivot
2. Another sub-array that contains elements < pivot
The sub-arrays are stored in the original data array.
Partitioning loops through, swapping elements
below/above pivot.
47. Quick Sort
40 20 10 80 60 50 7 30 100
[0] [1] [2] [3] [4] [5] [6] [7] [8]
m n
K = Pivot
Ki
Kj
i
j
m nj-1
j
j+1
48. CHAPTER 7 48
Time and Space Complexity for
Quick Sort
Space complexity:
– Average case and best case: O(log n)
– Worst case: O(n)
Time complexity:
– Average case and best case: O(n logn)
– Worst case: O(n )2
49. Merge Sort
• Apply divide-and-conquer to sorting problem
• Problem: Given n elements, sort elements into non-
decreasing order
• Divide-and-Conquer:
– If n=1 terminate (every one-element list is already sorted)
– If n>1, partition elements into two or more sub-
collections; sort each; combine into a single sorted list
CHAPTER 7 49
50. Merge-Sort
• An execution of merge-sort is depicted by a binary
tree
– each node represents a recursive call of merge-sort and
stores
– the root is the initial call
– the leaves are calls on subsequences of size 0 or 1
• Given two sorted lists
(list[i], …, list[m])
(list[m+1], …, list[n])
generate a single sorted list
(sorted[i], …, sorted[n])
• O(n) space vs. O(1) space
Merge Sort 50
65. Merge Sort
[3, 4, 6, 10]
[2, 3, 4, 5, 6, 7, 8, 10 ]
[2, 5, 7, 8]
[10, 4, 6, 3, 8, 2, 5, 7]Input Array
Output Array (Sorted)
X X
K
Xi Xj
Zk
66. Analysis
• array vs. linked list representation
– array: O(M(n-i+1)) where M: record length
for copy
– linked list representation: O(n-i+1)
(n-i+1) linked fields
CHAPTER 7 66
67. Heap Sort
Heap sort may be regarded as a two stage method.
First the tree representing the file is converted into a heap(max heap).
-max-heap property: the value of each node is less than or equal to the
value of its parent, with the maximum-value element at the root.
A heap is defined to be a complete binary tree with the property that the value
of each node is at least as large as the value of its children nodes (if they
exist) (i.e., Kj/2 Kj for 1 j/2 < j n).
74. Shell Sort
• Shellsort is an extension of insertion sort, which gains
speed by allowing exchanges of elements that are far apart.
• Shellsort is also known as diminishing increment sort.
• It is an advanced Sorting Method
• Shell sort is an algorithm that first sorts the elements far
apart from each other and successively reduces the interval
between the elements to be sorted. It is a generalized version
of insertion sort.
• In shell sort, elements at a specific interval are sorted. The
interval between the elements is gradually decreased based
on the sequence used. The performance of the shell sort
depicts on the type of sequence used for a given input array.
75. Shellsort
• Invented by Donald Shell in 1959.
• 1st algorithm to break the quadratic time
barrier but few years later, a sub quadratic
time bound was proven
• Shellsort works by comparing elements
that are distant rather than adjacent
elements in an array.
76. Shellsort
• Shellsort makes multiple passes through a list
and sorts a number of equally sized sets using the
insertion sort.
• The distance between comparisons decreases as
the sorting algorithm runs until the last phase in
which adjacent elements are compared
• Shellsort improves on the efficiency of insertion
sort by quickly shifting values to their destination
77. Empirical Analysis of Shellsort (Advantage)
• Advantage of Shellsort is that its only efficient
for medium size lists. For bigger lists, the
algorithm is not the best choice. Fastest of all
O(N^2) sorting algorithms.
• 5 times faster than the bubble sort and a little
over twice as fast as the insertion sort, its
closest competitor.
78. Empirical Analysis of Shellsort (Disadvantage)
• Disadvantage of Shellsort is that it is a complex
algorithm and its not nearly as efficient as the merge,
heap, and quick sorts.
• The shell sort is still significantly slower than the
merge, heap, and quick sorts, but its relatively simple
algorithm makes it a good choice for sorting lists of
less than 5000 items unless speed important. It's also
an excellent choice for repetitive sorting of smaller
lists.
79. Shellsort Examples –Pass 1
Interval 1
Sort: 18 32 12 5 38 33 16 2
8 Numbers to be sorted, Shell’s increment will be floor(n/2)
* floor(8/2) floor(4) = 4
increment 4: 1 2 3 4
18 32 12 5 38 33 16 2
(visualize underlining)
Step 1) Only look at 18 and 38 and sort in order ;
18 and 38 stays at its current position because they are in order.
Step 2) Only look at 32 and 33 and sort in order ;
32 and 33 stays at its current position because they are in order.
80. Shellsort Examples – Pass 1
Interval 1
Sort: 18 32 12 5 38 33 16 2
8 Numbers to be sorted, Shell’s increment will be floor(n/2) * floor(8/2) floor(4) = 4
increment 4: 1 2 3 4
18 32 12 5 38 33 16 2
(visualize underlining)
Step 3) Only look at 12 and 16 and sort in order ;
12 and 16 stays at its current position because they are in order.
Step 4) Only look at 5 and 2 and sort in order ;
2 and 5 need to be switched to be in order.
Sort: 18 32 12 5 38 33 16 2
Resulting numbers after increment 4 steps in pass1 :
18 32 12 2 38 33 16 5
81. Shellsort Examples – Pass 2
Interval 2
8 Numbers to be sorted, Shell’s increment will be floor(n/4) or (interval1/2)
* floor(4/2) floor(2) = 2
increment 2: 1 2
18 32 12 2 38 33 16 5
Step 1) Look at 18, 12, 38, 16 and sort them in their appropriate location:
12 32 16 2 18 33 38 5
Step 2) Look at 32, 2, 33, 5 and sort them in their appropriate location:
12 2 16 5 18 32 38 33
Sort: 18 32 12 5 38 33 16 2
Resulting numbers after increment 2 steps in pass2 :
12 2 16 5 18 32 38 33
82. Shellsort Examples- Pass 3
Interval 3
Sort: 18 32 12 5 38 33 16 2
* floor(2/2) floor(1) = 1
increment 1: 1
12 2 16 5 18 32 38 33
2 5 12 16 18 32 33 38
The last increment or phase of Shellsort is basically an Insertion Sort algorithm.
8 Numbers to be sorted, Shell’s increment will be floor(n/8) or (interval2/2)
83. Shell Sort Algorithm
1.shellsort(int arr[], int num)
2.{
3.int i, j, k;
4.for (i = num / 2; i > 0; i = i / 2)
5.{
6.for (j = i; j < num; j++)
7.{
8.for(k = j - i; k >= 0; k = k - i)
9.{
10.if (arr[k+i] >= arr[k])
11.break;
12.else
13.{
14.Swap arr[k] =
arr[k+i];}
15.}
16.}
17.}
18.}
86. FILES
A file is a collection of records which contain
data about individual entities.
The data is subdivided into records.
Each record contains a number of fields.
The primary key is a field, or a composite of
several fields which uniquely distinguishes a
record from all others.
All the remaining fields are the secondary
fields.
88. File Organization
A file organization refers to the way records are
arranged on a storage devices such as magnetic
tapes, disks, etc...
• Sequential File
• Direct File
• Indexed Sequential File
89. Objective of file organization
The primary objective of file organization
is to provide a means for record retrieval
and update.
The update of a record could involve its
deletion, changes in some of its fields or the
insertion of an entirely new record.
Records may be retrieved by specifying
values for some or using all of the keys.
90. How data can be organized on external
storage devices?
Depends on the following factors
Kind of external storage devices
available
Type of Queries allowed
Number of keys
Mode of retrieval
Mode of update
91. Storage Device Types - DASD
A direct access storage device is a
secondary storage device in which
“each physical record has a discrete
location and a unique address”.
Direct access storage devices allow
the host computer to access data
directly from wherever it is stored
within the storage device because each
data chunk is saved in a discrete and
separate location from other chunks
92. Query Types
A combination of key values specified for
retrieve will be termed a query.
The four query types are:
Simple query – The value of a single key is
specified.
Range query – A range of values for a
single key is specified.
Functional query – Some function of key
values in the file is specified (e.g. average or
median).
93. Boolean Query – A Boolean combination of all above queries
using logical operators and, or, not.
Q1: Dept = Security
Q2: Salary > 25,000
Q3: Salary>average salary of all employees
Q4: (Dept = security and salary > 25,000) or (Employee number =
367 and designation = manager)
Number of Keys
The chief distinction here will be between files having only one
key and files with more than one key.
Query Types
94. The mode of retrieval may be either real time
or batched.
* In real time retrieval the response time for
any query should be minimal.
Example: In an airline reservation
system we are able to determine the
status of a flight (number of seats
vacant) in a matter of few seconds.
Mode of Retrieval
95. • In the batched mode of retrieval, the response time is
not very significant.
• Requests for retrieval are batched together on a
“transaction file” until either enough requests have
been received or a suitable amount of time has passed.
• Then all queries on the transaction file are processed.
Mode of Retrieval
96. Mode of update – Real time
The function that keeps files current is known
as updating. The mode of update may again be either
real time or batched.
Real time involves a large number of users performing
transactions to change data.
The steps in real time involve sending the data to an
online database in a master file.
Data is accessed via direct access, which occurs when
data is accessed without accessing previous data items.
Uses an algorithm to calculate the location of data.
If the data is not there it continues to search through
successive locations until it is found.
97. Technology in real time requires secondary
storage to store large quantities of data for
quick access, magnetic disk storage.
Example: In an airline reservation system,
as soon as a seat on the flight is reserved,
the file must be changed to indicate the
new status.
Mode of update – Real time
98. Batch Update
A batch update is a set of multiple update
statements that is submitted to the database for
processing as a batch.
Sending multiple update statements to the
database together as a unit can, in some
situations, be much more efficient than sending
each update statement separately.
No user interaction is required.
Common examples of where batch processing
occurs include the processing of bank
statements, utility bills and credit card
transactions.
99. In case of batched update two files are
considered : Master file and Transaction file.
The permanent data file, called the master
file contains the most current file data.
The transaction file contains changes to be
applied to the master file.
Batch Update
100. How the required functions are
carried out efficiently on a tape?
* The records in the file are ordered by the key field.
* Requests for retrieval and update are batched onto a
transaction tape.
* When it is time to process the transactions, the
transactions are sorted into order by the key field and
update process is carried out creating a new master file.
* All records in the old master file are examined, changed
if necessary and then written out onto a new master file.
* The time required for the whole process is essentially
O(n + m log m) where n and m are the number of
records in the master and transaction files respectively.
101. * If m=1 and n=106 then clearly it is very wasteful to process the entire
master file.
* As the files in tape are sequentially ordered it is not possible to alter a
record in the middle of a tape without destroying information in an
adjacent record.
* For batched retrieval and update, ordered sequential files are
preferred over unordered sequential files since they are easier to
process.
- (contd)
102. How the required functions are
carried out efficiently on a disk?
Batched retrieval and update can be carried out essentially
in the same way as for a sequentially ordered tape file by
setting up input and output buffers and reading in perhaps,
one track of the master and transaction files at a time.
The transaction file should be sorted on the primary key
before beginning the master file processing.
The sequential interpretation is particularly efficient for
batched update and retrieval as the tracks are to be accessed
in the order.
The read/write heads are moved one cylinder at a time and
this movement is necessitated only once for every s tracks
read (s = number of surfaces).
104. If the records are of a fixed size then it
is possible to use binary search to
obtain the record with the desired key
value.
Example : For a file with 105 records
of length 300 characters this would
mean a maximum of 17 accesses
Binary Search
105. Index File Access
To access a record in a file randomly, we need to
know the address of the record.
An index is just a collection of key values and
address pairs.
The index itself is a very small file with only two
fields.
The key of the sequential file and the address
of the corresponding record on the disk.
The index is sorted based on the key values of the
data files.
106. An index which contains one entry for
every record in the file will be referred
to as a dense index.
Time is consumed in this access.
Index File Access
107. Index Techniques
• Indexing is a data structure technique to
efficiently retrieve records from the database
files based on some attributes on which
the indexing has been done. ...
Clustering Index − Clustering index is defined
on an ordered data file. The data file is
ordered on a non-key field.
108. Cylinder-surface indexing
• Simplest type of index organization. It is useful
only for the primary key index of a
sequentially ordered file. It assumes that
records are stored sequentially in increasing
order of primary key. The index consists of a
cylinder index and several surface indexes. If
the file requires c cylinders for storage then
the cylinder index contains c entries.
109. Hashed indexes
• Hash functions and overflow handling techniques are
used for hashing. Since the index is to be maintained
on disk and disk access times are generally several
orders of magnitude larger than internal memory
access times, much consideration is given to hash table
design and the choice of an overflow handling
technique.
• Overflow handling techniques:
• rehashing
• open addressing (random[f(i)=random()], quadratic,
linear)
• chaining
110. Tree indexing-B Trees
• Using m-way search tree can minimize the
search time, rather than using avl trees.
• B trees are used for indexing
•
111. Trie indexing
• An index structure that is particularly useful
when key values are of varying size is trie.
• A trie is a tree of degree m>=2 in which the
branching at any level is determined not by
the entire key value but by only a portion of it.
• The trie contains two types of nodes. First
type called the branch node and second
information node.
113. File Organization
• File organization refers to the way data is
stored in a file. File organization is very
important because it determines the methods
of access, efficiency, flexibility and storage
devices to use. There are four methods
of organizing files on a storage media.
114. • What is File?
• File is a collection of records related to each
other. The file size is limited by the size of
memory and storage medium.
• There are two important features of file:
1. File Activity
2. File Volatility
File Organization
115. • File activity specifies percent of actual records which proceed in a
single run.
File volatility addresses the properties of record changes. It helps to
increase the efficiency of disk design than tape.
• File Organization
File organization ensures that records are available for processing. It
is used to determine an efficient file organization for each base
relation.
For example, if we want to retrieve employee records in
alphabetical order of name. Sorting the file by employee name is a
good file organization. However, if we want to retrieve all
employees whose marks are in a certain range, a file is ordered by
employee name would not be a good file organization.
File Organization
116. Types of File Organizations are
• Sequential Organizations
• Random Organization
• Linked Organization
• Inverted Files
• Cellular partitions
117. Sequential Organizations
• Storing and sorting in contiguous block within files on
tape or disk is called as sequential access file
organization.
• In sequential access file organization, all records are
stored in a sequential order. The records are arranged
in the ascending or descending order of a key field.
• Sequential file search starts from the beginning of the
file and the records can be added at the end of the file.
• In sequential file, it is not possible to add a record in
the middle of the file without rewriting the file.
118. • Advantages of sequential file
It is simple to program and easy to design.
• Sequential file is best use if storage space.
• Disadvantages of sequential file
Sequential file is time consuming process.
• It has high data redundancy.
• Random searching is not possible.
Sequential Organization
119. Random Organization
• Records are stored randomly but accessed
directly. To access a file stored randomly, a
record key is used to determine where a
record is stored on the storage media.
Magnetic and optical disks allow data to be
stored and accessed randomly.
120. Linked Organization
• A linked data structure is a data
structure which consists of a set
of data records (nodes) linked together and
organized by references (links or pointers).
... Linked data structures include linked lists,
search trees, expression trees, and many
other widely used data structures.
121. Inverted Files
• An Inverted file is an index data structure that
maps content to its location within a
database file, in a document or in a set of
documents. ... The inverted file is the most
popular data structure used in document
retrieval systems to support full text search.
122. Cellular partitions
• To reduce the file search times, the storage
media may be divided into cells. A cell may be
an entire disk pack or it may simply be a
cylinder. Lists are localized to lie within a cell.