[Solved] Write a program in C# which uses Iterative Binary Search algorithm to search age of the person using his / her name

I do disagree with the way you store your input but you can achieve your search with the following: String[,] arr = new string[2,4]; arr[0, 0] = “saif”; arr[0, 1] = “25”; arr[0, 2] = “ali”; arr[0, 3] = “17”; arr[1, 0] = “aakif”; arr[1, 1] = “11”; arr[1, 2] = “hassnain”; arr[1, 3] = … Read more

[Solved] Searching using BinarySearch [closed]

You need to update the left and right values not the middle..change it like this while (true) { middle = (left + right) / 2; int copmarison = Name.compareTo(StudentName[middle]); if (Name.equals(StudentName[middle])) { return middle; } else if (left > right) { return count; } else { if (copmarison > 0) { left = middle + … Read more

[Solved] Time Complexity of Binary Search?

With binary search you typically search in a sorted random access data structure like an array, by discarding half of the array with each comparison. Hence, in k steps you effectively cover 2^k entries. This yields a complexity of at most log2(n) of n elements. With landau symbols, the base of the logarithm disappears because … Read more

[Solved] Why does the error keep stating incompatible integer to pointer in C for an array?

Based on the phrasing of your question, I’m guessing that you are unfamiliar with the concept of pointers. In C, pointer is a type that stores the memory address of another variable. The & operator retrieves the memory address of a variable. int i = 4; // < An integer variable equal to 4 int* … Read more

[Solved] How do I trace the progress of this tree code?

Without tracing, it’s relatively straightforward to see what a given tree should print. The structure of the method means that a string will look like this: <content><left sub-tree><content><right sub-tree><content> So all you have to do is continually substitute that pattern for the left and right sub-trees (with empty strings for non-existent sub-trees) and get the … Read more