0% found this document useful (0 votes)
3 views

Adobe Scan 02 Dec 2024

Uploaded by

ketankotane70
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Adobe Scan 02 Dec 2024

Uploaded by

ketankotane70
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Basis of

comparison Linear search Binary search


The linear search starts
searchingeachirom fnds the position of the
the first element and compares
Definition 12/43
element with a searched element till element by finding the mid
the element is not found. element of the array.
In a linear search, the elements don't The pre-condition for the binary
Sorted data need to be arranged in sorted order. search is that the elements must be
arranged in a sorted order,
The linear search can be The implementation of binary search
implemented
Implementation on any linear data structure such as an is limited as it can be implemented
lonly on
array, linked list, etc. those data structures that
have two-way traversal.

Approach It is based on the sequential annroach Is based on the divide and conguer
approach.
Size It is preferrable for the small-sized It is preferrable for the large-size
data sets. data sets.
It is less efficient in the case of large- It is more efficient in the case of
Eficiency size data sets. large-size data sets.
In a linear search, the worst- case In a binary search, the worst-case
Worst-case
scenario
scenario for finding the element is scenario for finding the element is
O(n). O(logn).
Best-case In a linear search, the best-case In a binary search, the best-case
scenario for finding the first element scenario for finding the first element
scenario
in the list is O(1). in the list is O(|).
Dimensional It can be implemented on both a single It can be implemented only on a
array and multidimensional array. multidimensional array.
Bubble sort Selection sort

in bubble sort, two adjacent elements are In selection sort, the minimum element is
compared. If the adjacent elements are not at selected from the array and swap with an

the correct position, swapping would be element which is at the beginning of the
performed. unsorted sub array.

The time complexities in best case and worstThe time complexity in both best and worst
case are o(n) and O(n2) respectively. cases is O(n 2).

It is an efficient sorting technique as compared


|it is not an efficient sorting technique.
to Bubble sort.
|It uses an exchanging method. It uses a selection method.

It is slower than the selection sort as a greaterIt is faster than the bubble sort as a lesser
number of comparisons is required. number of comparisons is required.
1.Compare Linked List and Array. (any 4 points)
Let's look at the differences between the array and linked list in a tabular form.

Array Linked list

An array is a collection of elements of a A linked list is a collection of objects known as


similar data type. a node where node consists of two parts, i.e.,
data and address.

Array elements store in a contiguous Linked list elements can be stored anywhere in
memory location. the memory or randomly stored.
Array works with a static memory. Here static The Linked list works with dynamic memory.
memory means that the memory size is fixed Here, dynamic memory means that the
and cannot be changed at the run time. memory size can be changed at the run time
according to our requirements.
Array elements are independent of each Linked list elements are dependent on each
other. other. As each node contains the address of
the next node so to access the next node, we
need to access its previous node.

Array takes more time while performing any Linked list takes less time while performing any
operation like insertion, deletion, etc. operation like insertion, deletion, etc.

Accessing any element in an array is faster as Accessing an element in a linked list is slower
the element in an array can be directly as it starts traversing from the first element of
accessed through the index. the linked list.

In the case of an array, memory is allocated In the case of a linked list, memory is allocated
at compile-time. at run time.

Memory utilization is inefficient in the array. Memory utilization is efficient in the case of a
For example, if the size of the array is 6, and linked list as the memory can be allocated or
array consists of 3 elements only then the deallocated at the run time according to our
rest of the space will be unused. requirement.
©J o.0Peronce beln e neral tee X binary bree
Gtenercal Jree Binary ree
dala slruclare ioÜ i a dala sruclar
which goch roa çan in cohich eoch ro can
have inlinde no ok chilsren have only leoo childrons
aij It has in de hes in
d Differentiate between stack and queue.( Any two points)
Ans Stack Queue
1. Stack is a data structure in which Queue is a data structure in
insertion and deletion operations which insertion and deletion
are performed at same end. operations are performed at
different ends.

2. In stack an element inserted last 2. In Queue an element inserted


is deleted first so it is called Last first is deleted first so it is called
In First Out list. First In First Out ist.

3.In stack only one pointer is used 3.In Queue two pointers are used
called as front and rear
called as stack top
4. Example: Stack of books 4. Example: Students standing in
a line at fees counter

5.Application: 5. Application:
" Recursion " In computer system for
" Polish notation organizing processes.
" In mobile device for sending
receiving messages.
Ans Sr. General Tree Binary Tree Any four
no relevant
A general tree is a data A Binary tree is a data structure differences
structure in which each node in which each node has at most -IM each
can have infinite number of two nodes i.e. left and right
children
In general tree, root has in- In binary tree, root has in
degree 0 and maximum out- degree 0and maximum out
degree n degree 2.
In general tree, each node In binary tree, each node have
have in-degree one and in-degree one and maximum
maximum out-degree n. out-degree 2.
Height of a general tree is the Height of a binary tree is :
length of longest path from Height(T) = (max (Height(Left
root to the leaf of tree. Child) , Height(Right Child)
Height(T) 1)
(max(height(child 1)
height(child2)
height(child-n) ) +1)
Subtree of general tree are Subtree of binary tree is
not ordered ordered.
General tree Binary Tree
Roc
Differentiate between linear and non-linear data structures on 2M
any two parameters.
Sr. Linear data structure Non-linear data structure
No.
Adata structure in which allA data structure in which all Any two
data elements are stored in a data elements are not stored differen
sequence is known as linear in a sequence is known as ces 1M
data structure. non-linear data structure. each
All elements are stored in All elements may stored in
contiguous memory non-contiguous memory
locations inside memory. locations inside memory.
Example:- stack, queue Example:- tree, graph

You might also like