The document discusses algorithms and data structures. It defines an algorithm and provides examples. It also defines different types of data structures including linear structures like arrays, stacks, queues and linked lists as well as non-linear structures like trees and graphs. Popular tree and graph based data structures are also mentioned.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
18 views
Notes For Dsa
The document discusses algorithms and data structures. It defines an algorithm and provides examples. It also defines different types of data structures including linear structures like arrays, stacks, queues and linked lists as well as non-linear structures like trees and graphs. Popular tree and graph based data structures are also mentioned.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4
NOTES FOR DSA • Algorithm to check prime number In linear data structures, the elements are
arranged in sequence one after the other. Since
What is an Algorithm? • Algorithm of Fibonacci series elements are arranged in particular order, they In computer programming terms, an algorithm Algorithm 1: Add two numbers entered by the are easy to implement. However, when the is a set of well-defined instructions to solve a user complexity of the program increases, the linear particular problem. It takes a set of input(s) and data structures might not be the best choice Step 1: Start because of operational complexities. produces the desired output. For example, Step 2: Declare variables num1, num2 and sum. An algorithm to add two numbers: Step 3: Read values num1 and num2. Popular linear data structures are: 1. Take two number inputs Step 4: Add num1 and num2 and assign the 1. Array Data Structure 2. Add numbers using the + operator result to sum. 3. Display the result In an array, elements in memory are arranged in sum←num1+num2 continuous memory. All the elements of an Qualities of a Good Algorithm array are of the same type. And, the type of Step 5: Display sum • Input and output should be defined elements that can be stored in the form of Step 6: Stop arrays is determined by the programming precisely. What are Data Structures? language. • Each step in the algorithm should be clear and unambiguous. Data structure is a storage that is used to store and organize data. It is a way of arranging data • Algorithms should be most effective on a computer so that it can be accessed and among many different ways to solve a problem. updated efficiently. • An algorithm shouldn't include 2. Stack Data Structure Depending on your requirement and project, it computer code. Instead, the algorithm should is important to choose the right data structure In stack data structure, elements are stored in be written in such a way that it can be used in for your project. For example, if you want to the LIFO principle. That is, the last element different programming languages. store data sequentially in the memory, then you stored in a stack will be removed first. It works Algorithm Examples can go for the Array data structure. just like a pile of plates where the last plate kept • Algorithm to add two numbers Note: Data structure and data types are slightly on the pile will be removed first. different. Data structure is the collection of data • Algorithm to find the largest among types arranged in a specific order. three numbers What are the types of Data Structure? • Algorithm to find all the roots of the quadratic equation I. Linear Data Structure
• Algorithm to find the factorial
In graph data structure, each node is called vertex and each vertex is connected to other 3. Queue Data Structure vertices through edges. Unlike stack, the queue data structure works in Popular Graph Based Data Structures: the FIFO principle where first element stored in the queue will be removed first. It works just • Spanning Tree and Minimum Spanning like a queue of people in the ticket counter Tree LINEAR VS NON LINEAR where first person on the queue will get the • Strongly Connected Components ticket first. LINEAR NON LINEAR • Adjacency Matrix The data items are The data items are arranged in arranged in non- • Adjacency List sequential order, one sequential order after the other. (hierarchical manner). All the items are The data items are 4. Linked List Data Structure present on the single present at different In linked list data structure, data elements are layer. layers. connected through a series of nodes. And, each It can be traversed It requires multiple 2. Trees Data Structure on a single run. That runs. That is, if we node contains the data items and address to the is, if we start from start from the first next node. Similar to a graph, a tree is also a collection of the first element, we element it might not vertices and edges. However, in tree data can traverse all the be possible to structure, there can only be one edge between elements traverse all the two vertices. sequentially in a elements in a single II. Non-Linear Structure Popular Tree based Data Structure: single pass. pass. The memory Different structures Unlike linear data structures, elements in non- • Binary Tree utilization is not utilize memory in linear data structures are not in any sequence. efficient. different efficient Instead, they are arranged in a hierarchical • Binary Search Tree ways depending on manner where one element will be connected • AVL Tree the need. to one or more elements. Non-linear data The time complexity Time complexity structures are further divided into graph and • B-Tree increase with the remains the same. tree-based data structures. data size. • B+ Tree Example: Arrays, Example: Tree, • Red-Black Tree Stack, Queue Graph, Map 1. Graph Data Structure Why Data Structure? Knowledge about data structures help you understand the working of each data structure. And, based on that you can select the right data structures for your project. This helps you write memory and time efficient code.