0% found this document useful (0 votes)
6 views11 pages

Lec 34 Java Fundamental of Computing

The document covers fundamental computing concepts including the Tower of Hanoi problem, binary search algorithms, and input/output operations in Java. It explains the recursive nature of the Tower of Hanoi and the constraints involved in moving discs. Additionally, it introduces basic input/output classes in Java for reading from the console and files.

Uploaded by

abhishekhamida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Lec 34 Java Fundamental of Computing

The document covers fundamental computing concepts including the Tower of Hanoi problem, binary search algorithms, and input/output operations in Java. It explains the recursive nature of the Tower of Hanoi and the constraints involved in moving discs. Additionally, it introduces basic input/output classes in Java for reading from the console and files.

Uploaded by

abhishekhamida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ESc101 : Fundamental of Computing

I Semester 2008-09

Lecture 34

• Fun : Tower of Hanoi - a classical recursive problem


• Binary Search
• Input/Output - Part 1
(using the existing classes and method of package java.io.*)

1
Tower of Hanoi

• There are three Towers : A,B,C


• Tower A has n discs arranged one above the other in the increasing order of
the radii from top to bottom.

• The towers B and C are empty.


• We can move one disc only in a single step.
• AIM : Describe the steps to transfer all discs from tower A to tower B.

Constraint : We can never place a bigger disc on smaller one.

2
Tower of Hanoi

• There are three Towers : A,B,C


• Tower A has n discs arranged one above the other in the increasing order of
the radii from top to bottom.

• The towers B and C are empty.


• We can move one disc only in a single step.
• AIM : Describe the steps to transfer all discs from tower A to tower B.

Constraint : We can never place a bigger disc on a smaller one.

3
Design a method Tower of Hanoi(n)

which prints the detailed instruction about the movement of discs in order to
transfer n discs from A to B .

4
Search

Problem : Given an array of large size, search whether an element is there ?


Easy solution : sequential search

what is we have to search 107 elements in an array of size 107

5
Search

Problem : Given an array of large size, search whether an element is there ?


Easy solution : sequential search

what if we have to search 107 elements in an array of size 107

6
Search

Problem : Given an array of large size, search whether an element is there ?


Easy solution : sequential search

what if we have to search 107 elements in an array of size 107

7
Binary Search : A powerful search algorithm

The code is given in file bin search.java.

8
Input Output from/to Console

Classes used :

• InputStreamReader
• BufferedReader
An interactive program for sorting numbers
see the file selection sort i.java

9
Input Output from/to Console

1. Reading characters one by one from console :


see the file Console Chareader.java

2. Reading Primitive types from console :


(first we read one complete input line as string and then convert that to the
primitive type)
see the file Interactively reading integers.java

10
Input Output from/to File - without buffers

To be discussed in next class

11

You might also like