This document discusses and provides code implementations for binary search and linear search algorithms using both recursive and non-recursive functions in C. It includes function definitions and implementations for binary search and linear search using recursion and non-recursion, as well as functions for reading in a list of integers, printing the list, and a main function to test the search algorithms.
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswiftTomohiro Kumagai
Swift 3.0 で変わったところから、興味の湧いた 13 項目を、自分が開催する "カジュアル Swift 勉強会" の紹介も兼ねつつ、Swift 愛好会で発表してきました。
少し前に iPhone Dev Sapporo 勉強会で話した内容から、項目数は減らしつつも、新たな項目を紹介したり、紹介済みの項目についても内容を少し膨らませたりしています。
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswiftTomohiro Kumagai
Swift 3.0 で変わったところから、興味の湧いた 13 項目を、自分が開催する "カジュアル Swift 勉強会" の紹介も兼ねつつ、Swift 愛好会で発表してきました。
少し前に iPhone Dev Sapporo 勉強会で話した内容から、項目数は減らしつつも、新たな項目を紹介したり、紹介済みの項目についても内容を少し膨らませたりしています。
a) Complete both insert and delete methods. If it works correctly 10.pdfMAYANKBANSAL1981
a) Complete both insert and delete methods. If it works correctly 100 points each.
b) Do not call the search method in delete method.
c) Make sure to write your name in main method.
d) DO NOT MODIFY PROCESS METHOD.
3- Create a proper input file with respect to process method to test all cases in both
insert and delete methods.
4- Compile and execute your program at the command prompt. Check your output, if it
is correct
//xxxxxH5.java is linked list implementation of lstinterface.
//Eliminate count form both insert and delete methods
// If works correctly, 200 points
import java.util.*;
import java.io.*;
//lstinterface is an interface
public class xxxxxH5 implements lstinterface {
// xxxxxH5 class variables
//head is a pointer to beginning of linked list
private node head = null;
//use prt for System.out to save typing
PrintStream prt = System.out;
// class node
private class node{
// class node variables
int data;
node rlink; //right link
// class node constructor
node(int x){
data = x;
rlink = null;
} // end class node constructor
}// class node
// insert x at position p,
// if successful return 1 otherwise return 0
public int insert(int x, int p){
prt.printf("\n\t\tInsert %5d at position %2d:", x, p);
// complete this method
return 0; // successful insertion
} // end insert
// delete x at position p
// if successful return 1 otherwise return 0
public int delete(int p){
prt.printf("\n\t\tDelete element at position %2d:", p);
// complete this method
return 0; // successful insertion
} // end delete
// sequential serach for x in the list
// if successful return its position otherwise return 0;
public int search(int x){
// Local variables
node cur;
prt.printf("\n\t\tSearch for %5d:", x);
// Complete the rest of the method
int pos = 0;
for (cur = head; cur != null ; cur = cur.rlink){
pos ++;
if (cur.data == x){
prt.printf(" Found at position %2d, ", pos);
return pos;
} // end if
} // end for
prt.printf(" Not Found.");
return 0; // x is not found.
} // end search
// print list elements formatted
public void printlst() {
// Local variables
node cur;
prt.printf("\n\tList contents: ");
for (cur = head; cur != null ; cur = cur.rlink)
prt.printf("%5d,", cur.data);
// end for
} // end printlst
// insert delete and search in the list
private void process(String fn){
// Local variables
int j, ins, del, srch, k, p;
int x;
prt.printf("\tLinked List implementation of int list without"+
//\n\tusing count, gets input file name from method argument, then
reads:"+
"\n\tinteger No. of elements to insert(ins)"+
" followed by elements to insert and their positions,"+
"\n\tinteger No. of elements to search(srch) followed by element to
search"+
"\n\tinteger No. of elements to delete(del) followed by position of"+
"elements to delete" +
"\n\t\tTo compile: javac xxxxxH5.java" +
"\n\t\tTo execute: java xxxxxH5 inputfilename");
try{
// open input file
Scanner inf = new Scanner(new File(fn));
//read no. of elements to insert
ins = inf.nextInt();
prt.printf("\n\tInsert %.
This document contains some programs of C using Data structures, like Stack, LinkedList, queue, Fibonacci series, addition and multiplication of two matrices,etc.
1. Perform Linear Search and Binary Search on an array.
Descriptions of the programs:
Read and array of type integer.
Input element from user for searching.
Search the element by passing the array to a function and then returning the position of the element from the function else return -1 if the element is not found.
Display the positions where the element has been found.
2. Implement sparse matrix using array.
Description of program:
Read a 2D array from the user.
Store it in the sparse matrix form, use array of structures.
Print the final array.
3. Create a linked list with nodes having information about a student and perform.
Description of the program:
Insert a new node at specified position.
Delete of a node with the roll number of student specified.
Reversal of that linked list.
4. Create doubly linked list with nodes having information about an employee and perform Insertion at front of doubly linked list and perform deletion at end of that doubly linked list.
5. Create circular linked list having information about a college and perform Insertion at front perform Deletion at end.
6. Create a stack and perform Pop, Push, Traverse operations on the stack using Linear Linked list.
7. Create a Linear Queue using Linked List and implement different operations such as Insert, Delete, and Display the queue elements.
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
/* Program of sorting using shell sort */
#include
#define MAX 20
main()
{
int arr[MAX], i,j,k,n,incr;
printf(\"Enter the number of elements : \");
scanf(\"%d\",&n);
for(i=0;i=1)
{
for(j=incr;j= 0 && k < arr[i]; i = i-incr)
arr[i+incr]=arr[i];
arr[i+incr]=k;
}
printf(\"Increment=%d \ \",incr);
for (i = 0; i < n; i++)
printf(\"%d \", arr[i]);
printf(\"\ \");
incr=incr-2; /*Decrease the increment*/
}/*End of while*/
printf(\"Sorted list is :\ \");
for (i = 0; i < n; i++)
printf(\"%d \", arr[i]);
printf(\"\ \");
}/*End of main()*/
redix sort
/*Program of sorting using radix sort*/
# include
# include
struct node
{
int info ;
struct node *link;
}*start=NULL;
main()
{
struct node *tmp,*q;
int i,n,item;
printf(\"Enter the number of elements in the list : \");
scanf(\"%d\", &n);
for(i=0;iinfo=item;
tmp->link=NULL;
if(start==NULL) /* Inserting first element */
start=tmp;
else
{
q=start;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}
}/*End of for*/
printf(\"Unsorted list is :\ \");
display();
radix_sort();
printf(\"Sorted list is :\ \");
display ();
}/*End of main()*/
display()
{
struct node *p=start;
while( p !=NULL)
{
printf(\"%d \", p->info);
p= p->link;
}
printf(\"\ \");
}/*End of display()*/
radix_sort()
{
int i,k,dig,maxdig,mindig,least_sig,most_sig;
struct node *p, *rear[10], *front[10];
least_sig=1;
most_sig=large_dig(start);
for(k = least_sig; k <= most_sig ; k++)
{
printf(\"PASS %d : Examining %dth digit from right \",k,k);
for(i = 0 ; i <= 9 ; i++)
{
rear[i] = NULL;
front[i] = NULL ;
}
maxdig=0;
mindig=9;
p = start ;
while( p != NULL)
{
/*Find kth digit in the number*/
dig = digit(p->info, k);
if(dig>maxdig)
maxdig=dig;
if(diglink = p ;
rear[dig] = p ;
p=p->link;/*Go to next number in the list*/
}/*End while */
/* maxdig and mindig are the maximum amd minimum
digits of the kth digits of all the numbers*/
printf(\"mindig=%d maxdig=%d\ \",mindig,maxdig);
/*Join all the queues to form the new linked list*/
start=front[mindig];
for(i=mindig;ilink=front[i+1];
else
rear[i+1]=rear[i];
}
rear[maxdig]->link=NULL;
printf(\"New list : \");
display();
}/* End for */
}/*End of radix_sort*/
/* This function finds number of digits in the largest element of the list */
int large_dig()
{
struct node *p=start ;
int large = 0,ndig = 0 ;
while(p != NULL)
{
if(p ->info > large)
large = p->info;
p = p->link ;
}
printf(\"Largest Element is %d , \",large);
while(large != 0)
{
ndig++;
large = large/10 ;
}
printf(\"Number of digits in it are %d\ \",ndig);
return(ndig);
} /*End of large_dig()*/
/*This function returns kth digit of a number*/
int digit(int number, int k)
{
int digit, i ;
for(i = 1 ; i <=k ; i++)
{
digit = number % 10 ;
number = number /10 ;
}
return(digit);
}/*End of digit()*/
Solution
/* Program of sorting using shell sort */
#include
#define MAX 20
main()
{
int arr[MAX], i,j,k,n,incr;
printf(\"Enter the number of elements : \");
scanf(\"%d\",&n);
for(i=0;i=1)
{
for(j=incr;j= 0 && k < arr[i]; i = i-incr)
arr[i+incr]=arr[i];
arr[i+incr]=k;
}
printf(\.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
We all have good and bad thoughts from time to time and situation to situation. We are bombarded daily with spiraling thoughts(both negative and positive) creating all-consuming feel , making us difficult to manage with associated suffering. Good thoughts are like our Mob Signal (Positive thought) amidst noise(negative thought) in the atmosphere. Negative thoughts like noise outweigh positive thoughts. These thoughts often create unwanted confusion, trouble, stress and frustration in our mind as well as chaos in our physical world. Negative thoughts are also known as “distorted thinking”.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
week-19x
1. /* Write C programs that use both recursive and non recursive functions to perform
the following searching operations for a Key value in a given list of integers :
ii) Binary search*/
#include <stdio.h>
#define MAX_LEN 10
/* Non-Recursive function*/
void b_search_nonrecursive(int l[],int num,int ele)
{
int l1,i,j, flag = 0;
l1 = 0;
i = num-1;
while(l1 <= i)
{
j = (l1+i)/2;
if( l[j] == ele)
{
printf("nThe element %d is present at position %d in listn",ele,j);
flag =1;
break;
}
else
if(l[j] < ele)
2. l1 = j+1;
else
i = j-1;
}
if( flag == 0)
printf("nThe element %d is not present in the listn",ele);
}
/* Recursive function*/
int b_search_recursive(int l[],int arrayStart,int arrayEnd,int a)
{
int m,pos;
if (arrayStart<=arrayEnd)
{
m=(arrayStart+arrayEnd)/2;
if (l[m]==a)
return m;
else if (a<l[m])
return b_search_recursive(l,arrayStart,m-1,a);
else
return b_search_recursive(l,m+1,arrayEnd,a);
}
return -1;
}
3. void read_list(int l[],int n)
{
int i;
printf("nEnter the elements:n");
for(i=0;i<n;i++)
scanf("%d",&l[i]);
}
void print_list(int l[],int n)
{
int i;
for(i=0;i<n;i++)
printf("%dt",l[i]);
}
/*main function*/
void main()
{
int l[MAX_LEN], num, ele,f,l1,a;
int ch,pos;
clrscr();
5. {
printf("Element is not found");
}
else
{
printf("Element is found at %d position",pos);
}
getch();
break;
case 2:printf("nNon-Recursive method:n");
b_search_nonrecursive(l,num,ele);
getch();
break;
}
}
getch();
}
6. /* Write C programs that use both recursive and non recursive functions
to perform the following searching operation for a Key value in a given list of integers :
i) Linear search */
#include <stdio.h>
#define MAX_LEN 10
void l_search_recursive(int l[],int num,int ele);
void l_search(int l[],int num,int ele);
void read_list(int l[],int num);
void print_list(int l[],int num);
void main()
{
int l[MAX_LEN], num, ele;
int ch;
clrscr();
8. case 2:printf("n**Non-Recursion method**n");
l_search_nonrecursive(l,num,ele);
getch();
break;
}
}
getch();
}
/*end main*/
/* Non-Recursive method*/
void l_search_nonrecursive(int l[],int num,int ele)
{
int j, f=0;
for(j=0;j<num;j++)
if( l[j] == ele)
{
printf("nThe element %d is present at position %d in listn",ele,j);
f=1;
break;
}
if(f==0)
printf("nThe element is %d is not present in the listn",ele);
9. }
/* Recursive method*/
void l_search_recursive(int l[],int num,int ele)
{
int f = 0;
if( l[num] == ele)
{
printf("nThe element %d is present at position %d in listn",ele,num);
f=1;
}
else
{
if((num==0) && (f==0))
{
printf("The element %d is not found.",ele);
}
else
{
l_search(l,num-1,ele);
}
}
getch();
10. }
void read_list(int l[],int num)
{
int j;
printf("nEnter the elements:n");
for(j=0;j<num;j++)
scanf("%d",&l[j]);
}
void print_list(int l[],int num)
{
int j;
for(j=0;j<num;j++)
printf("%dt",l[j]);
}