Posts

Data Structures Lab PCCSL 307 KTU BTech 2024 Scheme - Experiments and Reference

  Expt. No. Experiments 1 Find the sum of two sparse polynomials using arrays 2 Find the transpose of a sparse matrix and sum of two sparse matrices. 3 Convert infix expression to postfix(or prefix)and then evaluate using stack, 4 Implement Queue,DEQUEUE,and Circular Queue using arrays. 5 Implement backward and forward navigation of visited web pages in a web browser(i.e.back and forward buttons)using doublyl inked list operations. 6 Implement addition and multiplication of polynomials using singly linked lists. 7 Create a binary tree for a given simple arithmetic expression and find the prefix /postfix equivalent. 8 Implement a dictionary of word-meaning pairs using binary search trees. 9 Find the shortest distance of every cell from a land mine inside a maze.   ...

Polynomial Addition using Arrays

Polynomial  Addition We can represent a polynomial as a collection of terms and every term is having a coefficient and exponent. So, we can represent this as a list of terms having coefficients and exponents.  Each term of a polynomial (like 3 x 2 3x^2 , 5 x 1 5x^1 , − 7 x 0 -7x^0 ) can be stored in a structure having two parts: coefficient (like 3, 5, -7) exponent (like 2, 1, 0) An array of such structures represents the whole polynomial. Structure Definition (Example in C) struct Term { int coeff; // Coefficient of the term int expo; // Exponent of the term }; And then you can declare: struct Term poly1 [10], poly2 [10], polyResult [20]; to represent polynomials. Algorithm to Add Two Polynomials Assumption : Both polynomials are sorted in decreasing order of exponents . Steps : Initialize three pointers (indexes): i = 0 for first polynomial (poly1), j = 0 for second polynomial (poly2), k = 0 for result polynomial (polyR...

Sparse Matrix - Transpose and Addition

Image
  A sparse matrix is a special type of matrix in which most of the elements are zero or have some default value. In contrast, a dense matrix is one in which most of the elements are non-zero. Sparse matrices are used in various fields, including computer science, numerical analysis, and scientific computing, when dealing with large datasets or systems where efficiency and memory usage are crucial.   As a rule of thumb, if 2/3 of the total elements in a matrix are zeros, it can be called a sparse matrix . Using a sparse matrix representation — where only the non-zero values are stored — the space used for representing data and the time for scanning the matrix are reduced significantly. In many real-world problems — like graphs, networks, or scientific simulations — the majority of elements in the matrix are zero . Such a matrix is called a Sparse Matrix . Formally: A matrix in which the number of zero elements is significantly greater than the number of non-zero elements. ...