This document provides an overview of different data structures and sorting algorithms. It begins with an introduction to data structures and describes linear data structures like arrays, stacks, queues, and linked lists as well as non-linear data structures like trees and graphs. It then provides more detailed descriptions of stacks, queues, linked lists, and common sorting algorithms like selection sort and bubble sort.
The document discusses bubble sort, a simple sorting algorithm where each pair of adjacent elements is compared and swapped if out of order. It gets its name because elements "bubble" to their correct positions like bubbles rising in a glass of soda. The algorithm makes multiple passes through the list, swapping elements on each pass until the list is fully sorted. While simple to implement, bubble sort has a slow running time of O(n^2), making it inefficient for large data sets.
This document discusses arrays and operations on arrays. It defines an array as a fixed collection of homogeneous data items stored in contiguous memory locations and indexed by integers. It describes the insert operation as shifting existing elements over and adding the new element at the specified index. It also describes the delete operation as shifting elements back and overwriting the element at the specified index.
The document presents an overview of selection sort, including its definition, algorithm, example, advantages, and disadvantages. Selection sort works by iteratively finding the minimum element in an unsorted sublist and exchanging it with the first element. It has a time complexity of O(n2) but performs well on small lists since it is an in-place sorting algorithm with minimal additional storage requirements. However, it is not efficient for huge datasets due to its quadratic time complexity.
This document discusses stacks and queues as abstract data structures. Stacks follow LIFO (last in first out) order, adding and removing elements from one end. Queues follow FIFO (first in first out) order, adding to one end (rear) and removing from the other (front). The document provides examples of stack and queue applications and implementations using arrays.
This document discusses data abstraction and abstract data types (ADTs). It defines an ADT as a collection of data along with a set of operations on that data. An ADT specifies what operations can be performed but not how they are implemented. This allows data structures to be developed independently from solutions and hides implementation details behind the ADT's operations. The document provides examples of list ADTs and an array-based implementation of a list ADT in C++.
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.
The document discusses queue data structures. A queue is a linear data structure where additions are made at the end/tail and removals are made from the front/head, following a First-In First-Out (FIFO) approach. Common queue operations include add, remove, check if empty, check if full. A queue can be stored using either a static array or dynamic linked nodes. The key aspects are maintaining references to the head and tail of the queue.
This document discusses stacks and queues as linear data structures. It defines stacks as last-in, first-out (LIFO) collections where the last item added is the first removed. Queues are first-in, first-out (FIFO) collections where the first item added is the first removed. Common stack and queue operations like push, pop, insert, and remove are presented along with algorithms and examples. Applications of stacks and queues in areas like expression evaluation, string reversal, and scheduling are also covered.
This document discusses stacks and queues, which are linear data structures. Stacks follow LIFO (last in, first out) and use push and pop operations. Queues follow FIFO (first in, first out) and use insertion at the rear and deletion at the front. Real-world examples of stacks include discs in a holder and tokens in a stack. Real-world examples of queues include lines at counters. Stacks and queues have various applications like reversing strings, expression evaluation, job scheduling, and memory/process management in operating systems.
A stack is a data structure where items can only be inserted and removed from one end. The last item inserted is the first item removed (LIFO). Common examples include stacks of books, plates, or bank transactions. Key stack operations are push to insert, pop to remove, and functions to check if the stack is empty or full. Stacks can be used to implement operations like reversing a string, converting infix to postfix notation, and evaluating arithmetic expressions.
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, which are a fundamental data structure used in programs. It defines a stack as a linear list of items where additions and deletions are restricted to one end, called the top. Common stack operations include push, which adds an element to the top, and pop, which removes an element from the top. Stacks have applications in parsing expressions, reversing strings, implementing depth-first search algorithms, and calculating arithmetic expressions in prefix and postfix notation. Stacks can be implemented using static arrays or dynamic arrays/linked lists.
This document discusses data structures and linked lists. It provides definitions and examples of different types of linked lists, including:
- Single linked lists, which contain nodes with a data field and a link to the next node.
- Circular linked lists, where the last node links back to the first node, forming a loop.
- Doubly linked lists, where each node contains links to both the previous and next nodes.
- Operations on linked lists such as insertion, deletion, traversal, and searching are also described.
This presentation is useful to study about data structure and topic is Binary Tree Traversal. This is also useful to make a presentation about Binary Tree Traversal.
This is a presentation on Linked Lists, one of the most important topics on Data Structures and algorithms. Anyone who is new to DSA or wants to have a theoretical understanding of the same can refer to it :D
This document discusses priority queues. It defines a priority queue as a queue where insertion and deletion are based on some priority property. Items with higher priority are removed before lower priority items. There are two main types: ascending priority queues remove the smallest item, while descending priority queues remove the largest item. Priority queues are useful for scheduling jobs in operating systems, where real-time jobs have highest priority and are scheduled first. They are also used in network communication to manage limited bandwidth.
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.
Linked lists are linear data structures where each node points to the next. Each node contains a data field and a pointer to the next node. There are three types: singly, doubly, and circular linked lists. Linked lists allow for constant-time insertions and deletions and do not require fixed size allocation. Common operations on linked lists include insertion, deletion, searching, and traversal. Linked lists are useful for implementations like stacks, queues, and dynamic data structures.
The document discusses different data structures like arrays, stacks, queues, linked lists, trees, graphs. It provides definitions of each data structure and describes their common operations like traversing, searching, insertion, deletion. It also includes algorithms for operations on linear arrays, stacks, queues and priority queues. Implementation of different data structures and their applications are explained with examples.
This document discusses stacks and queues as data structures. It defines a stack as a LIFO data structure where items can only be inserted and removed from one end. Examples of stack applications include program execution, parsing, and evaluating postfix expressions. The key stack operations are push, peek, and pop. It also defines a queue as a FIFO data structure where items are inserted at one end and removed from the other. Example queue applications include scheduling and networking. The key queue operations are enqueue and dequeue. It discusses implementing both stacks and queues using arrays and linked lists.
1. The document introduces data structures and discusses primitive data structures like integers, booleans, and characters. It also discusses linear data structures like arrays, stacks, queues, and linked lists, as well as non-linear structures like trees and graphs.
2. Stacks are described as ordered collections that follow the LIFO principle. Basic stack operations like push, pop, full, and empty are explained along with algorithms to implement push and pop.
3. Applications of stacks include converting infix expressions to postfix and prefix notation, solving mazes using a scratch pad stack, and text editing operations like delete that utilize stacks.
The document discusses stacks and queues as data structures. It defines a stack as a linear data structure that follows the LIFO principle with insertion and deletion occurring at one end. Key stack operations are described as push, pop, peek, isEmpty and isFull. Queue is defined as a linear structure that follows the FIFO principle with insertion at the rear and deletion at the front. Common queue operations are enqueue, dequeue, peek, isEmpty and isFull. Array and linked list implementations of stacks and queues are also covered.
Revisiting a data structures in detail with linked list stack and queuessuser7319f8
This document discusses various data structures including arrays, stacks, queues, and linked lists. It provides code examples for creating and manipulating each type of data structure. Specifically, it shows code for inserting and deleting elements from arrays and linked lists. It also includes algorithms and code for common stack and queue operations like push, pop, enqueue, and dequeue. The document provides a detailed overview of linear and non-linear data structures.
This document discusses data structures stacks and queues. It provides definitions and examples of stacks and queues. Stacks follow LIFO (last in first out) and are useful for undo sequences and function calls. Queues follow FIFO (first in first out) and are useful for things like printer queues. The document discusses implementations of stacks and queues using arrays and linked lists. It provides pseudocode for common stack and queue operations like push, pop, enqueue, dequeue.
A stack is a linear data structure that follows the LIFO (last in, first out) principle. Elements can only be inserted or removed from one end, called the top. Common stack operations include push, which adds an element, and pop, which removes the top element. Stacks have applications in expression evaluation, parenthesis matching, and undo operations. A queue follows the FIFO (first in, first out) principle, with elements being inserted at the rear and removed from the front. Common queue operations are enqueue and dequeue. Queues are used in scheduling, printing, and resource allocation.
Data structures and Algorithm analysis_Lecture 2.pptxAhmedEldesoky24
This document discusses different data structures for lists, including abstract data types (ADTs), arrays, singly linked lists, and doubly linked lists. It describes common list operations like insert, remove, find, and their time complexities for each implementation. Array-based lists allow direct access but expensive updates. Linked lists have efficient insertion/deletion but slow random access. Doubly linked lists and circular lists add previous pointers for easier traversal in both directions.
Data Structure- Stack operations may involve initializing the stack, using it and then de-initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations −
PUSH, POP, PEEP
- Queues follow a First-In First-Out (FIFO) ordering principle where elements are inserted at the rear and removed from the front.
- Queues can be implemented using arrays or linked lists. Circular queues use arrays to avoid empty space issues.
- Priority queues order elements by priority rather than insertion order, with the highest priority element removed first. They have applications like job scheduling.
The document discusses data structures and abstract data types (ADTs). It provides examples of linear lists and linked lists as implementations of the ADT linear list. Key points made include:
- An ADT defines operations on a data structure without specifying its implementation.
- Linked lists provide flexibility for insertion and deletion compared to arrays.
- The main linked list operations are insertion, deletion, finding an element, and traversal.
- Queues and stacks are examples of linear lists with restricted insertion/deletion points.
The document discusses data structures and algorithms including stacks, queues, and their implementations using arrays and linked lists. Key points:
1. Stacks follow LIFO principle and allow insertion/removal at one end only. Queues follow FIFO principle. Both can be implemented using arrays or linked lists.
2. Common stack operations like push, pop, and peek have O(1) time complexity. Queue operations like enqueue and dequeue also have O(1) time complexity.
3. Linked list implementations of stacks and queues allocate memory dynamically and don't have size limits like arrays.
4. A circular queue treats the last node as connected to the first, forming a ring. This allows insertion
The document discusses various algorithms like priority queues, heaps, heap sort, merge sort, quick sort, binary search, and algorithms for finding the maximum and minimum elements in an array. It provides definitions and explanations of these algorithms along with code snippets and examples. Key steps of algorithms like heap sort, merge sort, and quick sort are outlined. Methods for implementing priority queues, binary search and finding max/min in optimal comparisons are also presented.
A queue is a linear data structure that follows the First In First Out (FIFO) principle, where elements are added to the rear of the queue and removed from the front. Elements can be added using the enqueue operation and removed using the dequeue operation. A queue can be implemented using an array or linked list. A circular queue was introduced to prevent wasted memory when the rear reaches the end of the array. Priority queues order elements by priority when removing them, with higher priority elements served first.
1.Introduction to Data Structures and Algorithms.pptxBlueSwede
This document provides an introduction to data structures and algorithms. It defines basic terminology like data, entities, information, and operations. It categorizes data structures as primitive and non-primitive. Primitive types include integers and characters, while non-primitive types are arrays, structures, and classes. Linear data structures like arrays maintain adjacency, while non-linear structures like trees and graphs do not. Common data structures like stacks, queues, linked lists, trees, and graphs are described along with their implementations and operations. The advantages of using abstract data types to encapsulate implementation details are also discussed.
This document discusses queues and their implementation using arrays and linked lists. It describes queues as first-in, first-out data structures where elements are added to the rear and removed from the front. Array and linked representations of queues are presented along with algorithms for insertion and deletion. Circular queues and their advantages over linear queues are also covered.
The document provides an introduction to embedded systems including definitions, explanations and comparisons to general purpose computer systems. It discusses the core components of embedded systems including hardware components like processors, memory and I/O as well as software components like operating systems and device drivers. It also covers various embedded system classifications, applications and communication interfaces.
The document discusses various aspects of embedded system development including development environments, integrated development environments (IDEs), cross compilation, debugger tools, and the overall product development life cycle. It describes the key components in development environments like host and target systems. It also explains concepts like cross compilation, types of files generated, and debugger tools. Finally, it summarizes the typical phases in an embedded product development life cycle from concept to maintenance.
1. Memory testing is an important part of embedded system development to ensure proper functionality.
2. Basic memory tests include data bus testing, address bus testing, and device testing.
3. Data bus testing uses techniques like walking 1's to write all possible data values and verify each bit. Address bus testing uses power-of-two addresses to isolate each address bit. Device testing writes data to addresses and checks for overwrites to test for overlapping addresses.
The document provides an introduction to embedded systems. It defines embedded systems as computing systems with tightly coupled hardware and software integration designed to perform dedicated functions. It discusses the differences between embedded systems and general purpose computers. Embedded systems are designed to perform specific tasks, use simplified circuits, require less memory, and are lower in cost compared to general purpose computers. The document also covers various components, software, and applications of embedded systems.
The document describes algorithms for scan converting primitive geometric objects like lines, circles, and ellipses. It explains Bresenham's line algorithm which uses integer arithmetic to efficiently determine the pixel locations along a line path, getting closer to the actual line than the traditional Digital Differential Analyzer (DDA) algorithm. It also covers the midpoint circle algorithm which uses distance comparison to test the midpoint between pixels to decide if it is inside or outside the circle boundary during scan conversion.
Rapid application development (RAD) aims to develop software quickly through a model with phases like business modeling, data modeling, process modeling, application generation, and testing. Business modeling defines information flow. Data modeling refines information into entities and attributes. Process modeling transforms data objects to support business functions. Automated tools help build the software. Testing reduces risk through component reuse and interface exercises. RAD requires tools like case tools, data dictionaries, storyboards, and risk registers. Advantages include quick reviews, isolation of problems, and flexibility, while disadvantages are lack of planning and need for skilled developers.
The document discusses various aspects related to sound and audio processing. It defines noise and sound, and describes the characteristics of sound like amplitude, wavelength, frequency, period, and waveform. It explains how the human ear can hear sounds within the frequency range of 20Hz to 20,000Hz. It also discusses sound processing components like microphones, amplifiers, and loudspeakers. Sound needs to be converted to digital format before processing using techniques like sampling, quantization, and code-word generation. Both lossy and lossless compression algorithms can be used to compress sound files.
Modern Operating System Windows Server 2008Sneha Chopra
Windows Server 2008 shares the same code base as Windows Vista, bringing many of the same technical, security, management and administrative features to servers. It includes improvements to installation, deployment, recovery, diagnostics, monitoring, firewall security, and virtualization capabilities. A Server Core installation provides a minimal interface for remote administration via command line. Active Directory is expanded with additional identity, rights and certificate management services.
3. What is Data Structure?
• A data structure is a structured set of variables
associated with one another in different ways,
cooperatively defining components in the system and
capable of being operated upon in the program.
• The following operations are done on data structures:
– Data organization or clubbing
– Accessing technique
– Manipulating selections for information.
• In computer science, data structure is a way of storing
data in a computer so it can be stored efficiently
4. Types of Data Structures
DATA STRUCTURE
LINEAR NON-LINEAR
TREES
ARRAYS STACK
QUEUE GRAPH
LINKED LIST
5. Types of Data Structures
• Data structures are classified into two main categories linear and non-
linear.
• A data is said to linear if its elements form a sequence.
• An array is a finite collection of similar elements stored in adjacent
memory locations.
• Linked list is a collection of elements called nodes each of which stores
two items one information and the other a link to the next element.
• A stack is a data structure in which addition of new elements or deletion
of old elements takes place at same end called top of stack.
• Queue is a linear data structure that permits insertion of new elements
takes place at one end and deletion of elements takes place at other end.
6. Types of Data Structures
• Elements in a data structure which do not form a
sequence are called as non-linear data structure.
• When any two vertices are connected by exactly one
path is called as tree.
• Forest can be defined as any two vertices connected by
at most one path.
• A graph can be defined as a set of dots (vertices and
nodes) joined by lines (the edges)
10. Stack
• A stack is a data structure in which addition of new elements and
deletion of old elements always takes place at same end known as
top of stack
• Stack is one of the most useful concepts which play a permanent
role in programming.
• In stack he last item to be inserted will be the first to be removed.
• This is why stack is referred to as LAST IN FIRST OUT [LIFO].
• If there are no items in stack then it is called as empty stack.
13. Stack Operations
• We can insert or delete an element from a list,
which takes place from one end.
• When an item is added to the stack the operation
is called "push" and when it is removed the
operation is called "pop".
• Due to the push operation from one end,
elements are added to the stack, the stack is also
known as pushdown list.
14. Stack Operations
• The following fundamental operations on stack:
– Creating a stack
– Checking stack—either empty or full
– Initializing a stack
– Insert (push) an element in the stack
– Delete (pop) an element from the stack
– Access the top element (peek)
– Display elements of stack
– Status: to identify present position of stack.
15. Stack Algorithm – Adding Elements
• Variables: int size=10, top=-1;
Object stack[10];
• Proc: void push(Object item)
• begin
if top is equal to size
then display stack_full;
else
top = top+1;
stack[top] = item;
end
16. Stack – Removing Elements
• Variables: int size=10, top=-1;
Object stack[10];
• Proc: Object pop()
• begin
if top is equal to -1
then stack_empty;
else
item = stack[top];
top = top-1;
end
18. Infix to Postfix conversion
• Rules
– If incoming operator has more precedence than top of stack
than push operator into stack.
– If incoming operator has less or equal precedence than top of
stack than operator is popped and incoming operator is pushed.
– If we encounter a right parenthesis “)”, keep performing pop
from the stack until we get matching left parenthesis. Do not
output parenthesis.
• HIGHEST PRIORITY: exponentiation ($, ^)
• MIDDLE PRIORITY: multiply (*) and divide (/)
• LOWEST PRIORITY: addition (+) and subtraction (-)
19. Infix to Postfix Example
A + B * C - D / E
Infix Stack(bot->top) Postfix
A + B * C - D / E
+ B * C - D / E A
B * C - D / E + A
* C - D / E + A B
C - D / E + * A B
- D / E + * A B C
D / E + - A B C *
/ E + - A B C * D
E + - / A B C * D
+ - / A B C * D E
A B C * D E / - +
20. Postfix Evaulation
Operand: push
Operator: pop 2 operands, do the math, push result
back onto stack
1 2 3 + *
Postfix Stack( bot -> top )
a) 1 2 3 + *
b) 2 3 + * 1
c) 3 + * 1 2
d) + * 1 2 3
e) * 1 5 // 5 from 2 + 3
f) 5 // 5 from 1 * 5
22. Introduction
• Queue is a linear data structure that permits insertion of a
new element at one end and deletion of element at the
other end.
• The end at which deletion of element takes place is known
as FRONT and the end at which addition of new elements
takes place is known as REAR.
• The first element that gets added into queue is the first to
get deleted.
• Hence queue is also referred to as FIFO list First In First
Out.
24. Adding elements in queue
• Variables: int size=10, front=0, rear=-1;
Object stack[10];
• Proc: void add(Object item)
• begin
if rear is equal to n
then queue_full
else begin
rear :=rear+1;
q[rear]:=item;
end;
end
25. Deleting elements from queue
• begin
if front = rear then queue_empty
else begin
front := front+1
item := q[front];
end;
end;
27. Introduction
• Alternate approach to maintaining an array of
elements
• Rather than allocating one large group of elements,
allocate elements as needed
• Q: how do we know what is part of the array?
A: have the elements keep track of each other
– use pointers to connect the elements together as a LIST of
things
28. Linked List
• A linked list is a series of connected nodes
• Each node contains at least
– A piece of data (any type)
– Pointer to the next node in the list
• Head: pointer to the first node
• The last node points to NULL
31. Introduction
• A sorting algorithm is an algorithm that puts
elements of a list in a certain order.
• Some of the sorting techniques are:
– Selection sort
– Bubble sort
– Quick sort
– Merge sort
32. Selection Sort
• In this method to sort data in ascending order the 0th element is
compared with all the other elements.
• If the 0th element is found to be greater than the compared
element then they are interchanged.
• So after the first iteration the smallest element is placed at the 0th
position.
• The same procedure is repeated for the first element and so on.
• So if there are n elements than after n-1 iterations the array
becomes sorted.
35. Bubble Sort
• In this method to sort data in ascending order the 0th element is compared
with the 1st element.
• If found to b greater than the positions are interchanged.
• Than the 1st element is compared with the 2nd element if found to be
greater than they are interchanged.
• In the same way all elements except the last are compared with the next
element and interchanged if required.
• This is the 1st iteration and on completion the largest gets stored at the
last position.
• As a result after all iterations the list becomes a sorted list.
• If there are n elements than after n-1 iterations the array becomes sorted
38. Quick Sort
• This algorithm is based on the fact that it is easier and
faster to sort two small arrays than one large one.
• The basic strategy of quick sort is to divide and
conquer.
• Quick sort is also known as partition exchange sort.
• Quick sort may be defined conveniently by using
recursive procedure
39. Quick Sort
• The basic divide-and-conquer process for sorting a subarray
S[p..r] is summarized in the following three easy steps:
Divide: Partition S[p..r] into two subarrays S[p..q-1] and S[q+1..r]
such that each element of S[p..q-1] is less than or equal to S[q],
which is, in turn, less than or equal to each element of S[q+1..r].
Compute the index q as part of this partitioning procedure
Conquer: Sort the two subarrays S[p...q-1] and S[q+1..r] by
recursive calls to quicksort.
Combine: Since the subarrays are sorted in place, no work is
needed to combing them: the entire array S is now sorted.
40. Quick Sort
• The divide-and-conquer strategy is used in quicksort. Below the
recursion step is described:
• Choose a pivot value. We take the value of the middle element as
pivot value, but it can be any value, which is in range of sorted
values, even if it doesn't present in the array.
• Partition. Rearrange elements in such a way, that all elements
which are lesser than the pivot go to the left part of the array and
all elements greater than the pivot, go to the right part of the array.
Values equal to the pivot can stay in any part of the array. Notice,
that array may be divided in non-equal parts.
• Sort both parts. Apply quicksort algorithm recursively to the left
and the right parts.
42. Merge Sort
• Merging means combining two sorted lists into one list.
• For this the elements from both the sorted lists are
compared.
• The smaller of both the elements is than sorted in the
third array.
• The sorting s complete when all the elements from
both the lists are placed in the third list.
43. Merge Sort
• Suppose array a & b contain 5 elements each. Than merge sort algorithm
works as follows:
• The arrays a & b are sorted using any algorithm
• The 0th element from 1st array is compared with the 0th element in the 2nd
array. The smaller of the two is placed in the 3rd array.
• Now the biggest of them is compared with the 1st element of the other array.
• The smaller of the two is placed in the third array.
• The same procedure is repeated till end of one of the arrays is reached.
• The remaining elements from the other array are placed directly into the third
list as they are already in the sorted order.
44. Merge Sort – Algorithm
• To sort the entire sequence A[1 .. n], make the initial call to
the procedure MERGE-SORT (A, 1, n).
• MERGE-SORT (A, p, r)
1. IF p < r // Check for base
2. THEN q = FLOOR[(p + r)/2] // Divide step
3. MERGE (A, p, q) // Conquer step.
4. MERGE (A, q + 1, r) // Conquer step.
5. MERGE (A, p, q, r) // Conquer step.
47. Introduction
• Searching is an operation which finds the
location of a given element in a list.
• The search is said to be successful or
unsuccessful depending on whether the
element that is being searched for is found or
not.
48. Linear Search
• This is the simplest method of searching.
• In this method the element to be found is sequentially
searched in the list.
• This method can be applied to a sorted or an unsorted
array.
• Searching in case of a sorted list starts from the 0th
element and continues until the element is found or an
element whose value is greater than the value being
searched is reached.
• Searching in case of an unsorted list starts from 0th
element and continues until element is found or end or
list is reached
49. Unsorted List – Linear Search
FOR (I=0; I<N-1;I++)
{
IF (ARR [ I ] = = NUM)
BREAK
}
IF (I = = 10)
PRINT (NO. NOT PRESENT)
ELSE
PRINT (NO. PRESENT)
50. Sorted List – Linear Search
FOR (I=0; I<N-1;I++)
{
IF (ARR [9] < NUM | | ARR [I] >= NUM)
{
IF (ARR [I] = = NUM)
PRINT (PRESENT)
ELSE
PRINT (ABSCENT)
BREAK
}
}
51. Binary Search
– This method is very fast and efficient.
– This search requires the list of elements to be in sorted
order.
– In this method to search for an element we compare with
the element present at the centre of the list.
– If it matches than the search is successful.
52. Binary Search
– Otherwise the list is divided into two halves:
– One from the 0th element to the centre of the list.
– The other from the centre to the end of the list.
– As a result all the elements in the first half are smaller than the centre
element whereas all elements in the second half are greater than the center
element.
– The searching will now precede in either of t he two halves depending on
whether the element is greater or smaller than the middle element.
– Same process of comparing the center element and then dividing the array is
repeated for the first or second half.
– This process is repeated till element is found or division results in one element
53. Binary Search – Algorithm
WHILE (NOT END OF INPUT)
{
LOW = 0
HI = N-1
WHILE (LOW<= HI)
{
MID = (LOW + HI) / 2
IF (KEY = = K [MID])
RETURN MID
IF (KEY < K [MID])
HI = MID – 1
ELSE
LOW = MID + 1
}
}
55. Introduction
• Definition: A binary tree, T, is either empty or
such that:
– T has a special node called the root node;
– T has two sets of nodes, LT and RT, called the left
subtree and right subtree of T, respectively;
– LT and RT are binary trees
57. Binary Tree - Terms
• Leaf: node that has no left and right children
• Parent: node with at least one child node
• Level of a node: number of branches on the path
from root to node
• Height of a binary tree: number of nodes no the
longest path from root to node
58. Binary Tree – Traversal
• Inorder
– Traverse the left subtree
– Visit the node
– Traverse the right subtree
• Preorder
– Visit the node
– Traverse the left subtree
– Traverse the right subtree
• Postorder
– Traverse the left subtree
– Traverse the right subtree
– Visit the node