Posts

Balanced parentheses and Reversing list

Image
    To check for balanced parentheses in C, a  Stack  data structure is used to ensure every opening bracket has a matching closing bracket in the correct order Algorithm Initialize  an empty stack. Traverse  the expression: Push  opening brackets ((, {, [) onto the stack. Pop  and check for matches if a closing bracket (), }, ]) appears. If the stack is empty at a closing bracket, or if a match fails, the expression is not balanced. Final Check : The expression is balanced only if the stack is empty at the end. Program : #include <stdio.h> #include <string.h> #define MAX 100 char stack[MAX]; int top = -1; // Push function void push(char c) {                if (top == MAX - 1) {                   ...

Data Structures R23 UNIT-1&2

                                    Data Structures Short questions Unit-1: 1. Define Data Structure. A data structure is a way of organizing and storing data so that it can be accessed and modified efficiently. 2. What are the different types of data structures? Two types: Linear Data Structures Non-Linear Data Structures 3. What is a linear data structure? A linear data structure stores elements sequentially where each element is connected to the next element. 4. What is a non-linear data structure? A non-linear data structure stores elements hierarchically and elements are not arranged sequentially. 5. Give two examples of linear data structures. Array Linked List 6. Give two examples of non-linear data structures. Tree Graph 7. Define Abstract Data Type (ADT). An ADT is a logica...

Data Structure- Algorithm Introduction

 What is an algorithm?   An algorithm is a finite set of step by step instructions to solve a problem. In normal language, algorithm is defined as a sequence of statements which are used to perform a task.  In computer science, an algorithm can be defined as follows:   An algorithm is a sequence of unambiguous instructions used for solving a problem, which can be implemented (as a program) on a computer.   Properties Every algorithm must satisfy the following properties:   1. Definiteness - Every step in an algorithm must be clear and unambiguous  2. Finiteness – Every algorithm must produce result within a finite number of steps.  3. Effectiveness - Every instruction must be executed in a finite amount of time.  4. Input & Output - Every algorithm must take zero or more number of inputs and must produce at least one output as result.  1.2 Performance Analysis In computer science there are multiple algorithms...