21) What is Searching? Explain any two different types of searching with an example.22) What is sorting? Explain Linear search and Binary search with an example.23) Write a difference between Linear search and Binary search.24) Write a difference between Merge sort and Quick sort.25) Write a difference between Selection sort and Insertion sort.26) What is a Linked List? Explain Singly, Doubly and Circular Linked List.
Question
- What is Searching? Explain any two different types of searching with an example.22) What is sorting? Explain Linear search and Binary search with an example.23) Write a difference between Linear search and Binary search.24) Write a difference between Merge sort and Quick sort.25) Write a difference between Selection sort and Insertion sort.26) What is a Linked List? Explain Singly, Doubly and Circular Linked List.
Solution
- Searching is the algorithmic process of finding a particular item in a collection of items. It can be done in two ways: Linear Search and Binary Search.
-
Linear Search: This is the simplest form of searching. It traverses the list sequentially and checks if the element is the same as the one being searched for. For example, if we have an array [5, 3, 9, 1, 6] and we want to find 1, we start from the first element and compare each element to 1 until we find a match.
-
Binary Search: This is a more efficient method of searching. It works by repeatedly dividing in half the portion of the list that could contain the item, until you've narrowed down the possible locations to just one. For example, if we have a sorted array [1, 3, 5, 7, 9] and we want to find 7, we start in the middle. 5 is less than 7, so we know 7 is not in the first half of the array. We then look at the second half, again starting in the middle. 7 is equal to 7, so we have found the item we are looking for.
- Sorting is the process of arranging items in a certain order. It can be done in many ways, including Linear Search and Binary Search.
-
Linear Search: As explained above, this method checks each element sequentially until it finds a match. For example, if we want to find 7 in the array [5, 3, 9, 1, 6, 7], we would check each element one by one until we find 7.
-
Binary Search: As explained above, this method repeatedly divides the list in half until it finds a match. For example, if we want to find 7 in the sorted array [1, 3, 5, 7, 9], we would start in the middle and eliminate half of the array in each step until we find 7.
-
The main difference between Linear Search and Binary Search is that Linear Search checks each element sequentially and is therefore slower, while Binary Search divides the list in half with each step and is therefore faster. However, Binary Search requires the list to be sorted, while Linear Search does not.
-
Merge Sort and Quick Sort are both sorting algorithms, but they work in different ways.
-
Merge Sort: This algorithm divides the unsorted list into n sublists, each containing one element (a list of one element is considered sorted), and then repeatedly merges sublists to produce new sorted sublists until there is only one sublist remaining.
-
Quick Sort: This algorithm works by selecting a 'pivot' element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. The sub-arrays are then recursively sorted.
- Selection Sort and Insertion Sort are also both sorting algorithms, but they have different methods.
-
Selection Sort: This algorithm sorts an array by repeatedly finding the minimum element from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array.
-
Insertion Sort: This algorithm works by taking elements from the unsorted list and moving them to the sorted part at their correct order, one at a time.
- A Linked List is a linear data structure where each element is a separate object. Each element (or node) of a list consists of two items: the data and a reference to the next node. The last node has a reference to null. The entry point into a linked list is called the head of the list.
-
Singly Linked List: In this type of list, every node stores the data and has a link to the next node in the list. It does not have a link to the previous node which makes going backwards impossible.
-
Doubly Linked List: In this type of list, every node has a link to the next node and also to the previous node. This allows traversal in both directions.
-
Circular Linked List: In this type of list, the last node of the list points back to the first node (or the head) of the list.
Similar Questions
21) What is Searching and Sorting?22) List out different types of searching.23) What is a Linked List?24) List out different types of the Linked list.
6) Explain about macros with an example.7) Explain about Bit fields with examples.8) What is an enumeration? Give an example for enumeration.9) What are self-referential structures? Write the syntax for the same.10) Write a C program to demonstrate Enumeration type?
11) What is the use of the enum keyword in C?12) What is Structure padding?13) What is the use of the bit field in C?14) What is meant by an anonymous structure?15) What is meant by nested structures?16) What are self referential structures?17) What is the use of #include preprocessor directive?18) What is the use of .(dot) operator?19) What is the use of ->(arrow) operator?20) What is the use of pointer variables in C?
16) What are Anonymous structures? Give an example.17) List out any 3 differences between static and dynamic memory allocations?18) Write an example program to demonstrate embedded nested structure?19) Write a C program to find the maximum and minimum of two numbers using macros?20) Explain the difference between arrays of structures and arrays within structures?
91. Which of the following data structures are indexed structures?#a) linear arraysb) linked listsc)Dequesd) Treese)Stacks92. Which of the following is not the required condition for binary search algorithm?a) The list must be sortedb) there should be the direct access to the middle element in any sublist#c)There must be mechanism to delete and/or insert elements in listd) The list must be partitionede) none of the above93. Which of the following is not a limitation of binary search algorithm?a) must use a sorted arrayb) requirement of sorted array is expensive when a lot of insertion and deletions areneededc)there must be a mechanism to access middle element directly#d) binary search algorithm is not efficient when the data elements are more than 1000.e) both a and b94. A variable P is called pointer if#a)P contains the address of an element in DATA.b) P points to the address of first element in DATAc) P can store only memory addressesd) P contain the DATA and the address of DATAe) P can store only the DATA95. Which of the following data structure can't store the non-homogeneous data elements?#a)Arraysb) Recordsc)Pointersd) LinkedListe)Trees96. Which of the following data structure store the homogeneous data elements?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.