# Category Archives: Searching and Sorting

## Linear Search vs Binary Search

Prerequisite: Linear Search Binary Search A linear search scans one item at a time, without jumping to any item . The worst case complexity is  O(n), sometimes known an O(n) search Time taken to search elements keep increasing as the number of elements are increased. A binary search however, cut down your search to half as… Read More »

See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.

## Linear Search

Problem: Given an array arr[] of n elements, write a function to search a given element x in arr[].

See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.

## Time Complexities of all Sorting Algorithms

Following is a quick revision sheet that you may refer at last minute   Algorithm Time Complexity   Best Average Worst Selection Sort Ω(n^2) θ(n^2) O(n^2) Bubble Sort Ω(n) θ(n^2) O(n^2) Insertion Sort Ω(n) θ(n^2) O(n^2) Heap Sort Ω(n log(n)) θ(n log(n)) O(n log(n)) Quick Sort Ω(n log(n)) θ(n log(n)) O(n^2) Merge Sort Ω(n log(n)) θ(n… Read More »

See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.

## Sorting Strings using Bubble Sort

Given an array of strings arr[]. Sort given strings using Bubble Sort and display the sorted array. In Bubble Sort, the two successive strings arr[i] and arr[i+1] are exchanged whenever arr[i]> arr[i+1]. The larger values sink to the bottom and hence called sinking sort. At the end of each pass, smaller values gradually “bubble” their… Read More »

See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.

## Binary Search for Rational Numbers without using floating point arithmetic

A rational is represented as p/qb, for example 2/3. Given a sorted array of rational numbers, how to search an element using Binary Search. Use of floating point arithmetic is not allowed. Example: Input: arr[] = {1/5, 2/3, 3/2, 13/2} x = 3/2 Output: Found at index 2 We strongly recommend you to minimize your… Read More »

See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.

## Recursive function to do substring search

Given a text txt[] and a pattern pat[], write a recursive function “contains(char pat[], char txt[])” that returns true if pat[] is present in txt[], otherwise false. Examples: 1) Input: txt[] = “THIS IS A TEST TEXT” pat[] = “TEST” Output: true 2) Input: txt[] = “geeksforgeeks” pat[] = “quiz” Output: false; We strongly recommend… Read More »

See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.