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 contains questions and answers based on the first module of the course, covering topics such as binary search algorithm, data structure, space time tradeoff of algorithm, Big-O notation, and different operations that can be performed on different data structures. The document also includes applications of data structure and their importance.

Typology: Exercises

2019/2020

Available from 10/04/2022

Tinutony
Tinutony 🇮🇳

8 documents

1 / 5

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 First Module)
1. Complexity of binary search algorithm is -------
Ans: n logn
2. Logical or mathematical model of particular organization of data is called ---------
Ans: data structure
3. Define data structure?
Ans: Logical or mathematical model of particular organization of data
4. What is a data?
Ans: a single value or a set of values
5. Briefly describe the notation of the space time tradeoff of algorithm.
Ans:
Time complexity is a function describing the amount of time an algorithm takes in terms of the amount
of input to the algorithm.
Space complexity is a function describing the amount of memory (space) an algorithm takes in terms of
the amount of input to the algorithm.
Big O notation is the language we use for talking about how long an algorithm takes to run. Order of
magnitude is often called Big-O notation (for “order”) and written as O(f(n)).
Common Functions for Big-O
F(n) Name
1
Constant
logn
Logarithmic
n
Linear
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 ( 3 rd^ Semester Online Study Material) B.Sc Computer Science & BCA (Questions and answers based on First Module)

  1. Complexity of binary search algorithm is ------- Ans: n logn
  2. Logical or mathematical model of particular organization of data is called --------- Ans: data structure
  3. Define data structure? Ans: Logical or mathematical model of particular organization of data
  4. What is a data? Ans: a single value or a set of values
  5. Briefly describe the notation of the space time tradeoff of algorithm. Ans: Time complexity is a function describing the amount of time an algorithm takes in terms of the amount of input to the algorithm. Space complexity is a function describing the amount of memory (space) an algorithm takes in terms of the amount of input to the algorithm. Big O notation is the language we use for talking about how long an algorithm takes to run. Order of magnitude is often called Big-O notation (for “order”) and written as O(f(n)). Common Functions for Big-O F(n) Name 1 Constant logn Logarithmic n Linear

nlog n Log Linear n^2 Quadratic n^3 Cubic 2 n^ Exponential Eg: Linear search : O(n) Binary search : O(log n) Bubble sort : O(n^2 ) Merge sort : O(n log n)

  1. Write different applications of data structure. Ans:
  2. Dynamic memory allocation
  3. Maintaining directory of names
  4. Performing arithmetic operations on long integers
  5. History of visited websites
  6. job scheduling
  7. What is the importance of Big-O notation? Ans: It is used to classify algorithms according to how their run time or space requirements grow as the input size grows.
  8. What are the different operations that can be performed on different data structure? Ans:  Operation means processing the data in the data structure.  The following are some important operations. a. Traversing b. Searching c. Inserting d. Deleting

Non- primitive data types are again divided into 2

  1. Linear
  2. Non – linear Linear Data structures:  This Data Structures involve arranging the elements in linear fashion. Eg: Stacks, Queue, Lists Non- Linear Data structures:  This Data structures involve representing the elements in Hierarchical order. Eg: Trees, Graphs
  3. Define string? Explain different string operations. Ans: Strings are defined as an array of characters. The difference between a character array and a string is the string is terminated with a special character ‘\0’. Operations:
  1. Length: Find length of the string. [Number of characters in a string is called its length.] Eg: s=”computer’ Length(s) = 8
  2. Substring: Accessing a substring from a given string. SUBSTRING(string, initial,length) Eg: S=”TO BE OR NOT TO BE” , 3,4) =BE O
  3. Concatenation: let S1 and S2 be strings s1//s2 is the string consisting of the characters of s followed by the characters of s2. Eg: S1= ‘welcome” S2=”majlis” S1//s2=” welcomemajlis”
  4. Indexing (pattern matching): find the position where a string pattern P Firstappears in a given string T. Eg: T=”welcome to majlis college” INDEX(T,”to”) =
  1. Explain Pattern matching algorithm Ans: Pattern matching algorithm Pattern Searching algorithms are used to find a pattern or substring from another bigger string. There are different algorithms. The main goal to design these types of algorithms to reduce the time complexity. The traditional approach may take lots of time to complete the pattern searching task for a longer text. Example: Main String: “ABAAABCDBBABCDDEBCABC”, Pattern “ABC” Output: Pattern found at position: 4 Pattern found at position: 10 Pattern found at position: 18 Algorithm: P and T are strings with length R and S.
  2. set k=1 and MAX= S – R +
  3. Repeat steps 3 to 5 while K<=MAX
  4. Repeat for L=1 to R If P[L]≠T[K+L-1] then goto step 5
  5. Set INDEX= K and exit
  6. Set K=K+
  7. Set INDEX= 7.Exit