Professional Documents
Culture Documents
Solution of Data Structure
Solution of Data Structure
(OBJECTIVE)
SECTION – A
Time allowed: 15 minutes Marks: 10
Note: Each statement carries one mark. Cutting & overwriting is not allowed.
Q.1: Encircle the correct option.
i. Best Algorithm is
a. Solve with in minimum time. b. Give good accuracy
c. Minimum time d. Minimum cost
x. If queue have five spaces and 50% queue is full, remaining places are
a. One b. One and Two
c. Two and Three d. None
FAZAIA COLLEGE OF EDUCATION FOR WOMEN
SARWAR ROAD, LAHORE CANTT
MID TERM EXAMINATION SOLUTION NOV – 2021
BSCS –III Data Structure and Algorithm
Time: 1Hrs 45 Mins Max Marks: 25
______________________________________________________________________________
(SUBJECTIVE)
SECTION – B
(5x3=15marks)
Q.2: Attempt the following questions. All questions carry equal marks.
i. What is skip list and circular queues, what is difference between them.
Answer:
Circular Queue is also a linear data structure, which follows the principle of FIFO(First In First Out),
but instead of ending the queue at the last position, it again starts from the first position after the last,
hence making the queue behave like a circular data structure.
In case of a circular queue, head pointer will always point to the front of the queue, and tail pointer will
always point to the end of the queue.
A skip list is a probabilistic data structure. The skip list is used to store a sorted list of elements or
data with a linked list. It allows the process of the elements or data to view efficiently. In one single
step, it skips several elements of the entire list, which is why it is known as a skip list.
ii. What is skip list and singly link list, what is difference between them.
Answer:
Skip List
A skip list is a probabilistic data structure. The skip list is used to store a sorted list of elements or
data with a linked list. It allows the process of the elements or data to view efficiently. In one single
step, it skips several elements of the entire list, which is why it is known as a skip list.
FAZAIA COLLEGE OF EDUCATION FOR WOMEN
SARWAR ROAD, LAHORE CANTT
Link List
A linked list is a sequence of data structures, which are connected together via links.
Linked List is a sequence of links which contains items. Each link contains a connection to another
link. Linked list is the second most-used data structure after array. Following are the important terms
to understand the concept of Linked List.
Answer:
Answer:
a= 8, b=12 ,K=2
Answer:
}}
Answer:
So, the time complexity is n2.. One n is for the inner loop and one for outer loop.
v. What is Order Notation, Upper Bounding Function and Lower Bounding Function.
Answer:
• Def: f(n)= O(g(n)) if c >0 and n0 > 0 such that f(n) cg(n) for all n n0.
f(n) = O(g(n)) iff limn < including the case where limit is 0
• Def: f(n)= (g(n)) if c > 0 and n0 > 0 such that 0 f(n) cg(n) for all n n0.
• f(n) = (g(n)) iff limn > 0 including the case where limit is
FAZAIA COLLEGE OF EDUCATION FOR WOMEN
SARWAR ROAD, LAHORE CANTT
SECTION – C
(2×5=10marks)
Sparse Tables
Sparse Table is a data structure, that allows answering range queries. It can answer most range
queries in O(logn), but its true power is answering range minimum queries (or equivalent range
maximum queries). ... The only drawback of this data structure is, that it can only be used on
immutable arrays.
Self-Organized of List
A self-organizing list is a list that reorders its elements based on some self-organizing heuristic to
improve average access time. The aim of a self-organizing list is to improve efficiency of linear search
by moving more frequently accessed items towards the head of the list.
ii. Write the code for link list, which have four nodes.
#include<iostream>
#include<conio.h>
using namespace std;
struct node
FAZAIA COLLEGE OF EDUCATION FOR WOMEN
SARWAR ROAD, LAHORE CANTT
{
int data;
node *link;
};
class list
{
private:
node *start, *cur,*temp;
public:
list()
{
start=NULL;
}
add_item(int n)
{
if(start==NULL)
{
start=new node;
start->link=NULL;
}
else
{
cur=start;
while(cur->link!=NULL)
cur=cur->link;
temp=new node;
temp->data=n;
FAZAIA COLLEGE OF EDUCATION FOR WOMEN
SARWAR ROAD, LAHORE CANTT
temp->link=start;
cur->link=temp;
}
}
insert(int x)
{
temp=new node;
temp->data=x;
temp->link=start;
start=temp;
}
print()
{
cur=start;
cout<<"\nvalue of list \n\n";
while(cur->link!=NULL)
{
cout<<cur->data<<endl;
cur=cur->link;
}
cout<<cur->data;
}
};
main()
{
list obj;
FAZAIA COLLEGE OF EDUCATION FOR WOMEN
SARWAR ROAD, LAHORE CANTT
int val,n;
cout<<"enter five values\n";
for(int i=1;i<=5;i++)
{
cin>>val;
obj.add_item(val);
}
cout<<"enter value to insert?";
cin>>n;
obj.insert(n);
obj.print();
}
(B): Explain the Following
i. What is Queue, implementation of Queue through Constructor, check Queue is empty, full,
front and rear.
FAZAIA COLLEGE OF EDUCATION FOR WOMEN
SARWAR ROAD, LAHORE CANTT
ii. What is stack, push 5 elements into stack and pop two elements.
A stack is a conceptual structure consisting of a set of homogeneous elements and is based on the
principle of last in first out (LIFO). It is a commonly used abstract data type with two major operations,
namely push and pop. Push and pop are carried out on the topmost element, which is the item most
recently added to the stack. The push operation adds an element to the stack while the pop operation
removes an element from the top position. The stack concept is used in programming and memory
organization in computers.
E
D D
C C C
B B B B
A A A A A