Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Data Structure notes, Exercises of Data Structures and Algorithms

An online study material for the 3rd semester of B.Sc Computer Science & BCA at Majlis Arts and Science College, Puramannur. It covers topics such as postfix notation, sparse matrix, recursion, linked lists, linear arrays, and insertion and deletion operations. The document also includes algorithms for insertion in a singly linked list, infix to postfix conversion, and inserting an element in a linear linked list.

Typology: Exercises

2019/2020

Available from 10/04/2022

Tinutony
Tinutony 🇮🇳

8 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MAJLIS ARTS AND SCIENCE COLLEGE, PURAMANNUR
DEPARTMENT OF COMPUTER SCIENCE
DATA STRUCTURES USING C (3rd Semester Online
Study Material)
B.Sc Computer Science &
BCA
(Questions and answers based on second Module)
1. Convert ((A+B)*C)(E-F) to postfix
Ans: AB+C*EF-*
2. Define polish notation.
Ans:
An expression is called the prefix expression if the operator appears in the expression before the operands.
Prefix notation is also known as Polish Notation.
3. Define sparse matrix.
Ans: If most of the elements of the matrix have 0 (zero)value, then it is called a sparse matrix.
4. Define recursion.
Ans: A function calls itself is called recursion
5. Node is collection of --------
Ans: data and link
6. Clarify whether linked list is linear or non linear.
Ans: Linear
7. How to represent two way linked list.
Ans: A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer, together with next
pointer and data which are there in singly linked list.
8. Define circular linked list.
Ans: Circular linked list is a linked list where all nodes are connected to form a circle. There is no NULL at the end.
9. What is linear array? What are the different operations on array.
Ans:
An array is a list of finite number of n homogeneous data elements.(i.e. data elements of the same type) such that
The elements of an array are referenced by an index.
Elements of array stored at contiguous memory locations.
This makes it easier to calculate the position of each element by simply adding an offset to a base value.
Traversal
Insertion
Deletion
Traversal
It prints all the array elements one after another.
Algorithm
LA is a linear array with lower bound LB and upper bound UB.
step 1: set k=LB
step 2: Repeat steps 3 and 4 while k<=UB
pf3
pf4
pf5

Partial preview of the text

Download Data Structure notes and more Exercises Data Structures and Algorithms in PDF only on Docsity!

MAJLIS ARTS AND SCIENCE COLLEGE, PURAMANNUR

DEPARTMENT OF COMPUTER SCIENCE

DATA STRUCTURES USING C (3rd^ Semester Online Study Material) B.Sc Computer Science & BCA (Questions and answers based on second Module)

  1. Convert ((A+B)C)(E-F) to postfix Ans: AB+CEF-*
  2. Define polish notation. Ans: An expression is called the prefix expression if the operator appears in the expression before the operands. Prefix notation is also known as Polish Notation.
  3. Define sparse matrix. Ans: If most of the elements of the matrix have 0 (zero)value, then it is called a sparse matrix.
  4. Define recursion. Ans: A function calls itself is called recursion
  5. Node is collection of -------- Ans: data and link
  6. Clarify whether linked list is linear or non linear. Ans: Linear
  7. How to represent two way linked list.

Ans: A D oubly L inked L ist (DLL) contains an extra pointer, typically called previous pointer , together with next

pointer and data which are there in singly linked list.

  1. Define circular linked list. Ans: Circular linked list is a linked list where all nodes are connected to form a circle. There is no NULL at the end.
  2. What is linear array? What are the different operations on array. Ans: An array is a list of finite number of n homogeneous data elements.(i.e. data elements of the same type) such that The elements of an array are referenced by an index. Elements of array stored at contiguous memory locations. This makes it easier to calculate the position of each element by simply adding an offset to a base value.

Traversal Insertion Deletion Traversal It prints all the array elements one after another. Algorithm LA is a linear array with lower bound LB and upper bound UB. step 1: set k=LB step 2: Repeat steps 3 and 4 while k<=UB

step 3: Apply visit to LA[k] step 4: set k=k+ step 5: exit Insertion It adds an element at given index. Algorithm INSERT(LA,N,K,ITEM) LA is a linear array with N elements and K is a positive integer K<=N. This algorithm inserts an element ITEM into the Kth position in LA. Step 1: set J=N step 2: Repeat steps 3 and 4 while J>=K step 3: set LA[J+1]=LA[J] step 4: set J=J- step 5: set LA[K]=ITEM step 6: set N=N+ step 7: exit Deletion Operation of removing one of the elements from LA. Algorithm DELETE(LA,N,K,ITEM) LA is a linear array with N elements and K is a positive integer ,K<=N. This algorithm deletes the Kth element from LA. step 1: set ITEM=LA[K] step 2: Repeat for J=K to N- step 3: set LA[J]=LA[J+1] step 4: set N=N- step 5: exit

  1. Write an algorithm for insertion in a singly linked list.
  2. What is the main difference between array and linked list? Ans: An array is a list of finite number of n homogeneous data elements.(i.e. data elements of the same type) such that The elements of an array are referenced by an index. Elements of array stored at contiguous memory locations. This makes it easier to calculate the position of each element by simply adding an offset to a base value.

B : Base address of the array w : Size of each element of the array L1 : lower bound of row L2 : lower bound of column

Find memory location in row major order

Eg: find location of A[4]=A[1][0] Row major address = B + w * (N * (i-L1) + j-L2) here, B= w = L1=L2=0 N= A[1 ][0] location=200+2[3*(1-0)+(0-0)] =200+ 6=

Find memory location in column major order

Eg: find location of A[4]=A[1][0] Column major address = B + w * (M * (j-L2) + (i-L1)) here, B= w = L1=L2=0 M= A[1 ][0] location=200+2[2(0-0)+(1-0)] =200+ 2=

  1. What are the different types of notations? Infix : An expression is called the Infix expression if the operator appears in between the operands in the expression.

Example : A+B (A+B) * (C-D) Prefix : An expression is called the prefix expression if the operator appears in the expression before the operands. Prefix notation is also known as Polish Notation.

Example : infix prefix A+B +AB (A+B) * (C-D) *+AB-CD Postfix : An expression is called the postfix expression if the operator appears in the expression after the operands. Postfix notation is also known as Reverse Polish Notation or Suffix.

Example : infix postfix A+B AB+

(A+B) * (C-D) AB+CD-*

  1. Write an algorithm to convert infix to postfix conversion. Ans:
  2. Write an algorithm to insert an element in linear linked list. Ans: Overflow Sometimes new data are to be inserted into a data structure but there is no available space, i.e, the free storage list is empty. This situation is called overflow. AVAIL = NULL Underflow START = NULL INSERTION FIRST

MIDDLE

LAST

Insert first