We have already discussed several sorting algorithms that can sort n numbers in both O(n²) and O(nlogn) time complexity in the worst case. These algorithms determine the sorted order based only on the comparisons between the input elements. We call such sorting algorithms comparison sort, where we use only comparisons between elements to gain order information about an input sequence A, A, . . . , A[n-1]. In other words, given two elements A[i] and A[j], we perform one of the tests A[i] <= A[j], A[i] >= A[j], A[i] = A[j] to determine their relative order. …
Difficulty: Medium, Asked-in: Google, Amazon, Uber, Hike
Given two array strings X and Y of size m and n, write a code to find the length of the longest common sequence.
Millions of users on the internet are generating terabytes of content every day, and the amazing part is: the amount of content is doubling every six months! So we need an effcient search mechanism or new data structures for storing and accessing data with such growth. From another perspective, Many applications require a mechanism that supports only the dictionary operations: Insert, Search, and Delete. For example, a compiler that translates a programming language maintains a symbol table, in which the keys of elements are character strings corresponding to identifiers in the language.
But the critical question is: what is wrong…
Computer science is a field of dream opportunities. All over the world, millions of students are looking forward to pursuing a career in the field of computer science. Though a lot of learning resources are available online, still, most of the students are struggling to become good at it and crack the interview. After working closely with more than 1k students, here I would like to highlight the top 5 learning challenges in computer science.
Solving problems is a practical skill like, let us say, swimming. We acquire any practical skill by imitation and practice. — George Polya
The critical question would be: How do we measure the time complexity of an algorithm? What are the essential concepts related to the complexity analysis? Let’s dive deep into it and learn step by step.
The input size is defined as the total number of items present in the input. The time taken by an algorithm grows with the size of the input i.e. If we increase the input size…
A pointer is a special kind of variable designed to store the memory address of another variable. Declaring a pointer is as simple as declaring any other variable, but it is tricky to handle. So, here is a question for you: How do you pass a 2D Array in a function if the parameters of the array are not declared globally? Choose your answer from the given options in the image below. Also, suggest in the comment if you have any other approach.
Object-Oriented Programming binds together the data and the methods in the form of an object and selectively exposes the data to other objects. It primarily revolves around classes and objects — definition, instantiation, relationship, communication, etc. On the other hand, the building block of procedural programming is procedures or functions that perform data operations. Explore and Think.
Asked In: Google, Facebook, Microsoft, Amazon, Flipkart, Hike, Morgan Stanley
Given an array of n integers and given a number targetSum, write a program to determines whether there is a pair of elements in the array that sums to exactly targetSum.
Asked in: Google, Amazon, Adobe, Oracle, Qualcomm, SAP Labs, Wipro
Given a sorted array X of n elements, write a program to search a given element key in X. If the key exists, then we need to return its index in the sorted array. Otherwise, return -1.
Input: X = [-4,2,4,5,9,12], key = 5
Explanation: 5 exists in X and its index is 3.Input: X = [-4,2,4,5,9,12], key = 6
Explanation: 6 does not exist in x so return -1
Asked In: Google, Microsoft, Adobe, SAP Labs, Goldman Sachs, Qualcomm
Quick Sort is one of the most popular algorithms that uses a divide and conquer problem-solving. Here are some excellent reasons to learn this algorithm —