Preview

Binary search using recursive function

Good Essays
Open Document
Open Document
777 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Binary search using recursive function
Binary search using recursive function

Question:
A class Admission contain the admission numbers of 100 students. Some of the data members/ member functions are given below:
Class name: Admission
Data member/instance variable:
Adno[ ]: Integer array to store admission numbers
Member functions/methods:
Admission(): constructur to initialize the array elements void fillArray(): to accept the element of the array in ascending order int binSearch(int l, int u, int v): to search for a particular admission number(v) using binary search and recursive technique and return 1 if found otherwise returns -1
Specify the class Admission giving details of the constructor, void fillArrray() and int binSearch(int, int, int). Define the main() function to create an object and call the functions accordingly to enable task.

import java.util.*; class Admission
{
int Adno[]=new int[100]; static Scanner sc = new Scanner(System.in); Admission() // Default constructor { for(int i=0; i<100; i++) { Adno[i]=0; } } void fillArray()throws Exception // Function to accept elements in ascending order { for(int i=0; i<100; i++) { System.out.print("Enter Admission no of student "+(i+1)+": "); Adno[i] = sc.nextInt(); } /*Sorting the array in ascending order */ int temp=0; for(int i=0; i<99; i++) { for(int j=i+1; j<100; j++) { if(Adno[i]>Adno[j]) { temp = Adno[i]; Adno[i] = Adno[j]; Adno[j] = temp; } } } } int binSearch(int l, int u, int v) // Recursive function implementing binary search { int mid = (l + u)/2; if(u < l) // condition if the search is unsuccessful { return -1; } if(v==Adno[mid])

You May Also Find These Documents Helpful

  • Good Essays

    ECET 370 Week 5 Lab 5

    • 650 Words
    • 3 Pages

    Exercise 1: Review of the Lecture Content Create a project using the ArrayList class and the Main class provided in DocSharing. The ArrayList class contains implementations of the first three search methods explained in this week's lecture: sequential, sorted, and binary search. The Main class uses these three methods. These programs test the code discussed in the lecture. Compile the project, run it, and review the code that is given carefully.…

    • 650 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Nt1310 Unit 1 Test Paper

    • 381 Words
    • 2 Pages

    3. Create a binary search function that tells whether a given value exists in the tree or not.…

    • 381 Words
    • 2 Pages
    Good Essays
  • Powerful Essays

    System.out.println("i = " + i + " f = " + f + " d = " + d);…

    • 2338 Words
    • 10 Pages
    Powerful Essays
  • Satisfactory Essays

    Pt1420 Unit 7 Study Guide

    • 582 Words
    • 3 Pages

    8.If AL contains 1 or 3, display ‘O’. If AL contains 2 or 4 display ‘E’. Write a program to solve it. Page: 105…

    • 582 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Input names of students from the user, terminated by ZZZ, and create a data file GRADES with records of the form: student(string), test1(integer), test2(integer), test3(integer). In this file, all test scores should b e set equal to 0.…

    • 349 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    lab 1

    • 636 Words
    • 3 Pages

    Before beginning, set up a data table similar to this Data Table 1. Fill in the names of the numbered structures.…

    • 636 Words
    • 3 Pages
    Powerful Essays
  • Satisfactory Essays

    Bio2135 Exam

    • 1718 Words
    • 7 Pages

    Name: ................................................................................................................................... Student No: ......................................................................................................................... Circle your lab section: Thursday: A1-BSC312, Friday: A2-BSC312, A3-BSC330, A4-BSC330 A5-BSC335 A6-BSC335 A7-BSC310…

    • 1718 Words
    • 7 Pages
    Satisfactory Essays
  • Good Essays

    Psy300 Week 8

    • 760 Words
    • 4 Pages

    • Think about this task in an object-oriented way, and identify the objects involved in the task.…

    • 760 Words
    • 4 Pages
    Good Essays
  • Powerful Essays

    Law 208 Week 1 Assignment

    • 4250 Words
    • 17 Pages

    |Class Participation |Pass/ Fail |N/A |1, 2, 3, 4, 5 |1, 2, 4, 5, 6, 7, 8, 9 |Criteria set out below |…

    • 4250 Words
    • 17 Pages
    Powerful Essays
  • Satisfactory Essays

    Databases are used for record keeping and tracking of information institutions like colleges or organizations (Coronel & Morris, 2015). In this case, the database will be used to keep track of the students・attendance, performance and the courses they are supposed to be taking. This will help the college analyze how the students perform and which classes they least or most attend. The database will also help the college keep track of all the subjects which the student is taking or is expected to take in during the course. Instructors will also be part of the database. The database will track their performance in various subjects and their attendance in each class. The database will be upgraded at the beginning of every subject where each student will confirm their attendance for the particular subject and whether the instructor is in class as well. After an examination, all the students・performance will be…

    • 590 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    The total number of data items with a value less than the upper limit for the class is given by the…

    • 1466 Words
    • 6 Pages
    Good Essays
  • Good Essays

    By the database, we know that 11 people from the department 1; 100 people from the department 2; 177 people from the department 3; So,…

    • 1009 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    CS 220 – Programming w/ Data Structures: You have missed one assignment and one quiz. Your instructor has extended your assignment due date to this Sunday, April 10. Your instructor has also let you to take your Quiz # 2 during his office hours during this week. Let me know if you need additional support to study for this quiz. Your grade to date in this class is 30.2/37 81.62% B.…

    • 354 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Database Design

    • 1126 Words
    • 5 Pages

    „h Large amounts of data are stored. An individual record is required for each student.…

    • 1126 Words
    • 5 Pages
    Better Essays
  • Satisfactory Essays

    Think about this task in an object-oriented way, and identify the objects involved in the task.…

    • 506 Words
    • 2 Pages
    Satisfactory Essays