


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Comprehensive B.Tech semester exam notes for Data Structures (DS) and Basic Electrical Engineering (BEE). Includes important theory questions, definitions, derivations, algorithms, short notes, diagrams, solved examples, and previous exam-oriented topics. Covers hashing, trees, graphs, sorting, searching, files, transformers, DC machines, AC circuits, semiconductor devices, Hall effect, lasers, quantum computing basics, and more. Useful for JNTUH engineering students for semester exam preparation and quick revision. Suitable for CSE, ECE, EEE, and related engineering branches.
Typology: Slides
1 / 42
This page cannot be seen from the preview
Don't miss anything!



































Graph is a non-linear data structure. It contains a set of points known as nodes (or vertices) and a set of links known as edges (or Arcs). Here edges are used to connect the vertices. A graph is defined as follows...
We use the following terms in graph data structure... Vertex Individual data element of a graph is called as Vertex. Vertex is also known as node. In above example graph, A, B, C, D & E are known as vertices. Edge An edge is a connecting link between two vertices. Edge is also known as Arc. An edge is represented as (startingVertex, endingVertex). For example, in above graph the link between vertices A and B is represented as (A,B). In above example graph, there are 7 edges (i.e., (A,B), (A,C), (A,D), (B,D), (B,E), (C,D), (D,E)). Edges are three types.
1. Undirected Edge - An undirected egde is a bidirectional edge. If there is undirected edge between vertices A and B then edge (A , B) is equal to edge (B , A). 2. Directed Edge - A directed egde is a unidirectional edge. If there is directed edge between vertices A and B then edge (A , B) is not equal to edge (B , A). 3. Weighted Edge - A weighted egde is a edge with value (cost) on it.
Undirected Graph A graph with only undirected edges is said to be undirected graph. Directed Graph A graph with only directed edges is said to be directed graph. Mixed Graph A graph with both undirected and directed edges is said to be mixed graph. End vertices or Endpoints The two vertices joined by edge are called end vertices (or endpoints) of that edge. Origin If a edge is directed, its first endpoint is said to be the origin of it. Destination If a edge is directed, its first endpoint is said to be the origin of it and the other endpoint is said to be the destination of that edge. Adjacent If there is an edge between vertices A and B then both A and B are said to be adjacent. In other words, vertices A and B are said to be adjacent if there is an edge between them. Incident Edge is said to be incident on a vertex if the vertex is one of the endpoints of that edge. Outgoing Edge A directed edge is said to be outgoing edge on its origin vertex. Incoming Edge A directed edge is said to be incoming edge on its destination vertex. Degree Total number of edges connected to a vertex is said to be degree of that vertex. Indegree Total number of incoming edges connected to a vertex is said to be indegree of that vertex.
Directed graph representation... Incidence Matrix In this representation, the graph is represented using a matrix of size total number of vertices by a total number of edges. That means graph with 4 vertices and 6 edges is represented using a matrix of size 4X6. In this matrix, rows represent vertices and columns represents edges. This matrix is filled with 0 or 1 or -1. Here, 0 represents that the row edge is not connected to column vertex, 1 represents that the row edge is connected as the outgoing edge to column vertex and -1 represents that the row edge is connected as the incoming edge to column vertex. For example, consider the following directed graph representation... Adjacency List In this representation, every vertex of a graph contains list of its adjacent vertices. For example, consider the following directed graph representation implemented using linked list...
This representation can also be implemented using an array as follows..
Graph traversal is a technique used for a searching vertex in a graph. The graph traversal is also used to decide the order of vertices is visited in the search process. A graph traversal finds the edges to be used in the search process without creating loops. That means using graph traversal we visit all the vertices of the graph without getting into looping path. There are two graph traversal techniques and they are as follows...
Sorting Sorting is the process of arranging a list of elements in a particular order (Ascending or Descending). Insertion Sort Insertion sort algorithm arranges a list of elements in a particular order. In insertion sort algorithm, every iteration moves an element from unsorted portion to sorted portion until all the elements are sorted in the list. The insertion sort algorithm is performed using the following steps...
//Insertion Sorting #include void main() { int size, i, j, temp, list[100]; printf("Enter the size of the list: "); scanf("%d", &size); printf("Enter %d integer values: ", size); for (i = 0; i < size; i++) scanf("%d", &list[i]); //Insertion sort logic for (i = 1; i < size; i++) { temp = list[i]; j = i - 1; while ((temp < list[j]) && (j >= 0)) { list[j + 1] = list[j]; j = j - 1; } list[j + 1] = temp; } printf("List after Sorting is: "); for (i = 0; i < size; i++) printf(" %d", list[i]); }
Bubble sort Bubble sort is a simple sorting algorithm. This sorting algorithm is comparison-based algorithm in which each pair of adjacent elements is compared and the elements are swapped if they are not in order. This algorithm is not suitable for large data sets as its average and worst case complexity are of Ο(n^2 ) where n is the number of items. Ex: We take an unsorted array for our example. Bubble sort takes Ο(n^2 ) time so we're keeping it short and precise. Bubble sort starts with very first two elements, comparing them to check which one is greater. //Selection Sort #include void main() { int size,i,j,temp,list[100]; printf("Enter the size of the List: "); scanf("%d",&size); printf("Enter %d integer values: ",size); for(i=0; i list[j]) { temp=list[i]; list[i]=list[j]; list[j]=temp; } } } printf("List after sorting is: "); for(i=0; i And when there's no swap required, bubble sorts learns that an array is completely sorted. Heap Sort Heap sort is one of the sorting algorithms used to arrange a list of elements in order. Heapsort algorithm uses one of the tree concepts called Heap Tree. In this sorting algorithm, we use Max Heap to arrange list of elements in Descending order and Min Heap to arrange list elements in Ascending order. Max Heap Heap data structure is a specialized binary tree-based data structure. Heap is a binary tree with special characteristics. In a heap data structure, nodes are arranged based on their values. A heap data structure some times also called as Binary Heap. There are two types of heap data structures and they are as follows...
Max Heap
Min Heap //Bubble Sort #include int main() { int a[50],n,i,j,temp; printf("Enter the size of array: "); scanf("%d",&n); printf("Enter the array elements: "); for(i=0;ia[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } printf("\nArray after sorting: "); for(i=0;i Every heap data structure has the following properties... 1 (Ordering): Nodes must be arranged in an order according to their values based on Max heap or Min heap. 2 (Structural): All levels in a heap must be full except the last level and all nodes must be filled from left to right strictly. Max heap data structure is a specialized full binary tree data structure. In a max heap nodes are arranged based on node value. Max heap is a specialized full binary tree in which every parent node contains greater or equal value than its child nodes. Ex: Above tree is satisfying both Ordering property and Structural property according to the Max Heap data structure. Operations Finding Maximum Value Finding the node which has maximum value in a max heap is very simple. In a max heap, the root node has the maximum value than all other nodes. So, directly we can display root node value as the maximum value in max heap. Insertion Insertion Operation in max heap is performed as follows...
Insert the newNode as last leaf from left to right.
Compare newNode value with its Parent node.
If newNode value is greater than its parent, then swap both of them.
Repeat step 2 and step 3 until newNode value is less than its parent node (or) newNode reaches to root. Ex: Consider the above max heap. Insert a new node with value 85.