Week 1

Problem 1

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

Input : arr[] = {10, 20, 80, 30, 60, 50, 
                     110, 100, 130, 170}
          x = 110;
Output : 6
Element x is present at index 6

Input : arr[] = {10, 20, 80, 30, 60, 50, 
                     110, 100, 130, 170}
           x = 175;
Output : -1
Element x is not present in arr[].

Hint: linear search

Problem 2

Problem: Write a Java program to arrange the elements of an given array of integers where all negative integers appear before all the positive integers.

Input: { 2, 5, -55, 8, -72, -1, 53 }

Output: { -55, -72, -1, 2, 5, 8, 53 }