1-Import Java
1-Import Java
Scanner;
import java.util.concurrent.TimeUnit;
int n;
// dup array stores the value from array and its frequency if it has duplicates
n = sc.nextInt();
array[i] = sc.nextInt();
// log the starting time before starting finding largest element in array
int flag;
for(int j = i+1; j < n; j++) // traverse through array to find duplicates of ith element
if(array[i] == array[j]) // if ith element of array is equal to jth element, then atleast one
duplicate exists
{
flag = 1; // set flag variable to indicate existence of duplicates
array[j] = -1; // make jth element = -1 to indicate it is already counted for duplicates
System.out.print("\t" + array[i]);
Q2:
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class Main
int n, large;
n = sc.nextInt();
{
System.out.print("Enter #" + (i+1) + ": ");
array[i] = sc.nextInt();
// log the starting time before starting finding largest element in array
large = array[0];
if(array[i] > large) // if ith element of array is > than largest element,
Q3:
class Node
// each node in binary tree contains data field, pointer to left child, pointer to right child
int data;
Node left;
Node right;
public Node(int d)
right = null;
// BinaryTree class
class BinaryTree
Node root;
// 1
// / \
// 2 5
// / \ /
// 3 4 6
preorder(root);
// method for performing preorder traversal of binary tree starting from root node
// it is a recursive method
if (node == null)
return;
// display the current nodes data
System.out.print(node.data + "\t");
preorder(node.left);
preorder(node.right);
// driver class
bt.constructTree();
// traverse binary tree in preorder
bt.preOrder();