How do I make a completely unbalanced binary search tree by using java?
For example I have an array A[1,2,3,4,5,6,7,8,9] and then I want to put these elements into a empty Binary search tree that will make this tree completely unbalanced.
See also questions close to this topic

MenuItem on Navigation Drawer does not respond
i am new to java programming, now i am working on a simple app that has an webview integrated that open a particular website. My style is navigation drawer for the app. When i press an item from the drawer menu it doesn't work at all. I am trying to open a URL using the webview but nothing happens. I have tried many things i found on here but i cant get any results
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent Email = new Intent(Intent.ACTION_SEND); Email.setType("text/email"); Email.putExtra(Intent.EXTRA_EMAIL, new String[]{"sales@alfagreece.com"}); Email.putExtra(Intent.EXTRA_SUBJECT, "AlfaGreece App"); // Email 's Subject Email.putExtra(Intent.EXTRA_TEXT, "Hi Alfa Greece," + ""); //Email 's Greeting text startActivity(Intent.createChooser(Email, "Send message")); } }); DrawerLayout drawer = findViewById(R.id.drawer_layout); NavigationView navigationView = findViewById(R.id.nav_view); myWebView =(WebView) findViewById(R.id.webView); WebSettings webSettings=myWebView.getSettings(); myWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webSettings.setJavaScriptEnabled(true); webSettings.setAllowContentAccess(true); webSettings.setAppCacheEnabled(true); webSettings.setCacheMode(webSettings.LOAD_CACHE_ELSE_NETWORK); webSettings.setDomStorageEnabled(true); webSettings.setUseWideViewPort(true); webSettings.setSavePassword(true); webSettings.setSaveFormData(true); webSettings.setEnableSmoothTransition(true); DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); myWebView.setWebViewClient(new WebViewClient()); myWebView.loadUrl("https://www.alfagreece.com"); // Passing each menu ID as a set of Ids because each // menu should be considered as top level destinations. mAppBarConfiguration = new AppBarConfiguration.Builder( R.id.nav_home) .setDrawerLayout(drawer) .build(); NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration); NavigationUI.setupWithNavController(navigationView, navController); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onSupportNavigateUp() { NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); return NavigationUI.navigateUp(navController, mAppBarConfiguration)  super.onSupportNavigateUp(); } public boolean onNavigationItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.nav_home) { myWebView.loadUrl("https://youtube.com"); Toast.makeText(MainActivity.this,"pressed", Toast.LENGTH_LONG).show(); return true; } else if (id == R.id.nav_gallery) { myWebView.loadUrl("https://yahoo.com"); return true; } return true; } @Override public void onBackPressed() { if(myWebView.canGoBack()) { myWebView.goBack(); } else { super.onBackPressed(); } } }

because he throws Attempt to invoke virtual method 'java.io.FileInputStream
I have a problem with a code that use for write and read in android, write good but not read the file annex code
public void ReadText(int EventoGuardar){ InputStreamReader flujo = null; BufferedReader lector = null; try{ flujo = new InputStreamReader(openFileInput(nomArchivo)); lector = new BufferedReader(flujo); String texto = lector.readLine(); while (texto != null){ texto = lector.readLine(); /*convierte toda la linea leída a un arreglo y obtiene el tamaño*/ String[] arr = texto.split(""); int numeroElementos = arr.length; String dataExtraida; /*Valida que el nuevo arreglo no este vacio*/ if (numeroElementos > 0){ /*Recorre el arreglo creado*/ for (int i = 0; i<numeroElementos; i++){ dataExtraida = ExtraeData(arr[i],EventoGuardar); ConstruyeData(dataExtraida); } }else{ Log.i(TAG,"Arreglo VacioExtraer Data txt"); } } }catch (Exception ex){ Log.i(TAG,"No se pudo leer el archivo"+ ex.getMessage()); } finally { try { if(flujo!=null) flujo.close(); } catch (IOException e) { e.printStackTrace(); } } }
The Log print this : Attempt to invoke virtual method 'java.io.FileInputStream android.content.Context.openFileInput(java.lang.String)' on a null object reference

Tic Tac Toe using Java, Not Sure Where the Error Is
I have an issue with an assignment on CodeHS  I have the code done and ready, but it's telling me that I'm messing up somewhere.
Here's the relevant code:
public class TicTacToe { //copy over your constructor from the Tic Tac Toe Board activity in the previous lesson! private String board[][] = {{"","",""}, {"","",""}, {"","",""}}; public TicTacToe() { } private int turn; //this method returns the current turn public int getTurn() { return turn; } /*This method prints out the board array on to the console */ public void printBoard() { System.out.println(" 0" + " 1" + " 2"); for(int row = 0; row < board.length; row++) { System.out.print(row + " "); for(int column = 0; column < board[row].length; column++) { System.out.print(board[row][column] + " "); } System.out.println(""); } } //This method returns true if space row, col is a valid space public boolean pickLocation(int row, int col) { if(board[row][col] == "") { return true; } else { return false; } } //This method places an X or O at location row,col based on the int turn public void takeTurn(int row, int col) { if(turn %2 == 0) { //Even turn if (pickLocation(row, col) == true) {board[row][col] = "X";} turn++; } else { //Odd turn if (pickLocation(row, col) == true) {board[row][col] = "O";} turn++; } checkWin(); } //This method returns a boolean that returns true if a row has three X or O's in a row public boolean checkRow() { for(int row = 0; row < board.length; row++) { if(board[row][0].equals(board[row][1]) && board[row][1].equals(board[row][2])) { return true; } } return false; } //This method returns a boolean that returns true if a col has three X or O's public boolean checkCol() { for(int col = 0; col < board[0].length; col++) { if(board[0][col].equals(board[1][col]) && board[0][col].equals(board[2][col])) { return true; } } return false; } //This method returns a boolean that returns true if either diagonal has three X or O's public boolean checkDiag() { if(board[0][0].equals(board[1][1]) && board[1][1].equals(board[2][2])) { return true; } else if (board[0][2].equals(board[1][1]) && board[1][1].equals(board[2][0])) { return true; } return false; } //This method returns a boolean that checks if someone has won the game public boolean checkWin() { return (checkCol()  checkRow()  checkDiag()); } }
And the error is as follows: Screenshot of the error, shows that the checkRow method still returns false.
I am unable to "check" the code myself as the tester to verify it isn't visible to the user. I ran a similar scenario through the tester:
public class TicTacToeTester { public static void main(String[] args) { //This is to help you test your methods. Feel free to add code at the end to check //to see if your checkWin method works! TicTacToe game = new TicTacToe(); System.out.println("Initial Game Board:"); game.printBoard(); //Prints the first row of turns taken for(int row = 0; row < 3; row++) { if(game.pickLocation(0, row)) { game.takeTurn(0, row); } } System.out.println("\nAfter three turns:"); game.printBoard(); } }
By manually playing the game, and it all checks out on my end.
I'm wondering if I overlooked something in my code, or if there's some sort of bug in the internal tester. Any feedback about my code (the TicTacToe class, not the Master class) would also be appreciated as I'm still new to 2D arrays.

optimization with sqp algorithm
my optimization problem runs with the interior point algorithm but my matlab function blcok demands the sqp algorithm. But now my problem is not solveable. Can someone tell me why, please. Thats my probelm:
function [ Fx1, Fx2, Fx3, Fx4, alpha1, alpha2, alpha3, alpha4] = fcn(Fx_v, Fy_v, Mz_v, P_max_1, P_max_2, P_max_3, P_max_4, M_reg_1, M_reg_2, M_reg_3, M_reg_4, k, delta_T_aA, SW_1, SW_2, SW_3, SW_4, w_1, w_4, w_3, w_2, d_delay_1, d_delay_2, d_delay_3, d_delay_4, r_dyn_1, r_dyn_2, r_dyn_3, SOC_1, SOC_2, r_dyn_4, SOC_3, SOC_4, f_lag, n, j,w_vr, w_vl, w_hr, w_hl, l_h, l_v, c_w,d_min_vl, d_max_vl, d_min_vr, d_max_vr, d_min_hl, d_max_hl, d_min_hr, d_max_hr, A, B, FxB_max, SOC_krit, C, x0) fun = @(x) C*((Fx_v(x(1)*cos(x(5)+SW_1)+x(2)*cos(x(6)+SW_2)+x(3)*cos(x(7)+SW_3)+x(4)*cos(x(8)+SW_4)x(5)*sin(x(5)+SW_1)*c_wx(6)*sin(x(6)+SW_2)*c_wx(7)*sin(x(7)+SW_3)*c_wx(8)*sin(x(8)+SW_4)*c_w))^2+ (Fy_v(x(1)*sin(x(5)+SW_1)+x(2)*sin(x(6)+SW_2)+x(3)*sin(x(7)+SW_3)+x(4)*sin(x(8)+SW_4)+x(5)*cos(x(5)+SW_1)*c_w+x(6)*cos(x(6)+SW_2)*c_w+x(7)*cos(x(7)+SW_3)*c_w+x(8)*cos(x(8)+SW_4)*c_w))^2+ (Mz_v(x(1)*(cos(x(5)+SW_1)*w_vl+l_v*sin(x(5)+SW_1))+x(2)*(cos(x(6)+SW_2)*w_vr+sin(x(6)+SW_2)*l_v)+x(3)*(cos(x(7)+SW_3)*w_hll_h*sin(x(7)+SW_3))+x(4)*(cos(x(8)+SW_4)*w_hrsin(x(8)+SW_4)*l_h)+x(5)*(sin(x(5)+SW_1)*c_w*w_vl+cos(x(5)+SW_1)*c_w*l_v)+x(6)*(sin(x(6)+SW_2)*c_w*w_vr+cos(x(6)+SW_2)*c_w*l_v)+x(7)*(sin(x(7)+SW_3)*c_w*w_hlcos(x(7)+SW_3)*c_w*l_h)+x(8)*(cos(x(8)+SW_4)*c_w*l_hsin(x(8)+SW_4)*c_w*w_hl)))^2); %(f_lag >= 0).*((A/SOC_1)*(x(1))^2+(A/SOC_2)*(x(2))^2+(A/SOC_3)*(x(3))^2+(A/SOC_4)*(x(4))^2+(d_delay_1(SW_1+x(5)))^2+(d_delay_2(SW_2+x(6)))^2+(d_delay_3(SW_3+x(7)))^2+(d_delay_4(SW_4+x(8)))^2) + (f_lag == 1).*((((B*(M_reg_1/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_1)*(1/(x(1)^2)))+(((B*(M_reg_2/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_2)*(1/(x(2)^2)))+(((B*(M_reg_3/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_3)*(1/(x(3)^2)))+(((B*(M_reg_4/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_4)*(1/(x(4)^2)))+(d_delay_1(SW_1+x(5)))^2+(d_delay_2(SW_2+x(6)))^2+(d_delay_3(SW_3+x(7)))^2+(d_delay_4(SW_4+x(8)))^2); fun = @(x) C*((Fx_v(x(1)*cos(x(5)+SW_1)+x(2)*cos(x(6)+SW_2)+x(3)*cos(x(7)+SW_3)+x(4)*cos(x(8)+SW_4)x(5)*sin(x(5)+SW_1)*c_wx(6)*sin(x(6)+SW_2)*c_wx(7)*sin(x(7)+SW_3)*c_wx(8)*sin(x(8)+SW_4)*c_w))^2+ (Fy_v(x(1)*sin(x(5)+SW_1)+x(2)*sin(x(6)+SW_2)+x(3)*sin(x(7)+SW_3)+x(4)*sin(x(8)+SW_4)+x(5)*cos(x(5)+SW_1)*c_w+x(6)*cos(x(6)+SW_2)*c_w+x(7)*cos(x(7)+SW_3)*c_w+x(8)*cos(x(8)+SW_4)*c_w))^2+ (Mz_v(x(1)*(cos(x(5)+SW_1)*w_vl+l_v*sin(x(5)+SW_1))+x(2)*(cos(x(6)+SW_2)*w_vr+sin(x(6)+SW_2)*l_v)+x(3)*(cos(x(7)+SW_3)*w_hll_h*sin(x(7)+SW_3))+x(4)*(cos(x(8)+SW_4)*w_hrsin(x(8)+SW_4)*l_h)+x(5)*(sin(x(5)+SW_1)*c_w*w_vl+cos(x(5)+SW_1)*c_w*l_v)+x(6)*(sin(x(6)+SW_2)*c_w*w_vr+cos(x(6)+SW_2)*c_w*l_v)+x(7)*(sin(x(7)+SW_3)*c_w*w_hlcos(x(7)+SW_3)*c_w*l_h)+x(8)*(cos(x(8)+SW_4)*c_w*l_hsin(x(8)+SW_4)*c_w*w_hl)))^2); %(f_lag >= 0).*((A/SOC_1)*(x(1))^2+(A/SOC_2)*(x(2))^2+(A/SOC_3)*(x(3))^2+(A/SOC_4)*(x(4))^2+(d_delay_1(SW_1+x(5)))^2+(d_delay_2(SW_2+x(6)))^2+(d_delay_3(SW_3+x(7)))^2+(d_delay_4(SW_4+x(8)))^2) + (f_lag == 1).*((((B*(M_reg_1/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_1)*(1/(x(1)^2)))+(((B*(M_reg_2/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_2)*(1/(x(2)^2)))+(((B*(M_reg_3/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_3)*(1/(x(3)^2)))+(((B*(M_reg_4/(M_reg_1+M_reg_2+M_reg_3+M_reg_4)))/SOC_4)*(1/(x(4)^2)))+(d_delay_1(SW_1+x(5)))^2+(d_delay_2(SW_2+x(6)))^2+(d_delay_3(SW_3+x(7)))^2+(d_delay_4(SW_4+x(8)))^2); A = []; b = []; %equality constraints % Aeq*x = beq Aeq = [ 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0]; beq = [ 0, 0]; if f_lag == 1 %if it is possible the regenerative braking torque is the limit % sum of the Force from the regenerative braking torque in vehiclecoordinates is bigger than the demanded force for the whole vehicle % M_reg is always positive and Fx_v can be either positive or negative in the braking case if (cos(SW_1)*(M_reg_1/r_dyn_1)+cos(SW_2)*(M_reg_2/r_dyn_2)+cos(SW_3)*(M_reg_3/r_dyn_3)+cos(SW_3)*(M_reg_4/r_dyn_4))> abs(Fx_v) % max. regenerative braking torque lb = [M_reg_1/r_dyn_1, M_reg_2/r_dyn_2, M_reg_3/r_dyn_3, M_reg_4/r_dyn_4, d_min_vlSW_1, d_min_vrSW_2, d_min_hlSW_3, d_min_hrSW_4]; %d and betato the left side are positive, to the right side are negative %regenerative braking torque must be positive ub = [M_reg_1/r_dyn_1, M_reg_2/r_dyn_2, M_reg_3/r_dyn_3, M_reg_4/r_dyn_4, d_max_vlSW_1, d_max_vrSW_2, d_max_hlSW_3, d_max_hrSW_4]; else % mechanical braking %FxB_max is positive lb = [FxB_max, FxB_max, FxB_max, FxB_max, d_min_vlSW_1, d_min_vrSW_2, d_min_hlSW_3, d_min_hrSW_4]; %d and betato the left side are positive, to the right side are negative %FxB_max is negative ub = [FxB_max, FxB_max, FxB_max, FxB_max, d_min_vlSW_1, d_min_vrSW_2, d_min_hlSW_3, d_min_hrSW_4]; end % close conditions for braking loop, max braking torque is positive %driving mode else lb = [P_max_1/(r_dyn_1*w_1), P_max_2/(r_dyn_2*w_2), P_max_3/(r_dyn_3*w_3), P_max_4/(r_dyn_4*w_4), d_min_vlSW_1, d_min_vrSW_2, d_min_hlSW_3, d_min_hrSW_4]; ub = [P_max_1/(r_dyn_1*w_1), P_max_2/(r_dyn_2*w_2), P_max_3/(r_dyn_3*w_3), P_max_4/(r_dyn_4*w_4), d_max_vlSW_1, d_max_vrSW_2, d_max_hlSW_3, d_max_hrSW_4]; end %ub = (1:8); output = @optim; x = output(fun,x0,A,b,Aeq,beq,lb,ub,Fx_v,Fy_v,Mz_v,SW_1,SW_2,SW_3,SW_4,w_vr, w_vl, w_hr, w_hl, l_h, l_v, c_w); Fx1 = x(1); Fx2 = x(2); Fx3 = x(3); Fx4 = x(4); alpha1 = x(5); alpha2 = x(6); alpha3 = x(7); alpha4 = x(8);
I am desperate, can someone tell me how to solve my problem?

What is the BigO of this function
The BigO notation concept is not new for me, but I've just seen this code snippet where the author says that it is cubic time or O(N^3) and I'm confused, I would say that it is O(n^2), can anybody help me in the right direction?
Thx!
long sum = 0; for( int i = 0; i < n; i++ ) { for( int j = 0; j < n*n; j++ ) { sum += i  j; } }

Longest substring of 2 alternating characters
I am trying to solve such competitive programming problem:
Alex likes to laugh a lot. Laughter is a sequence of alternating letters "a" and "h". For example, "ahahaha", "hah" and "a" are laughter and "abacaba" and "hh" are not. Alex speaks very quickly, so all his words merge into one big one. You need to find out how long he can laugh. You have a line  a recording of Alex's conversation. Determine the maximum length of laughter in this conversation.
Input file is called "laugh.in"
Output file is called "laugh.out"
Input data: The first line of the input file contains a single integer N (1 < N ≤ 10^5)  the length of the string with Alex's conversation. The second line contains a string of small Latin letters of length N  recording Alex's conversation.
Output data: Output one number  the longest laugh length in Alex's conversation
Here's some examples of how input/output data must look like.
Examples:
Input in laugh.in
5 ahaha
Output in laugh.out
5
Input in laugh.in
24 ahahrunawayahahsofasthah
Output in laugh.out
4
Input in laugh.in
10 ahahaahaha
Output in laugh.out
5
So, here is my code, that is supposed to solve given problem:
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { freopen("laugh.in", "r", stdin); freopen("laugh.out", "w", stdout); ios::sync_with_stdio(false); cin.tie(nullptr); int n, i; cin >> n; char *s = new char[n + 1]; getchar(); for (i = 0; i < n; i += 1) { s[i] = getchar(); } s[n] = '\0'; int max_length = 0; int length = 0; for (i = 0; i < n; i += 1) { length += !length && (s[i] == 'a'  s[i] == 'h'); if ((s[i] == 'a' && s[i + 1] == 'h')  (s[i] == 'h' && s[i + 1] == 'a')) { length += 1; } else { max_length = max(max_length, length); length = 0; } } cout << max(max_length, length) << endl; delete[] s; return 0; }
It only passes 13 tests with other 33 resulting in "Wrong answer" verdict. So why my code is not working? Please, give counter examples to it or explain error.
Any help would be highly appreciated.

Practical usecase or scenario to get top view or side view of tree
Is there any practical use case of competitive problems like print the top view , side view of Tree etc..

I am trying to find the height of a Binary tree with this code, but it keeps returning 0, can someone tell me why?
I am trying to find the height of a Binary tree with this code, but it keeps returning 0, can someone please tell me why?
int heightHelper(Node* root, int maxheight, int rootheight) { if (root>right == nullptr && root>left == nullptr) { //checks if the node has a child if (maxheight < rootheight) { maxheight = rootheight; } } else { //if it has then increase height by 1 rootheight += 1; if (root>left != nullptr) { heightHelper(root>left, maxheight, rootheight); } if (root>right != nullptr) { heightHelper(root>right, maxheight, rootheight); } } return maxheight; //return height } int height(Node* root) { // Write your code here. return heightHelper(root, 0, 0); //root node base case }

What algorithm is this code using to find the lowest common ancestor of a binary tree?
I found this solution on Leetcode while trying to solve this problem:
https://leetcode.com/problems/lowestcommonancestorofabinarytree/
Everyone on Leetcode seems to take for granted how this works. But I don't get it. What is going on here and what algorithm is this using to find the LCA of the binary tree?
public TreeNode lowestCommonAncestorBinaryTree(TreeNode root, TreeNode p, TreeNode q) { if(root==null) { return null; } if(root==p) { return p; } if(root==q) { return q; } TreeNode left = lowestCommonAncestorBinaryTree(root.left, p, q); TreeNode right = lowestCommonAncestorBinaryTree(root.right, p, q); if (left != null && right != null) { return root; } if(left!=null && right==null) { return left; } if(right!=null && left==null) { return right; } return null; }

C++ Binary Search Tree template return Node from function
I've got the following
BinaryTree
class that includes a private class calledNode
(I've omitted everything except what's needed for this question):template<typename T> class BinaryTree{ private: template<typename NT> class Node{ public: Node<NT>* left; Node<NT>* right; NT item; }; public: Node<T> Find(T itemToFind); };
which is fairly standard. I'm trying to implement the
Node FindMax()
function that returns aNode
object and I'm unable to figure out how to define it. For example, I assumed (incorrectly) that this would suffice:template<typename T> Node<T> BinaryTree<T>::Find(T itemToFind){ // > error line //...do something.... }
but I get an error saying:
No template named Node
. I've tried various other combinations to no avail. I'm not looking to return abool
if found, I want to return theNode
itself. 
Python, Tree delete method is not working correctly?
I am learning trees and I am making the delete method in tree but after deleting a node the preorder traversal is not printing all the nodes in the tree.Which means i am making a mistake while rereferencing nodes but i can't figure it out.
 delete()
def delete(self,root, val): if root is None: #base case return None if root.data>val: #if the node to be deleted is in the left sub tree root.left = self.delete(root.left,val) elif root.data < val: #if the node to be deleted is in the right sub tree root.right = self.delete(root.right,val) else: #if the node to be deleted is the current root node if root.left is None: #if the node to be deleted have 0 or 1 child temp =root.right root = None return temp elif root.right is None: #if the node to be deleted have 0 or 1 child temp = root.left root = None return temp else: #if the node to be deleted have 2 child temp = self.minNode(root.right)[0] #for finding the minimum node in the subtree root.data = temp.data root.right = self.delete(root.right,temp.data) return root
 Testing delete Method
All other methods like insert() and preorder() are working fine tested
tree = Bst() #Creating Object of binary search tree tree.insert(10) tree.insert(20) tree.insert(5) tree.insert(1) tree.insert(0) tree.insert(52) tree.insert(102) tree.insert(203) tree.insert(54) tree.insert(204) tree.delete(tree.root,54) tree.preorder()
 Expected Output
10 5 1 0 20 52 102 203 204
 actual output
10 5 1 0
 Code of used methods
1.preorder()
def preorder(self,node=None): if node is None: node = self.root print(node.data) if node.left is not None: self.preorder(node.left) if node.right is not None: self.preorder(node.right)
2.minNode()
def minNode(self,node=None): if node is None: node = self.root while node.left is not None: node = node.left return (node,node.data)
I have gone through it many times but it seems i am missing the loop hole any help will be appreciated. Thank you

find successor in binary search tree
I am trying to understand the node deletion as implemented in Python at this site. When a node has two children, I understand that I can just pick the rightmost node in the left subtree (or the leftmost node in the right subtree) as a replacement for the node to be deleted (referred as 'currentNode' in the following piece of code).
elif currentNode.hasBothChildren(): #interior succ = currentNode.findSuccessor() succ.spliceOut() currentNode.key = succ.key currentNode.payload = succ.payload
where the successor is found using the following code
def findSuccessor(self): succ = None # Will this 'if' condition be always true? Note that # self as both the children if self.hasRightChild(): succ = self.rightChild.findMin() # Why the following 'else' part is needed? I think # the following part would never be accessed as the # above 'if' statement would always be true, right? else: if self.parent: if self.isLeftChild(): succ = self.parent else: self.parent.rightChild = None succ = self.parent.findSuccessor() self.parent.rightChild = self return succ def findMin(self): current = self while current.hasLeftChild(): current = current.leftChild return current
Pardon me for a very basic question related to node deletion in binary search tree. The question is that, if findSuccessor() is always called on the node to be deleted i.e. currentNode, then what's the role of the following part?
else: if self.parent: if self.isLeftChild(): succ = self.parent else: self.parent.rightChild = None succ = self.parent.findSuccessor() self.parent.rightChild = self return succ
Since, self.hasRightChild() would always be true as self is an interior node.

Can anybody suggest me good books to get a good idea of programming?
I'm new to the programming world and I'm not a CSE student, but I'm highly interested in learning programming and computer and web technologies. Have basic knowledge of general computing and using contemporary internet tools.
Drem to be a developer.
Thanks Priyashis.

How can I include sound into a project on bluej by URL?
I have a project due tomorrow for school and I'm a little confused on how I add sound to it. Our class works on the bluej platform, and the sound needs to be added by URL and not by a file on our computer, so that when the teacher runs it he can hear the music. We are doing an applet project, if that makes any difference. I have seen many demonstrations online of how to add sound to a project, but none on how to add a sound from a URL, and I am desperate for help. Thanks

Turing Machine For balanced parenthesis
How to desgin a turing machine that can recognize the strings of balanced parenthesis? For example (())().